Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I'm doing a raytracing exercise. I have a vector representing the normal of a surface at an intersection point, and a vector of the ray to the surface. How can I determine what the reflection will be?

In the below image, I have d and n. How can I get r?

Vector d is the ray; n is the normal; t is the refraction; r is the reflection

Thanks.

share|improve this question
add comment

2 Answers

Let $\hat{n} = {n \over \|n\|}$. Then $\hat{n}$ is the vector of magnitude one in the same direction as $n$. The projection of $d$ in the $n$ direction is given by $\mathrm{proj}_{n}d = (d \cdot \hat{n})\hat{n}$, and the projection of $d$ in the orthogonal direction is therefore given by $d - (d \cdot \hat{n})\hat{n}$. Note that $-r$ has the same projection onto $d$, with its orthogonal projection given by $-1$ times that of $d$. Thus we have $$d = (d \cdot \hat{n})\hat{n} + [d - (d \cdot \hat{n})\hat{n}]$$ $$-r = (d \cdot \hat{n})\hat{n} - [d - (d \cdot \hat{n})\hat{n}]$$ The later equation is exactly $$r = -(d \cdot \hat{n})\hat{n} + [d - (d \cdot \hat{n})\hat{n}]$$ Hence one can get $r$ from $d$ via $$r = d - 2(d \cdot \hat{n})\hat{n}$$ Stated in terms of $n$ itself, this becomes $$r = d - {2 d \cdot n\over \|n\|^2}n$$

share|improve this answer
add comment

$$r = d - 2 (d \cdot n) n$$

where $d \cdot n$ is the dot product, and $n$ must be normalized.

share|improve this answer
1  
And if my d happens to be pointing the other direction, I need to negate it first, right? –  Rosarch Dec 6 '10 at 18:00
    
@user2755 Yes, but you can test this yourself with pencil and paper using simple cases, e.g. $d = [1,-1]; n=[0,1]$ (incoming down and to the right onto a ground plane facing upwards). With this, $r = [1,-1] - 2 \times (-1) \times [0,1] = [1,-1] + 2 \times [0,1] = [1,-1] + [0,2] = [1,1]$. –  Phrogz Dec 6 '10 at 18:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.