using System.Drawing; 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 = 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 slopeCosThetaMinusSinTheta = slopeCosTheta - sinTheta; var intersectionMinusXposCosThetaPlusYSinTheta = intersectionMinusXposCosTheta + ySinTheta; var slopeCosThetaMinusSinThetaPow2 = Math.Pow(slopeCosThetaMinusSinTheta, 2); var ser = intersectionMinusXposCosThetaPlusYSinTheta * (slopeCosThetaMinusSinTheta) * 2; var intersectionMinusXposCosThetaPow2 = Math.Pow(intersectionMinusXposCosThetaPlusYSinTheta, 2); var a1 = minorSquared * slopeCosThetaMinusSinThetaPow2; var b1 = minorSquared * ser; var c1 = minorSquared * intersectionMinusXposCosThetaPow2; var slopeSinThetaPlusCosTheta = slopeSinTheta + cosTheta; var intersectionMinusXposSinThetaMinusYCosTheta = intersectionMinusXposSinTheta - yCosTheta; var slopeSinThetaMinusCosThetaPow2 = Math.Pow(slopeSinThetaPlusCosTheta, 2); var se = intersectionMinusXposSinThetaMinusYCosTheta * (slopeSinThetaPlusCosTheta) * 2; var intersectionMinusXposSinThetaMinusYCosThetaPow2 = Math.Pow(intersectionMinusXposSinThetaMinusYCosTheta, 2); var a2 = majorSquared * slopeSinThetaMinusCosThetaPow2; var b2 = majorSquared * se; var c2 = majorSquared * intersectionMinusXposSinThetaMinusYCosThetaPow2; 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 + line.C, y)).ToList(); } }