NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
January 18, 2020, 12:03:58 pm

To live close to great minds is the best kind of education. ..."John Buchan (1875~1940 Scotticsh historian, Governor General of Canada)"

 Pages: [1]   Go Down
 Author Topic: Ray tracing for laser light  (Read 22748 times) 0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3084

 « Embed this message on: March 08, 2010, 12:23:16 pm » posted from:Taipei,T\'ai-pei,Taiwan

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

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

Embed a running copy of this simulation

Embed a running copy link(show simulation in a popuped window)
Full screen applet or Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
• Please feel free to post your ideas about how to use the simulation for better teaching and learning.
• Post questions to be asked to help students to think, to explore.
• Upload worksheets as attached files to share with more users.
Let's work together. We can help more users understand physics conceptually and enjoy the fun of learning physics!

The range of the X-Y coordinate system is between -100 and 100.
number of points =Please enter correct number of points
The data points should be enter in clockwise direction!
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.

 raytracing.gif (1.92 KB, 581x449 - viewed 658 times.)  polygonrays1.gif (2.44 KB, 581x449 - viewed 597 times.)  polygonray2.gif (3.96 KB, 581x449 - viewed 594 times.)  polygonray3.gif (4.71 KB, 581x449 - viewed 657 times.) Logged
liesenbergk
Newbie

Offline

Posts: 16

 « Embed this message Reply #1 on: March 11, 2010, 05:17:40 pm » posted from:Itapecerica Da Serra,Sao Paulo,Brazil

Dear Professor,

Thanks for your programming efforts. I have been testing the new simulation. What I am missing is the possibility of defining the polygon with coordinates as well as the position of the laser beam. This feature is available in the previous simulation and it is very usefull. I wonder if this could be programmed as well.

Kind regards from Brazil!
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3084

 « Embed this message Reply #2 on: March 11, 2010, 08:48:06 pm » posted from:Taipei,T\'ai-pei,Taiwan

O.K. It is done.
 Logged
liesenbergk
Newbie

Offline

Posts: 16

 « Embed this message Reply #3 on: March 11, 2010, 09:50:40 pm » posted from:Itapecerica Da Serra,Sao Paulo,Brazil

Thanks Professor, that was more than fast!

I don't want to abuse, but I am missing the drag mode in this new version...

Best regards!
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3084

 « Embed this message Reply #4 on: March 11, 2010, 11:14:25 pm » posted from:Taipei,T\'ai-pei,Taiwan

Because the feature has been implemented before, what I did was copy code from previous page.
And I find some free time after I went home tonight.
The drag mode should be available now.
 Logged
liesenbergk
Newbie

Offline

Posts: 16

 « Embed this message Reply #5 on: March 12, 2010, 05:43:00 pm » posted from:Itapecerica Da Serra,Sao Paulo,Brazil

Wow Professor! You're my idol!!! Thanks for your efforts and congratulations for you outstanding skills.
 Logged
liesenbergk
Newbie

Offline

Posts: 16

 « Embed this message Reply #6 on: March 15, 2010, 06:26:24 pm » posted from:Itapecerica Da Serra,Sao Paulo,Brazil

Dear Professor,

The new simulation is very useful for me, especially with the possibility of entering the polygon's defining coordinates.

There are, however, some changes which could be very interesting.

The first one (please see attached "laser pen handling" picture) concerns on how to handle the laser pen. As it is now, you can drag the pen to coordinates defines by its basis, and then rotate the pen over the axis of the basis. If you want to follow a particular line you have to, in most cases, drag and rotate, in order to avoid the entering of the laser pen's output in the optical body. It would be very nice if the laser pen can be dragged and rotated based on the coordinates of its beam output. It would also be very nice if the laser pen's angle could be entered, as shown in the related picture.

The other wished enhancement is the possibility of exporting ray data (please see attached "desired ray data" picture). Here the defining coordinates of the way of the primary beam would be outputted, if possible with its final intensity too.

I will understand if you don't have time or if this is to complicated to do. But,... it would be nice!

With best regards!
 laser pen handling.jpg (27.02 KB, 815x361 - viewed 589 times.)  desired ray data.jpg (21.25 KB, 769x379 - viewed 714 times.) Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3084

 « Embed this message Reply #7 on: March 18, 2010, 10:02:35 pm » posted from:Taipei,T\'ai-pei,Taiwan

I justed modified the code so that a new window will popup when you click the arrow of laser pointer or click the check box labeled "table".
You can change the angle with slider or text field.

I also add a table to show a list of (x,y,I) which represent all rays (include reflected ray and refracted ray).
You should be able to find which one is reflected ray, which one is refracted ray from intensity.
 Logged
