# NTNUJAVA Virtual Physics Laboratory

## Easy Java Simulations (2001- ) => Optics => Topic started by: Fu-Kwun Hwang on February 19, 2010, 11:06:26 am

Title: Ray tracing (polygon: range from 3-32 faces)
Post by: Fu-Kwun Hwang on February 19, 2010, 11:06:26 am
Quote
I am enjoying a lot your nice prism simulation. It is really amazing! I wonder if it would be possible to create a simulation with a polygonal prism, for example with 4, 5 or even 6 faces. This would be nice, even if there would be some form restrictions.

The following simulation was created due to above request (Re: Prism: Reflection and refraction (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=37.msg5425#msg5425))

You can drag the slider to change the number of faces. (N:from 3 to 32, it is similar to a circle when N=32, you will study physics of rainbow (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1430))

The intensity was calculated for s-wave.
The subroutine for p-wave is also available in the xml source.
Click show all chekbox to show all the rays with equal intensity. (Maximum number of trace can be changed with right slider 3-20)
If the drag mode is checked, you can drag the whole polygin.
otherwise, you can drag each corner to change the shape of the polygon (with restrictions).

You can dray the arrow to change it's location or direction (depends on where you drag).
It can be drag inside the polygon,too!

un-check the checkbox labeled "check" if you want to created inward type polygon shape.

The following simulation assume the ray will not enter the polygon more than once.

[ejsapplet]

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=

You are welcomed to check out the following similar/related applets,too!
Dispersion of light with prism (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=415.0) ,
Prsim optics (slow motion of light entering a prism) (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=414.0) ,
It is fun to play with prism. (light trace and intensity due to refraction) (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=412.0)
or Lens (thick lens) and Mirror (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=121.0)

Title: Re: Ray tracing (polygon: range from 3-32 faces)
Post by: liesenbergk on February 24, 2010, 04:37:13 am
Dear Professor,

Thanks again for you gentle efforts. The feature of entering the polygon corners is very convenient and practical.

I guess that I met a bug in the simulation.

I made an internal "triangle cut" into the polygon and the ray is not reflecting at this point as it should. Please see the comparison between a triangle and the concave hexagon as attached.

Could this be solved?

With kind regards!
Title: Re: Ray tracing (polygon: range from 3-32 faces)
Post by: Fu-Kwun Hwang on February 24, 2010, 09:37:04 am
It will be difficult to solve the problem if we do not have enough information.
Would you please give me the coordinates for those polygons that you have tried?
It will be much easier for me to test it if you can provide me more information.
Title: Re: Ray tracing (polygon: range from 3-32 faces)
Post by: liesenbergk on February 24, 2010, 06:31:09 pm
Dear Professor,

One possible data set, among many others, could be:

Refraction index: 1,49
Faces: 6
x: -10,-10,0,10,10,0
y: 0,20,30,20,0,10

I hope this will help.

Thanks a lot again! Regards.
Title: Re: Ray tracing (polygon: range from 3-32 faces)
Post by: Fu-Kwun Hwang on February 24, 2010, 10:54:17 pm
I assumed when the ray enter the polygon, there is only one intersection point.
However, there are three points in your case.
You only told me that you want to extend prism to more faces polygon.
The design of the simulation will be different if you have told me the shap of the polygon earlier.
I need to find time to re-write the code again.

Title: Re: Ray tracing (polygon: range from 3-32 faces)
Post by: liesenbergk on February 24, 2010, 11:49:44 pm
I'm am sorry for the misunderstanding, Professor.

I hope that you will find time to work on this issue.

Best regards!
Title: Re: Ray tracing (polygon: range from 3-32 faces)
Post by: Fu-Kwun Hwang on February 26, 2010, 11:38:01 pm
For the prism simulation,
there are two more rays produced each time the main ray touch the prism boundary.
One is the reflected ray and another one is the refracted ray.
So I use two array to record and polt the trace for those rays.
The intensity for all the rays are also calculated.
Up to 20 reflection/refraction rays are traced.
The intensity of the reflected ray is less than 5% so it become very weak.
That is why a show all check box is added to show all the traces.

For the case of (http://www.phy.ntnu.edu.tw/ntnujava/index.php?action=dlattach;topic=1434.0;attach=1688;image)
The ray enter the prism will create a series of rays.
However, the ray enter the polygon more than once so more sets of rays are needed to trace all possible traces.

Because the simulation also allow user to change number of face for the polygon.
So it is not easy to know how many rays are needed.
It can be done with dynamical allocated memory to solve the problem. However, it is not the way EJS(The tool used to create the simulation) was designed.

I can modify to solved the problem for the above case. However, there might be another bug for another type of problem. It is not easy to design a simulation to fit with too many degree of freedom. I did all this with my spare time.
It will be much easier if we do not need to trace many reflected rays.
Please let me know what you really want to do. What is the purpose of your work so that I can create a simulation better fit with what you need.

Does the following shape is the only case you want to study?
(http://www.phy.ntnu.edu.tw/ntnujava/index.php?action=dlattach;topic=37.0;attach=1686;image)
Please let me know what kind of information you are really intereated in.
What is the purpose for the study?

Do you need to calculate up to 20 reflected rays? Do you need to know information for the intensity for each ray? Do you need reflected ray and refracted ray?
Please describe all the possible cases you want to do.

You only ask one more feature at a time. Please let me know all the information and I will try to help.

Title: Re: Ray tracing (polygon: range from 3-32 faces)
Post by: liesenbergk on February 27, 2010, 07:42:17 pm
Dear Professor,

Unfortunately I cannot tell you in detail at the present time what I have been analyzing and the purpose behind it. I promise you that I will tell you everything and show you further details in the near future at the right time. I am really sorry for this, but I will make it up shortly. I hope that you understand this.

I know that the simulation I have been asking for is tricky and that the resources of the programming tool might not extend to cover these requests.

In this moment the coverage of the hexagon as attached is sufficient for my needs. The reflected and refracted rays are important up to the intensity sum of 80%. Usually these rays do not surpass the amount of 3 or 4 rays. Having their individual intensity would be nice. If the effort to calculate them is very hi, I will understand that you suppress this feature. Beyond 20% of the remaining energy, further rays are not relevant. So, if you could help to debug the attached case I would be more than happy.

Once again, sorry for not answering fully your question in this moment! :-[ :-[

Best regards, Professor!
Title: Re: Ray tracing (polygon: range from 3-32 faces)
Post by: Fu-Kwun Hwang on February 28, 2010, 12:49:00 am
The coding of a simulation often depends on the purpose for the simulation.

For glass (index of refraction =1.5), the intensity of reflected ray is roughly 4% of the incoming ray for normal incident.
The reflected ray become important when total reflection occurs (or at angle near that).
The intensity of the reflected/refracted ray also depends on it's polarization.
Are you working with polarized light?
Does the incoming ray is always horizontally or it need to be adjustable?
Do you need slope value for different rays?
.....

For different problem, the best way to solve might be different.
I can understand if you do not want to tell me the purpose of the project.
However, you can at least tell me what kind of information you need to find out from the simulation (The specification for the simulation)!
It is become difficuit if you keep asking me one more thing at a time (because I might need to change the design of the simulation because of different requirement).
I will try to create another simulation for you. But I can not be sure that it will be what you really need unless I can get more detail information from you! I am waiting for your information/specification for the simulation![hide]
But I need you to give me all the detail information you want for the simulation.
The problem need to be understood before it can be solved.
I will have to say sorry if I do not know what I am doing? [/hide]
Title: Re: Ray tracing (polygon: range from 3-32 faces)
Post by: liesenbergk on March 01, 2010, 07:08:18 pm
Dear Professor,

I will try to be more specific in the data, although I might not have all answers in hands.

The material is acrylic (refraction index ~1.49). The light is mainly polarized and comes from a plane which is located under the optical device. I guess that only s type rays will cover the case properly. In my simulations the rays come from bottom to top and from left to right in an angle which is in the range of roughly 27 degrees in the upper limitation line and 45 degrees in the lower ray limitation line (please see attached graphic). Having slope values for the different rays would be fine, but not essential. The way you indicate it with different colors in the existing model is fine.

What is essential for me is the consideration and calculation the rays in concave faces (see attached graphic, where a simple concave polygon appears with a ray crossing two concave cuts; the ray angles are only as example!  :) ).

The maximum incidence of concave areas are two subsequent ones.

So, if you consider the specified light (s), the material used, the origin of the rays from one specific plane and the maximum incidence of concave cuts in the polygon it might be easier for you creating the necessary changes in the simulation.

Please let me know if you need further information or data.

Once again, I am more than grateful for your support and interest! The existing simulation is helping me a lot in my investigations.

Kind regards!
Title: Re: Ray tracing (polygon: range from 3-32 faces)
Post by: Fu-Kwun Hwang on March 01, 2010, 11:40:23 pm
OK! It is much better now. I will try to find time to create a new simulation.
However, I can only do it in my spare time. But I will try to manage it as soon as I can. :-)
Title: Re: Ray tracing (polygon: range from 3-32 faces)
Post by: liesenbergk on March 02, 2010, 06:10:46 pm
Thanks, again, dear Professor!
Title: Re: Ray tracing (polygon: range from 3-32 faces)
Post by: Fu-Kwun Hwang on March 08, 2010, 01:19:45 pm
I am sorry that I was very busy last week. However, I managed to finish the coding today.
The default configuration for the following simulation is the same as what you want.
The design of the coding is totally different from the above one.
However, it can be used to simulated many faces polygon,too!
The slider at the top can be used to adjust minimum intensity ray to be drawn/calculated in the simulation.

Please check out Ray tracing for laser light (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1445.msg5475#msg5475)
Title: Re: Ray tracing (polygon: range from 3-32 faces)
Post by: jpurrazz on January 12, 2012, 10:22:49 pm
I like this simpulation, but I see the exiting refraction angle changes for a horizontal beam going into a right angle prism when the prism is translated horizontally without changing the angles. Physically this doesn't happen. There also some unusual beam reflections and refractions for this condition when the prism is translated vertically and horizontally which don't exist.
It is a very handy illustration when it does work though.
Regards,
Joseph
Title: Re: Ray tracing (polygon: range from 3-32 faces)
Post by: Fu-Kwun Hwang on January 13, 2012, 01:02:05 am
Thank you for the bug report.
However, I could nor figure the problem.
Could you download the jar file and double click the file to run it locally.
Right click and select capture the screen to save a snapshot file when the problem occurs.
Then, upload the image file as attachment.

I will try to fix the problem if I know what might went wrong. ;D