*
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SellmeierEquation
|
||||
{
|
||||
public class Coefficients {
|
||||
public float[] B { get; private set; }
|
||||
public float[] C { get; private set; }
|
||||
|
||||
public Coefficients(float[] b, float[] c) {
|
||||
B = b;
|
||||
C = c;
|
||||
|
||||
if (b == null || c == null) {
|
||||
throw new System.Exception("Invalid args");
|
||||
}
|
||||
|
||||
if (b.Length == 0 || c.Length == 0) {
|
||||
throw new System.Exception("Invalid args");
|
||||
}
|
||||
|
||||
if (b.Length != c.Length) {
|
||||
throw new System.Exception("Invalid args");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Coefficients _coeffs;
|
||||
|
||||
public SellmeierEquation(Coefficients coeffs) {
|
||||
_coeffs = coeffs;
|
||||
}
|
||||
|
||||
public float Calc(float wavelength) {
|
||||
return Calc(_coeffs, wavelength);
|
||||
}
|
||||
|
||||
public static float Calc(Coefficients coeffs, float wavelength) {
|
||||
float lSquare = wavelength * wavelength;
|
||||
float resultSquared = 1.0f;
|
||||
|
||||
for (int i = 0; i < coeffs.B.Length; i++) {
|
||||
float bi = coeffs.B[i];
|
||||
float ci = coeffs.C[i];
|
||||
resultSquared += (bi * lSquare) / (lSquare - ci);
|
||||
}
|
||||
|
||||
return Mathf.Sqrt(resultSquared);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user