dagostinelli / hypatia

A header-only, pure-C math library for 2D/3D graphics (matrix, vector, quaternion) Seeks to be close to C89/C90 compliant for portability. It's like a BLAS, but easier to use.
http://dagostinelli.github.io/hypatia/
Other
83 stars 8 forks source link

Add { float r; float i; } to vector2 #13

Open dagostinelli opened 3 years ago

dagostinelli commented 3 years ago

This was snipped from #12 and written by @awsdert -- moved here to split the issues


Also please add this struct to the union vec2s: struct { float r; float i; } r is for the "real" numbers and i is for "imaginary" numbers (in case you are still having trouble understanding what "imaginary" numbers are, I think of them as square root pairs, for example i5 i5 is -25, in "real" that would be -5 5 or 5 * -5, i5 represents that "real" pair)

Edit: Also do similar for any related unions please


dagostinelli commented 3 years ago

I should be able to make something like this happen. Let's chat about it a bit more.

I'd like to have some consistency with quaternion, and vector4. They already use x, y, z, w and i, k, j, a.

The paradigm: i, j, k, w is consistent with online tutorials on quaternions. Now that you've asked your question, I wonder if I should add i, j, k, a to the vector4 so that it can also have i, j, k, w.

In hindsight, I can't remember why I added that a. Maybe I added the a to satisfy the compiler. If that's why, and it can be disregarded, maybe I should have labeled it as such: _disregard. I mention this because of what I write next:

Your suggestion is to add r, i.

A variant on this is to swap that disregarded 'a' in the quaternion and vector4 for letter r. Then add these two vector2 and vector3:

vector2: i, r vector2: _d, w

vector3: i, j, r vector3: _d1, _d2, w

(where the ones with the underscore should be disregarded)

That results in:

vector2: i, r and i, w vector3: i, j, r and i, j, w vector4: i, j, k, r and i, j, k, w

as well as variations with x, y and z

NOTE: I think the essential difference between what I'm proposing and what you are proposing is the ordering of the elements.

Would that work for you?

awsdert commented 3 years ago

Well I'm no expert but I've using them the other way round, r aligning with x and i aligning with y, it feels natural to think of them that way as that's how the axis are named in math vids I sometimes watch, I stopped my official math education at GCSEs, the rest is just out of occasional interest, I suppose you could just name the structs as ri and xy to ensure other variations can be used without collisions

Edit: Considering the usage it doesn't really matter which way round they go so I'll leave it to your discretion

Edit 2: Was just thinking, since you spoke of vec3 & vec4 despite them having nothing to do with the closed scenario of real & imaginary numbers might as well posit an idea for some specific named structs in all 3

struct { float r, s; } rs;
struct { float r, s, c; } rsc;
struct { float r, s, c, q; } rscq;

The r still stands for "real", the s, c, & q stand for "square root pair", "cubic root trio" and "quantum root quad", should make things clearer in the functions that need those values in that context instead of the usual {x, y, z, w}