This is a problem that I need to figure out to complete a Java Raytracer Render Engine.

Let's say a Light is positioned at (x, y, z) position in a 3D Environment. There's also a metallic object, let's say an sphere (composed by triangles: [ The triangles are joined by vertices, each of them has a normal vector and a position ]) at another (x, y, z) position in the same environment.

A light ray is created from the light source and it hits the "sphere" in one of it's triangles, generating an intersection ray. This is going to be the Incidence Ray.

How would you calculate the Reflected Ray or Reflected Vector of the Ray on that Triangle?

I researched a bit and saw that in a 2D Plane you can calculate the Angle between the Normal Vector and the Ray Vector, and with that calculation you can create a new reflected vector. But this doesn't apply to 3D Vectors, right?.


Assuming small triangles and calling the three triangle vertices $A,B,C$ the normal vector to the triangle can be computed as

$$ \vec n = (C-B)\times (B-A) $$

the triangle barycenter is given by $G_0=\frac 13(A+B+C)$

now given any radiating spatial point $P_0$ the incident ray to the barycenter is over the line

$$ P = P_0 + \lambda\vec v $$

where $\vec v = G_0-P_0$


$$ \vec v_{\vec n} = \left(\frac{\vec n}{||\vec n||}\cdot \vec v\right)\frac{\vec n}{||\vec n||} $$

is the $\vec v$ component along $\vec n$ and correspondingly

$$ \vec v_{\Pi} = \vec v-\vec v_{\vec n} $$

is the $\vec v$ component pertaining to the triangle plane

The reflected vector $\vec v_r$ is calculated as

$$ \vec v_r = \vec v_{\Pi}-\vec v_{\vec n} = \vec v-2\vec v_{\vec n} $$


$$ \vec v_r = \vec v - 2 \left(\frac{\vec n}{||\vec n||}\cdot \vec v\right)\frac{\vec n}{||\vec n||} $$

and consequently the reflected ray is along the line

$$ P_r = G_0 + \mu \vec v_r $$


The triangles should be oriented so the normal is at the required surface side.

| cite | improve this answer | |
  • $\begingroup$ Thank you sir! This solved the issue. $\endgroup$ – Alan Maldonado May 21 '19 at 1:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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