liesenbergk
Newbie

Offline

Posts: 16

 « Embed this message Reply #8 on: March 19, 2010, 05:10:57 pm » posted from:Itapecerica Da Serra,Sao Paulo,Brazil

That is stunning, Master! Thanks a lot. The data table is very useful.

Kind regards, Professor!
 Logged
tmzoughi
Newbie

Offline

Posts: 9

 « Embed this message Reply #9 on: March 28, 2010, 10:42:40 pm » posted from:Kennesaw,Georgia,United States

This is wonderful simulation and it offers many possibilities. I tried to use it for a particular geometry and I think I have detected a small bug. Or it might be an opportunity for me to learn something new!
I am attaching an image of the setting I am using. This is the output of the lines generated:
j=0,I=1.0,c=1.7669502000928863,x=-75.51111260566398,y=-21.117714323462188
j=0,I=1.0,c=0.26179938779914935,x=-75.51111260566398,y=-21.117714323462188
j=1,I=0.057796105403213144,c=-1.8325957145940464,x=-15.075862213492771,y=-4.924137786507226
j=2,I=0.9422038945967869,c=0.44556125394332635,x=-15.075862213492771,y=-4.924137786507226
j=3,I=0.9422038945967869,c=-0.4455612539433263,x=58.049565975939494,y=30.0
j=4,I=0.0733637418622893,c=-2.6960313996464667,x=100.0,y=9.964797822930265
j=5,I=0.8688401527344976,c=-0.18820469334913387,x=100.0,y=9.964797822930265
j=6,I=0.0733637418622893,c=2.6960313996464667,x=16.320254742697305,y=-29.999999999999993
j=7,I=0.02264313020441028,c=2.016357580738223,x=4.221937396573228,y=-24.221937396573228
j=8,I=0.05072061165787902,c=2.1447458012139355,x=4.221937396573228,y=-24.221937396573228
j=9,I=0.00118179551253197,c=-2.016357580738223,x=-21.67403968794734,y=29.999999999999996
j=10,I=0.02146133469187831,c=2.1705020069039946,x=-21.67403968794734,y=29.999999999999996
j=11,I=0.006915452246752739,c=-2.1447458012139355,x=-30.83551657260938,y=30.0
j=12,I=0.04380515941112628,c=1.7669502000928863,x=-30.83551657260938,y=30.0

The first bug seems to be related to the ray corresponding to j=5. Since this represents a beam going from n=1.5 to n=1, the refracted beam should be larger than what what is shown. The same problem happens to beam j=8 when it refracts into beam j=12. The problem does not happen for beam j=7!
The other item I don't understand is the fact that we have two beams reflected at x=4.221937396573228,y=-24.221937396573228 (j=7 and j=8)
Thanks for your help clarifying this and for all of your amazing work.
 trapezoid.png (12.03 KB, 400x214 - viewed 667 times.) Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3084

 « Embed this message Reply #10 on: March 28, 2010, 11:18:07 pm » posted from:Taipei,T\'ai-pei,Taiwan

Could you give me the coordinates for those polygon points and light source and angle to test it out!
 Logged
tmzoughi
Newbie

Offline

Posts: 9

 « Embed this message Reply #11 on: March 29, 2010, 12:07:33 am » posted from:Kennesaw,Georgia,United States

Thanks. I have attached the xml file that I have used.
Taha
 *** There are 1 more attached files. You need to login to acces it! Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3084

 « Embed this message Reply #12 on: March 29, 2010, 10:42:47 am » posted from:Taipei,T\'ai-pei,Taiwan

Yes. It is a bug. Thank you for reporting it.
The last ray should be a total reflection ray. However, the ray was treated emmitted from air to glass, so the code did something wrong.
It is fixed now.

The above simulation was designed such that you can use javascript to change the shape of the polygon (px,py) and the position of laser point(xs,ys).

You do not need to re-compile the EJS. For you case :
n=4;
px=10,-50,100,100
py=-30,30,30,-30
xs=-90
ys=-25

