Names of vector operations
I am making a 2D game with physically accurate object movement and collisions. I managed to make it work, but I have one small problem - since using scalars, like
object.x += object.vx;
object.y += object.vy;
was boring, I decided to create my own vector library and now I can write
vector_add(&object.position, &object.velocity);
I''m rewriting all my game to use vectors and now I have a problem - what names should I give to my vector functions. For example, if there is
float value = a.x * b.x + a.y * b.y;
in my code, then I put a vector_dot_product(&a, &b) function there. But what to do with this:
float value = a.y * b.x - a.x * b.y;
I want to do:
float value = vector_operation_with_some name_that_other_people_can_understand_and_not_laugh_at_me(&a, &b);
but does this operation have some special name? Another example:
c.x = a.x * b.y + a.y * b.x;
c.y = a.y * b.y - a.x * b.x;
I searched the web, but found only vector sums, dot products and cross products. Are there some special names for other vector operations or should I invent my own terminology?
quote:
c.x = a.x * b.y + a.y * b.x;
c.y = a.y * b.y - a.x * b.x;
This is called complex product, where .y is the real part and .x is the imaginary part.
quote:
float value = a.y * b.x - a.x * b.y;
This can be called something like dot_product_rotating_one_of_the_vectors_90_degrees_first, but it''s a pretty long name.

You can also think of it as evaluating a vector internal product which is not the standard dot product and whose matrix is
[0 +1]
[-1 0]
This means that you compute vector_a * M * vector_b_transposed.
quote:
Original post by Advanced Bug
float value = a.y * b.x - a.x * b.y;
This is the z component of CrossProduct(b,a).
Thanks for the replies. At least now I have some idea what should I search for
.

While you''re at it, look for "operator overloading", if you''re using C++. It makes vectorial operations look much nicer.
Cédric
Cédric
Just to expand what cedricl said, a little;
It makes operations like...
Vector A, B, C;
...
//Init A, B & C
...
A = B + C;
A += B;
A /= C;
C = A * B;
... possible
It makes operations like...
Vector A, B, C;
...
//Init A, B & C
...
A = B + C;
A += B;
A /= C;
C = A * B;
... possible

delete this;
And how exactly do you define division of a vector by a vector?
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
November 04, 2002 01:27 PM
What makes you think /= must denote division? It''s just a symbol. Use it for whatever you like.
quote:
Original post by Anonymous Poster
What makes you think /= must denote division? It''s just a symbol. Use it for whatever you like.
No. Don''t do that. The whole point of operator overloading is to make the code clearer. Sure, you can map operator+ to the substraction of two vectors, but it defeats the purpose of operator overloading.
Cédric
November 04, 2002 03:15 PM
What makes you believe someone would like to use + to denote subtraction?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement