Rotating Detector Normal To Rays

You can use FRED's built in BASIC scripting language to loop over the rays, determine the average direction of the rayset, and use that information to set the orientation of the surface. This article outlines this process using the example in the picture below. We wish to orient the detector shown at the right normal to the output beam. 


  • The T_RAY structure stores all of the basic information of the ray (position, direction, wavelength, power etc.).
  • tRay.entity is the id of the surface with which the ray last intersected.
  • TransformDirection converts direction information from one coordinate system to another.
  • The use of GetFirstRay, GetNextRay, etc., is referred to as "The Ray Loop".
  • TraceCreate is the scripting equivalent to Raytrace / Trace All Sources.


1. Obtain the average direction of each ray. 

2. Set the orientation of the detector to the average. You can see that in this example, SetOperation is updating the 4th, 5th and 6th parameters in row2 in the detector's Position/Orientation list on the Location dialog box. 

3. Run the script to rotate the detector surface normal to the output beam. 

Associated FRED file: AlignDetectorToBeam

*This script is located in the Embedded Scripts folder.

Still need help? Contact Us Contact Us