Jump to content
  • Advertisement
Sign in to follow this  
ravinDavin

Help with reflection Maths

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

Hi, I attached a picture of something I got from a maths book. It is about calculating angle/direction of reflection. I cannot anywhere find actual worked examples using numbers on any type of math used in different rendering methods.

Can someone explain to me why the distance bettween L and N is L-(N.L)N and linked to that, why is the vector N as (N.L)N?

I have studied vector math and I understand the basics, but the way these books "explain" things is not helpful for me, I need to see things in action for understanding, any help is appreciated.

Picture of my problem is attached

http://i44.tinypic.com/i40dna.png

Share this post


Link to post
Share on other sites
Advertisement
The dot product (which is the N.L you're talking about) takes two vectors and produces a scalar, which tells you how much two vectors are similar. Here, they're assuming N is a normalized vector, it looks like, and if you do (N.L)*N, you will get a vector back that describes "L projected onto N." Essentially, they're projecting one vector onto another, and the dot product is critical for that. They aren't saying N = (N.L)*N. See that there's a smaller vector, parallel to N but shorter than N, which they're calling (N.L)*N.

This (N.L*N) vector represents the portion of L that is parallel to N (or if you were to project L onto N, what you would get). If you subtract this from L, you take away everything in L that makes it kinda like N, and you end up with something that is completely perpendicular to N. The shortest distance between a line and a point is perpendicular line from the line to the point.

If you add the two vectors you've talked about together (L-(N.L)*N and (N.L)*N), you'll get (L-(N.L)*N)+(N.L)*N) == L+0 == L, or you'll get the vector L back, which is exactly what the picture shows.

The reflection vector R then is just (N.L)*N-(L-(N.L)*N), which if you simplify gives you 2*(N.L)*N-L. If you want to see how it works, I suggest you get a pen and paper and add/subtract some of these vectors (L-(N.L)*N and (N.L)*N) and then simplify them to see what you get (both do it algebraically and by drawing the vectors out and adding/subtracting them).

I also suggest you look into projecting vectors and the dot product, since that's pretty much all they're doing here.

Share this post


Link to post
Share on other sites

The dot product (which is the N.L you're talking about) takes two vectors and produces a scalar, which tells you how much two vectors are similar. Here, they're assuming N is a normalized vector, it looks like, and if you do (N.L)*N, you will get a vector back that describes "L projected onto N." Essentially, they're projecting one vector onto another, and the dot product is critical for that. They aren't saying N = (N.L)*N. See that there's a smaller vector, parallel to N but shorter than N, which they're calling (N.L)*N.

This (N.L*N) vector represents the portion of L that is parallel to N (or if you were to project L onto N, what you would get). If you subtract this from L, you take away everything in L that makes it kinda like N, and you end up with something that is completely perpendicular to N. The shortest distance between a line and a point is perpendicular line from the line to the point.

If you add the two vectors you've talked about together (L-(N.L)*N and (N.L)*N), you'll get (L-(N.L)*N)+(N.L)*N) == L+0 == L, or you'll get the vector L back, which is exactly what the picture shows.

The reflection vector R then is just (N.L)*N-(L-(N.L)*N), which if you simplify gives you 2*(N.L)*N-L. If you want to see how it works, I suggest you get a pen and paper and add/subtract some of these vectors (L-(N.L)*N and (N.L)*N) and then simplify them to see what you get (both do it algebraically and by drawing the vectors out and adding/subtracting them).

I also suggest you look into projecting vectors and the dot product, since that's pretty much all they're doing here.


That was great, I didn't even see the vector parallel to N, which was basically the most confusing part. Can you recommend any books on rendering algorithms/Maths that may have simple worked examples to illustrate equations and such? Are there any?

Share this post


Link to post
Share on other sites
I dunno, I've never really read any books. The one book I own is Numerical Recipes, which you probably don't want at this point (well, I own some books for school but I've never read any of them).

I am taking a computer graphics course right now though, and my professor has put all his slides and videos of his lectures online. They're available here if you're interested. I've learned tons so far. He does assume you're familiar with basic vector and matrix math, but he does kind of review the basics a little for those who may have forgotten.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!