44 lines
1.5 KiB
C#
44 lines
1.5 KiB
C#
using LensSimulatorCore.Shapes;
|
|
|
|
namespace LensSimulatorCore.Optical;
|
|
|
|
class FlatRefractive : SphericalSurface
|
|
{
|
|
public FlatRefractive(Element parent) : base(parent)
|
|
{
|
|
|
|
}
|
|
|
|
public override void Calculate(Point hitPosition, Ray ray, SellmeierCoefficients s)
|
|
{
|
|
double n1, n2;
|
|
switch (IsFront)
|
|
{
|
|
case true:
|
|
n1 = s.AirRefractiveIndex(ray.Wavelength);
|
|
n2 = s.CalculateRefractiveIndex(ray.Wavelength);
|
|
break;
|
|
case false:
|
|
n1 = s.CalculateRefractiveIndex(ray.Wavelength);
|
|
n2 = s.AirRefractiveIndex(ray.Wavelength);
|
|
break;
|
|
default:
|
|
n1 = 0;
|
|
n2 = 0;
|
|
break;
|
|
}
|
|
|
|
//need to convert vector to angle correctly
|
|
var count = ray.PointVectors.Count - 1;
|
|
var lineAngle = -Math.Atan2(ray.PointVectors[count].Vector.Y, ray.PointVectors[count].Vector.X);
|
|
const double normalAngle = 0; //Math.Asin(hitPosition.Y / (QuadraticSign * face.Radius));
|
|
var angleOfIncidence = normalAngle + lineAngle;
|
|
var angleOfRefractionFromCentreline = Math.Asin((n1 * Math.Sin(angleOfIncidence)) / n2);
|
|
|
|
var b = Math.Tan(angleOfRefractionFromCentreline);
|
|
var c = hitPosition.Y - (hitPosition.X * b);
|
|
|
|
ray.PointVectors.Add(new PointVector(new Point(hitPosition.X, hitPosition.Y), Point.AngleToVector(angleOfRefractionFromCentreline)));
|
|
ray.Lines.Add(new Line(b, c));
|
|
}
|
|
} |