Archived

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

Vector Reflection in 3D space

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

Im working on a water demo and for the reflection part of it, I want to have a vector representing the distance and direction from the center of the screen and a triangle and then have it "bounce" off that triangle at an appropriate reflection angle. The triangle will be defined as basically just 3 points arranged in any way in 3D space. Im sure there''s a fairly simple algorithm for calculating the new vector givin the three points but am unsure what it is. Anyone know an algorithm that could do this? -Mark

Share this post


Link to post
Share on other sites
Calculate the normal N of the plane defined by those three vertices. (crossproduct of (p2-p1) and (p3-p1) )

the "bounced vector" b of your original vector v will be
b = v + 2 * n * n.v
(with "*" being scalar multiplication and "." dotproduct)

(maybe the "+" is a "-" for you, depends on the way your triangles are oriented)

Share this post


Link to post
Share on other sites
I think you can do the same for refraction as well. note that you do not need to have a normalised normal for the triangle.

n = (p2 - p1) x (p3 - p1)

v'' = v - (2 * (n.v)/(n.n)) * n

and (n.v) / (n.n) is relate to the cosine the the incident vector, which can be useful.





Share this post


Link to post
Share on other sites