Advertisement

Names of vector operations

Started by November 01, 2002 05:41 AM
25 comments, last by Advanced Bug 22 years, 3 months ago
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.

Advertisement
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
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
delete this;
Advertisement
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
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
What makes you believe someone would like to use + to denote subtraction?

This topic is closed to new replies.

Advertisement