Skip to main content
Solved

Vertex position and ray location


Hello. I am trying to get the vertex position of each optical element in terms of global coordinates. I have found I need this as I am trying to find the full X, Y, Z location for each ray when running a “CreateNormUnpol” raytrace. When I am reading the ray information, I only get values for the X & Y locations and a 0.0 value for the Z location of the ray. Is there a way to enable global position for all axes?

 

In a similar analysis, I want to know if there is a way to run a single ray trace and get all the location and angle information at each surface as is done in the Single Ray Trace window under the Analysis tab?

Best answer by MichaelH

Hey Mark,

All values in OpticStudio sequential mode are always calculated in local coordinates from one surface to the next.  In order to convert from local to global, you’ll need to get the Global Rotation Matrix for the given surface and convert to global; this is the same operation that the Single Ray Trace does when you click “Global Coordinates”.  The xo, yo, zo are the surface vertex offsets and the r## are the Euler rotation matrix.  Below is Python code to calculate this (note this is only for XYZ values...LMN values are :

def l2g(self, surf, xl, yl, zl):

    _, r11, r12, r13, r21, r22, r23, r31, r32, r33, xo, yo, zo = self.TheSystem.LDE.GetGlobalMatrix(surf, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

    

    xg = r11 * xl + r12 * yl + r13 * zl

    yg = r21 * xl + r22 * yl + r23 * zl

    zg = r31 * xl + r32 * yl + r33 * zl

    

    return [xg, yg, zg]

As for a way in the API to return similar results to the Single Ray Trace, you will need to loop through each surface with the SingleRayNormUnpol method (rather than the CreateNormUnpol); this allows you to get the XYZ, LMN, and Normal vectors.  Note that the “Path Length" is going to be the physical length of the ray, not the optical length, so you can calculate this with the Cartesian distance formula.  Also, you will need to handle Non-Sequential Components separately since the SingleRayNormUnpol is only for sequential mode.

View original
Did this topic help you find an answer to your question?

2 replies

MichaelH
Luminary
Forum|alt.badge.img+2
  • Luminary
  • 336 replies
  • Answer
  • May 4, 2022

Hey Mark,

All values in OpticStudio sequential mode are always calculated in local coordinates from one surface to the next.  In order to convert from local to global, you’ll need to get the Global Rotation Matrix for the given surface and convert to global; this is the same operation that the Single Ray Trace does when you click “Global Coordinates”.  The xo, yo, zo are the surface vertex offsets and the r## are the Euler rotation matrix.  Below is Python code to calculate this (note this is only for XYZ values...LMN values are :

def l2g(self, surf, xl, yl, zl):

    _, r11, r12, r13, r21, r22, r23, r31, r32, r33, xo, yo, zo = self.TheSystem.LDE.GetGlobalMatrix(surf, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

    

    xg = r11 * xl + r12 * yl + r13 * zl

    yg = r21 * xl + r22 * yl + r23 * zl

    zg = r31 * xl + r32 * yl + r33 * zl

    

    return [xg, yg, zg]

As for a way in the API to return similar results to the Single Ray Trace, you will need to loop through each surface with the SingleRayNormUnpol method (rather than the CreateNormUnpol); this allows you to get the XYZ, LMN, and Normal vectors.  Note that the “Path Length" is going to be the physical length of the ray, not the optical length, so you can calculate this with the Cartesian distance formula.  Also, you will need to handle Non-Sequential Components separately since the SingleRayNormUnpol is only for sequential mode.


CJ27
  • Visible
  • 17 replies
  • January 8, 2025

Hi ​@MichaelH ,

I was wondering about what you wanted to say about the LMN values in your answer to this question. The global XYZ coordinates can be obtained by following the approach you provided but what about the direction cosines? By default, these are also expressed in the local coordinate system basis if I use CreateNormUnpol right? How could I re express these direction cosine vectors in terms of the global coordinate system basis? 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings