Solved

Vertex position and ray location

  • 4 May 2022
  • 1 reply
  • 454 views

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?

icon

Best answer by MichaelH 4 May 2022, 19:17

View original

1 reply

Userlevel 6
Badge +2

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.

Reply