2023-06-07 19:16:35 +00:00
|
|
|
using System.Drawing;
|
2023-06-06 22:56:56 +00:00
|
|
|
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<Point> GetIntersectionPoints(Line line)
|
|
|
|
{
|
|
|
|
var cosTheta = Math.Cos(_radianAngle);
|
|
|
|
var sinTheta = Math.Sin(_radianAngle);
|
|
|
|
var majorSquared = _semiMajorAxis * _semiMajorAxis;
|
|
|
|
var minorSquared = _semiMinorAxis * _semiMinorAxis;
|
|
|
|
|
2023-06-07 19:16:35 +00:00
|
|
|
var lcm = majorSquared * minorSquared;
|
2023-06-06 22:56:56 +00:00
|
|
|
|
|
|
|
var intersectionMinusXpos = line.C - _position.X;
|
|
|
|
|
2023-06-07 19:16:35 +00:00
|
|
|
var intersectionMinusXposCosTheta = intersectionMinusXpos * cosTheta;
|
|
|
|
var intersectionMinusXposSinTheta = intersectionMinusXpos * sinTheta;
|
2023-06-06 22:56:56 +00:00
|
|
|
var ySinTheta = _position.Y * sinTheta;
|
|
|
|
var yCosTheta = _position.Y * cosTheta;
|
|
|
|
var slopeCosTheta = line.B * cosTheta;
|
|
|
|
var slopeSinTheta = line.B * sinTheta;
|
|
|
|
|
2023-06-07 19:16:35 +00:00
|
|
|
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;
|
2023-06-06 22:56:56 +00:00
|
|
|
|
2023-06-07 19:16:35 +00:00
|
|
|
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;
|
2023-06-06 22:56:56 +00:00
|
|
|
|
|
|
|
var a = a1 + a2;
|
|
|
|
var b = b1 + b2;
|
2023-06-07 19:16:35 +00:00
|
|
|
var c = c1 + c2 - lcm;
|
|
|
|
|
2023-06-06 22:56:56 +00:00
|
|
|
var y = CoreMaths.SolveQuadratic(a, b, c);
|
|
|
|
|
2023-06-07 19:16:35 +00:00
|
|
|
return y.Select(y => new Point(line.B * y + line.C, y)).ToList();
|
2023-06-06 22:56:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|