using LensSimulatorCore.MathsLib; using LensSimulatorCore.Shapes; namespace LensSimulatorCore.Shapes; public class Ellipse { public Ellipse(double angle, double semiMajorAxis, double semiMinorAxis, Point position) { _radianAngle = angle;//* (180 / Math.PI); _semiMajorAxis = semiMajorAxis; _semiMinorAxis = semiMinorAxis; _position = position; } private readonly double _semiMajorAxis; private readonly double _semiMinorAxis; private readonly Point _position; private readonly double _radianAngle = 0; public List GetIntersectionPoints(Line line) { var cosTheta = Math.Cos(_radianAngle); var sinTheta = Math.Sin(_radianAngle); var majorSquared = _semiMajorAxis * _semiMajorAxis; var minorSquared = _semiMinorAxis * _semiMinorAxis; var LCM = CoreMaths.CalculateLCM(majorSquared, minorSquared); var intersectionMinusXpos = line.C - _position.X; var intersectionMinusXposCosTheta = (intersectionMinusXpos * cosTheta); var intersectionMinusXposSinTheta = (intersectionMinusXpos * sinTheta); var ySinTheta = _position.Y * sinTheta; var yCosTheta = _position.Y * cosTheta; var slopeCosTheta = line.B * cosTheta; var slopeSinTheta = line.B * sinTheta; var a1 = minorSquared * Math.Pow(slopeCosTheta - sinTheta, 2); var b1 = minorSquared * (slopeCosTheta - sinTheta) * (intersectionMinusXposCosTheta + ySinTheta) * 2; var c1 = minorSquared * Math.Pow(intersectionMinusXposCosTheta + ySinTheta, 2); var a2 = majorSquared * Math.Pow(slopeSinTheta + cosTheta, 2); var b2 = majorSquared * (slopeSinTheta + cosTheta) * (intersectionMinusXposSinTheta - yCosTheta) * 2; var c2 = majorSquared * Math.Pow(intersectionMinusXposSinTheta - yCosTheta, 2); var a = a1 + a2; var b = b1 + b2; var c = c1 + c2 - LCM; var y = CoreMaths.SolveQuadratic(a, b, c); return y.Select(y => new Point(line.B * y!.Value + line.C, y.Value)).ToList(); } }