Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Names of vector operations

This topic is 5675 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
While you''re at it, look for "operator overloading", if you''re using C++. It makes vectorial operations look much nicer.

Cédric

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What makes you think /= must denote division? It''s just a symbol. Use it for whatever you like.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What makes you believe someone would like to use + to denote subtraction?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!