Navigation: Scripting Reference Manual > Functions & Subroutines > SpectrumGetRandomWavelength

 

SpectrumGetRandomWavelength

 

Contact Us: fredsupport@photonengr.com

 

Description

Gets a single wavelength value from a spectrum according to the spectrum's probability distribution.  This function can be used to simplify modeling of emission phenomena such as fluorescence.  If this function is used during a raytrace (i.e. in a surface or volume scatter model) it is suggested that the spectrum node number (specNode) be explicitly defined in the function call rather than using the SpectrumFindName function.  Explicitly defining the spectrum node number will be faster than querying the document on each evaluation of the calling routine.

 

Note: The "random reseed" option on the Miscellaneous tab of the FRED Preferences must be active for this function call to return random wavelengths.  This can be done using the GUI or by issuing PrefsSetRandomReseed( True ) in the scripting language.

 

 

Syntax

wl = SpectrumGetRandomWavelength( specNode )

 

 

Parameters

wl ( Double )

Wavelength value generated according to the specNode distribution.

 

specNode As Long

Node number of the spectrum being used to generate the random wavelength.

 

 

Example

The following example demonstrates the use of the SpectrumGetRandomWavelength command inside of the Sub EvalVolScat()...End Sub statements for a scripted volume scattering material.  In this implementation two checks occur to see if a ray's wavelength is changed:

 

1)A randomly generated number between zero and one is less than the fluorescence efficiency (QE)

2)The ray's current wavelength (g_wav) lies within the range 0.425 and 0.490

 

If both of these checks are evaluated True, then the rays wavelength is re-assigned to a value returned by SpectrumGetRandomWavelength.  Note that the spectrum node number is explicitly assigned.  Finally, new direction cosines, g_uout, g_vout and g_wout, are generated randomly for isotropic fluorescence.

 

'fraction of ray power that fluoresces (QE)

Dim QE As Double

QE = 0.77

 

'check QE and current wavelength to see if the ray will fluoresce

If Rnd()<QE And (g_wav>0.425 And g_wav<0.490) Then

          g_wav = SpectrumGetRandomWavelength( 2 )

End If

 

'isotropic direction fluorescence

a#=2*g_r1-1 : b#=2*g_r2-1 : c#=2*g_r3-1

SetLength3D a,b,c,1

g_uout=a : g_vout=b : g_wout=c

 

See Also

Spectrum Scripting Commands

Scripted Volume Scatter

 

 

 

 

 

Copyright © Photon Engineering, LLC