# Simple 2d normal

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

## 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 on other sites
(-y, x) or (y, -x) ..you should of course normalize this if it's needed for bouncing :)

##### Share on other sites
Do I get a cookie for saying linevec×[0,0,1] ;D ?

##### Share on other sites
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 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.

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 13
• 76
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632968
• Total Posts
3009583
• ### Who's Online (See full list)

There are no registered users currently online

×