Jashcraf / Gaussian-Beamlets

12 stars 8 forks source link

Real Ray Tracing with Beamlets #26

Open Jashcraf opened 2 years ago

Jashcraf commented 2 years ago

The real ray tracing has been trouble to implement because of the conversion of what a "real ray" is to the paraxial convention with ABCD matrices. Since the beamlet code runs on ABCD matrices we can compute the matrix to determine the beamlet propagation.

A real ray is specified by 6 dimensions: Their positions in three orthogonal directions and the associated direction cosines. However, ray transfer matrices don't operate on the z-axis, so we need to convert the direction cosines into slopes in the xz and yz plane.

The method I had derived for this conversion is shown below

Jashcraf commented 2 years ago

I think there's a bug with the raytrace - I'm giving some of the rays an angle but they still show up as having 0 position for the outgoing rayset image

Jashcraf commented 2 years ago

It would appear that the GetGlobalMatrix() method fails at the image surface without throwing an error - just returns a success value of 0. Maybe global coordinates are unnecessary

Jashcraf commented 2 years ago

Local Coordinates Calculations

On-axis position and angle

image

+ Position X

image

+ Position Y

image

+ Angle X

image

+ Angle Y

image

These are all about what I would expect - so we can proceed with attempting the differential ray transfer matrix

Jashcraf commented 2 years ago

First Result

image

This is organized [A,B] [C,D]

Overall this sort of conflicts with what I was expecting. The A and D matrices make enough sense - though there is a factor of -1 in the D matrix that was unanticipated. The B and C matrices almost seem switched, I wonder if the matrix is being incorrectly computed somehow?

Jashcraf commented 2 years ago

Consider writing a function to connect this to a gbd simulation

Jashcraf commented 2 years ago

Getting quite close - need to figure out why yout is such a large number

image
Jashcraf commented 2 years ago

Bug was over-subtraction of yout - it works now!

image
Jashcraf commented 2 years ago

Tested with reflection and not getting encouraging results - I think it has to do with one or more of the following:

To address the first we just need to define rayin in the context of the surface.

Maybe it's as simple as the PRT approach - trace to a surface and report the angle in and out using the vector snell's law.

image
Jashcraf commented 2 years ago

Perhaps I'm overcomplicating this - Worku constructs each ray transfer matrix for each interaction individually using the finite differences method - let's try with just a single distance and single refraction! Had to rewrite the

Case: Propagate 5000mm

Jashcraf commented 2 years ago

Rewrote the entire thing in matlab so that I don't have to keep generating text files and we can just send the final Ray Transfer Matrix to the beamlet code. Here are some test cases:

Case: Propagate 5000mm

image

This is exactly what we expect (with some errors in precision)

Case: Refract at a 5000mm radius paraboloid image

Everything in this matrix could potentially be real - with the exception of the elements of the B matrix (top right 2x2). There shouldn't be anything here because the refracting surface is the entrance pupil - I wonder if it has to do with the propagation of the rays from the stop surface to the mirror surface?

Well, no need to fix something that might not be broken - let's do a full calculation and see what the result for a single parabola is.

Jashcraf commented 2 years ago

Actually - perhaps moving forward with Stone to just not compute the values that shouldn't be there might be the move.

Jashcraf commented 2 years ago

This is nearly what I would expect from a paraxial lens going to focus ... time to plot it! image

Jashcraf commented 2 years ago

oh my god I think it worked image