In computer graphics applications its often needed to calculate the reflection ray for example if you are writing a ray tracer, a shader for some advanced lighting , or environment mapping etc.
If you are writing shaders , there are standard library function to do that . In cg shading language there is a function reflect(also its more efficient than writing our own).
In this post rather than just giving the vector formula for reflection ray , i am trying to explain the simple mathematics behind that.
See the following image, I is the original ray, and R is the reflected ray which we need to found.N is the normal of the incident plane. P is the line perpendicular from normal to both rays. it is obvious that at both ends the length of P will be same.
Dot product between two unit vectors gives the cosine of the angle between them. So using this idea we can find
R = DotProduct[ I, N ] * N + P . ---> Eq(1)
We don't know P now. But I + P = N * DotProduct[ I,N].
So by rearranging P = N * DotProduct[ I,N] - I. Substituting the value of P now in equation(1) gives the final equation.
Here it is the final equation R = 2 * N * ( DotProduct[ I,N] ) - I
2 comments:
Pretty section of content. I just stumbled upon your blog
and in accession capital to assert that I acquire in fact enjoyed account your blog posts.
Any way I'll be subscribing to your feeds and even I achievement you access consistently rapidly.
Have a look at my blog ; more info
Please accept me to share your knowledge to my design group with thanks
Post a Comment