The following simulation is created due to request from [url=]Re: Ray tracing (polygon: range from 3-32 faces)[/url]

The slider at the top can be used to adjust minimum intensity ray to be drawn/calculated in the simulation.

/htdocs/ntnujava/ejsuser/2/users/ntnu/fkh/polygonraysn_pkg/polygonraysn.propertiesFull screen applet or Problem viewing java?Add to exception site list
Press the Alt key and the left mouse button to drag the applet off the browser and onto the desktop. This work is licensed under a Creative Commons Attribution 2.5 Taiwan License
Download EJS jar file(1337.9kB):double click downloaded file to run it. (32 times by 22 users) , Download EJS source (13 times by 8 users) View EJS source

The range of the X-Y coordinate system is between -100 and 100.
number of points =Please enter correct number of points
[b]The data points should be enter in clockwise direction[/b]!
X= enter , separated x coordinate
Y= enter , separated x coordinate
Laser Pointer x=,y=

How to calculate the reflected light from incoming ray?
Support the vector for the incoming ray is $\vec{a}$,
We need to know either the component of incoming ray in the normal direction $\vec{b}$ or the parallel component along the interface $\vec{b}'$ to find the reflected ray vector $\vec{c}$ with  $\vec{c}=\vec{a}-2\vec{b}=2\vec{b}'-\vec{a}$

If you know the unit vector $\hat{b}$ , then $\vec{b}=(\vec{a}\cdot\hat{b}) \hat{b}$.
If you know the unit vector $\hat{b}'$, then $\vec{b}'=(\vec{a}\cdot\vec{b})\hat{b}'$.

The refracted angle can be calculated with $n_1 \sin\theta_1=n_2\sin\theta_2$,
where $\sin\theta_1=\frac{\vec{a}\cdot\hat{b}'}{|\vec{a}|}$ or $\cos\theta_1=\frac{\vec{a}\cdot\hat{b}}{|\vec{a}|}$

The normal vector $\vec{b}=\vec{a}-\vec{b}'$.
The refracted ray can be calculated with $\hat{b}\,\cos\theta_2+\hat{b}'\,\sin\theta_2$


You can study many different cases with this applet. Please check out attached files for examples.