Suppose the name for the EJS applet is "polygonsn". The following two javascript call will set up the above configuration.
Code:
document.polygonsn._setVariables("n=4;px=10,-50,100,100;py=-30,30,30,-30;xs=-90;ys=-25");//set up the above parameters
document.polygonsn._model.setit();// Some parameters need to re-calculate according to the above change,this is the method defined as Custom code
EJS variables are decleared as global variables, so you can change it with _setVariables (";" separated variable assignment , use "," to separate indicidual array (variable) values.

I just added another option so that user can edit coordinate for polygon in the popup window (when table is checked).
There is a second tabbed panel which display coordinate for the polygon points (it is editable).
However, only the fist N rows are useful (You can adjust N with slider).
 Logged
tmzoughi
Newbie

Offline

Posts: 9

 « Embed this message Reply #13 on: March 29, 2010, 04:49:51 pm » posted from:Kennesaw,Georgia,United States

Thanks. I knew I could modify it with JavaScript but I needed it to pop up for students under that particular configuration. I prefer that they ran it as a JAR. They then can play around and do whatever they want. Thanks for your help with this and all of your great work.

Taha
 « Last Edit: March 29, 2010, 04:52:08 pm by tmzoughi » Logged
tmzoughi
Newbie

Offline

Posts: 9

 « Embed this message Reply #14 on: March 29, 2010, 05:28:13 pm » posted from:Kennesaw,Georgia,United States

I just noticed that there is still a problem with the refraction. It still behaves like from air to glass.

Taha
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3084

 « Embed this message Reply #15 on: March 29, 2010, 05:45:12 pm » posted from:Taipei,T\'ai-pei,Taiwan

I can not find the bug, please let me know where you found it.
The following is the modified version from your case.

I also fixed other minor bug.

Embed a running copy of this simulation

Embed a running copy link(show simulation in a popuped window)
Full screen applet or Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
• Please feel free to post your ideas about how to use the simulation for better teaching and learning.
• Post questions to be asked to help students to think, to explore.
• Upload worksheets as attached files to share with more users.
Let's work together. We can help more users understand physics conceptually and enjoy the fun of learning physics!
 Logged
tmzoughi
Newbie

Offline

Posts: 9

 « Embed this message Reply #16 on: March 29, 2010, 06:51:57 pm » posted from:Alpharetta,Georgia,United States

Hi Fu-Kwun:

Thanks for your help. I am attaching a picture to explain. There are 3 refractions in this case. The first is from air to glass. It works fine. The other two are from glass to air, they don't work properly.  In the picture, I drew the normal in red. I drew the original beam direction in green and the direction of what we should expect for the refracted beam in purple.
 trapezoid.png (6.94 KB, 425x181 - viewed 558 times.) Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3084

 « Embed this message Reply #17 on: March 30, 2010, 09:53:32 am » posted from:Taipei,T\'ai-pei,Taiwan

The mistake has been fixed with new method -- to calculate direction for refracted ray (using vector analysis instead change angle directly).

 Logged
tmzoughi
Newbie

Offline

Posts: 9

 « Embed this message Reply #18 on: March 30, 2010, 06:33:21 pm » posted from:Kennesaw,Georgia,United States

Wonderful it works. Thanks so much for all of your efforts. The new method is instructive.

Taha
 Logged
vinay
Newbie

Offline

Posts: 1

 « Embed this message Reply #19 on: March 31, 2010, 10:12:27 pm » posted from:Calcutta,West Bengal,India

sir i am just begining the topic of laser optics ....i want to know why did the meta stable state dosnt take place between two energy states and take place between more than three or three..
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3084

 « Embed this message Reply #20 on: April 01, 2010, 06:05:15 am » posted from:Taipei,T\'ai-pei,Taiwan

I assumed that you understand about the meaning of energy level of electrons in atom.
The electron is likely to be in the lower energy level (ground state).
It might be excited to higher energy level with external source.
Normallly, there are higher probability to find electron in lower energy state.
When an electron are excited to higher energy state, it will fall back to lower energy state in a chort time (around 10-6-10-8 s)
The are selection rule between different energy levels. If it satisfy the selection rule, the probability to jump from one state to another state is much higher,otherwise it become very difficult.

In the case of  two energy levels state:
If it is easy to jump from lower energy level A to higher energy level B, it is also easy to jump back from B to A.
If it is difficult to jump from lower energy level A to higher energy level B, it is also difficult to jump back from B to A.
And the probability to find electron in level A is always higher than B,
$P_B/P_A = e^{-\Delta E/kT}$ where $\Delta E$ is the energy difference between those two states.

In the case of three energy levels state: A , B, C
It might be that it is easy to jump from A to B (the highest energy level), and it is also easy to jump from B back to C
However, it is difficult to jump from C back to A (because some selection rule is not satisfied so the probability to make transition is smaller than normal case)
Then, it is possible to pump electron from A to B and later find out more electron in energy level C than in energy level A.
 Logged
 Pages: [1]   Go Up
To live close to great minds is the best kind of education. ..."John Buchan (1875~1940 Scotticsh historian, Governor General of Canada)"