Navigation: Scripting Reference Manual > Functions & Subroutines > GetRayIncidentOrDepartureAngle

 

GetRayIncidentOrDepartureAngle

 

Contact Us: fredsupport@photonengr.com

 

Description

This function calculates the angle of incident or departure angle for a single ray and returns a boolean indicating whether the evaluation was successful.  The angle is calculated with respect to the local surface normal at the ray's intersection point.

 

If the ray ID number that is passed to the function corresponds to an empty ray slot or a ray that has previously been deleted, the function will halt with an error.  Empty ray slots may occur during multi-threaded raytracing (see the multi-threading help topic for more information), so the user should always use an appropriate ray buffer loop structure or otherwise check that the ray ID is a live ray using the IsRayLive function.  See the example below for the recommended ray buffer loop structure.

 

The raytrace control and coating properties on a given surface will dictate whether a ray's departure angle can be calculated.  If the raytrace control on a surface is Halt All, for example, incident rays cannot transmit/reflect from the surface and therefore no departure angle can be calculated.  In this case, the bSuccess flag will return False and the value of dAng should not be used.

 

Depending on the number of rays traced, it may be necessary to dimension ray index and ray counter variables as data type Huge_ instead of Long.  Please see Multi-threaded Raytracing for more information.

 

Syntax

bSuccess = GetRayIncidentOrDepartureAngle( nRay, bWantIncident, dAng )

 

 

Parameters

bSuccess As Boolean

Returned boolean indicating whether the evaluation was successful.

 

nRay As Long (or Huge_)

ID number of the ray whose incident/departure angle is being requested.

 

bWantIncident As Boolean

Boolean flag that specifies whether the ray should return the incident angle or the departure angle.  When True, the incident angle on the ray is returned.  When False, the departure angle on the ray is returned.

 

dAng As Double

This variable is passed into the function call as an argument.  If the function call is successful, then dAng holds the value of the incident/departure angle in degrees.

 

 

Example

The example below demonstrates how to loop over the ray buffer, query each live ray for its angle of incidence and then print a report for each ray to the output window.

 

Sub Main

 

    ClearOutputWindow()

 

    Dim curRay As Long

    Dim dAng As Double

    Dim aoiSuccess As Boolean, raySuccess As Boolean

    Dim tRay As T_RAY

 

    'Output ray header

    Print "Ray Num" & Chr(9) & "Inc. Angle" & Chr(9) & "Success?" & Chr(9) & "Entity"

 

    'Loop over rays

    raySuccess = GetFirstRay( curRay, tRay )

    While raySuccess

 

        'Calculate angle of incidence

        aoiSuccess = GetRayIncidentOrDepartureAngle( curRay, True, dAng )

 

        'Print result to output window

        Print curRay;

        If aoiSuccess Then

            Print dAng;

        Else

            Print "---";

        End If

        Print aoiSuccess;

        Print GetFullName( tRay.entity )

 

        'Get next live ray

        raySuccess = GetNextRay( curRay, tRay )

 

    Wend

 

End Sub

 

 

See Also

Looping over the ray buffer

IsRayLive

 

 

 

 

 

Copyright © Photon Engineering, LLC