using LensSimulatorCore.Shapes; namespace LensSimulatorCore.Optical; class SphericalRefractive : SphericalSurface { public SphericalRefractive(double radius, Element parent) : base(parent) { face.Radius = radius; } 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); var normalAngle = Math.Asin(hitPosition.Y / (QuadraticSign * face.Radius)); var angleOfIncidence = normalAngle + lineAngle; var angleOfRefraction = Math.Asin((n1 * Math.Sin(angleOfIncidence)) / n2); var angleOfRefractionFromCentreline = angleOfRefraction - normalAngle; double b, c; b = Math.Tan(angleOfRefractionFromCentreline); 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)); } }