Reflecting a vector from a line
I can''t seem to find a good way to calculate this..
I have a velocity vector (2d), and a surface it needs to reflect off of (also 2d). How can I do this in a generic way, given that all the needed coords are known?
Thanks.
[size="1"][[size="1"]TriangularPixels.com[size="1"]] [[size="1"]Rescue Squad[size="1"]] [[size="1"]Snowman Village[size="1"]] [[size="1"]Growth Spurt[size="1"]]
if your collision is perfectly elastic, then:
say the original vector is
v1 = (x1,y1)
and your surface normal is
v2 = (x2,y2), [v2] = 1
then
v1 - 2* (v1 (dot) v2) * v2 = v3 (the outgoing vector).
calculating, this means
v3 = (x1 - 2*x1*x2, y2 - 2* y1*y2)
If your collision is NOT perfectly elastic, or if you want to introduce more complex effects such as rotation-inducing friction at the surface, the above can be scale with simple multiplications of the subtractive terms.
thanks,
ld
say the original vector is
v1 = (x1,y1)
and your surface normal is
v2 = (x2,y2), [v2] = 1
then
v1 - 2* (v1 (dot) v2) * v2 = v3 (the outgoing vector).
calculating, this means
v3 = (x1 - 2*x1*x2, y2 - 2* y1*y2)
If your collision is NOT perfectly elastic, or if you want to introduce more complex effects such as rotation-inducing friction at the surface, the above can be scale with simple multiplications of the subtractive terms.
thanks,
ld
No Excuses
hm, that doesnt seem to give me the results i''d expect 
(i is incidence, n is normal, angle is result):
Unfortunatly, both give wrong result, so i''m at a loss..

(i is incidence, n is normal, angle is result):
angle.x = iX - 2*iX*nX;angle.y = iY - 2*iY*nY;// Also tried the following equation (from some random site):// A = i - ( 2i.n )nfloat constant = (2*(iX*nX + iY*nY);// Precidence of 2* and dot correct?angle.x = iX - constant*nX;angle.y = iY - constant*nY;
Unfortunatly, both give wrong result, so i''m at a loss..
[size="1"][[size="1"]TriangularPixels.com[size="1"]] [[size="1"]Rescue Squad[size="1"]] [[size="1"]Snowman Village[size="1"]] [[size="1"]Growth Spurt[size="1"]]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement