Jump to content
  • Advertisement
Sign in to follow this  
fishleg003

Simple 2d normal

This topic is 4479 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

Proberly stupid question, im used to working out the 3d normal for lighting etc but im currently in the process of making a 2d sprite based game. I need to calculate the 2d normal of a line so the player can correctly bounce off objects. Like this example below, Must be some way really simple to do it but ive tried alsorts and nothing works :(. Cheers for any help fishy

Share this post


Link to post
Share on other sites
Advertisement
you can normalize any value but the type of normal you are looking for requires that you compute the cross product. The rules involved in computing a cross product requires it to be a 3D point. You can't do it with a 2D point. This has to do with the laws of multiplying vectors.

Since your game is a 2D game, you can always assume the third point is always pointing straight up.

Share this post


Link to post
Share on other sites
You could compute the result by projecting the cross-product
[x,y,0]T x [0,0,1]T = [y,-x,0]T
or also
[0,0,1]T x [x,y,0]T = [-y,x,0]T
as Bob Janova and howie_007 suggested, to yield in the results e-u-l-o-g-y has already shown.

However, the definition of orthogonal vectors is that their dot-product disappears (what works well in N dimensions) and not the use of the cross-product; so:
v1 . v2 == 0
In the given case
x*a + y*b == 0
is to be solved for a and b to yield in a vector [a,b]. Besides the trivial case a==0 and b==0, from
x/y == -b/a
it could be seen that the above 2 solutions are valid but also any co-linear vector of them (in fact [y,-x] and [-y,x] are already co-linear, of course).


BTW: From a sematics (vector algebra) point of view you cannot compute the cross-product of points, neither in 2D nor in 3D. But you can compute it from direction vectors.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!