This commit is contained in:
josephroy99 2023-06-07 20:16:35 +01:00
parent 70f3e458d4
commit 57d6e99256
21 changed files with 74 additions and 43 deletions

View File

@ -1,14 +1,31 @@
// See https://aka.ms/new-console-template for more information // See https://aka.ms/new-console-template for more information
using System.Diagnostics; using System.Diagnostics;
using LensSimulatorCore;
using LensSimulatorCore.Optical; using LensSimulatorCore.Optical;
using LensSimulatorCore.Shapes; using LensSimulatorCore.Shapes;
using LensSimulatorCore.Workspace;
namespace ImplementationTest;
internal class Program
{
static void Main(string[] args)
{
var ellipse = new Ellipse(-0.6,1.8,1.4,new Point(2.1,-0.5));
var resultEllipse = ellipse.GetIntersectionPoints(new Line(3.7, 2.8));
var circle = new Circle(1.4, new Point(2.1, -0.5));
var resultCircle = circle.GetIntersectionPoints(new Line(3.7, 2.8));
var ellipse = new Ellipse(0.2,3,4,new Point(1,3));
var result = ellipse.GetIntersectionPoints(new Line(-2, 3));
var ListOfPointsOnCircle = (double n) => var ListOfPointsOnCircle = (double n) =>
{ {
@ -44,3 +61,5 @@ var time = s.ElapsedMilliseconds;
Console.Write("F"); Console.Write("F");
}
}

View File

@ -29,9 +29,9 @@ public static class CoreMaths
return num1; return num1;
} }
public static List<double?> SolveQuadratic(double a, double b, double c) public static List<double> SolveQuadratic(double a, double b, double c)
{ {
var solutions = new List<double?>(); var solutions = new List<double>();
double discriminant = b * b - 4 * a * c; double discriminant = b * b - 4 * a * c;
if (discriminant < 0) if (discriminant < 0)

View File

@ -1,3 +1,4 @@
using System.Drawing;
using LensSimulatorCore.MathsLib; using LensSimulatorCore.MathsLib;
using LensSimulatorCore.Shapes; using LensSimulatorCore.Shapes;
@ -22,36 +23,49 @@ public class Ellipse
{ {
var cosTheta = Math.Cos(_radianAngle); var cosTheta = Math.Cos(_radianAngle);
var sinTheta = Math.Sin(_radianAngle); var sinTheta = Math.Sin(_radianAngle);
var majorSquared = _semiMajorAxis * _semiMajorAxis; var majorSquared = _semiMajorAxis * _semiMajorAxis;
var minorSquared = _semiMinorAxis * _semiMinorAxis; var minorSquared = _semiMinorAxis * _semiMinorAxis;
var LCM = CoreMaths.CalculateLCM(majorSquared, minorSquared); var lcm = majorSquared * minorSquared;
var intersectionMinusXpos = line.C - _position.X; var intersectionMinusXpos = line.C - _position.X;
var intersectionMinusXposCosTheta = (intersectionMinusXpos * cosTheta); var intersectionMinusXposCosTheta = intersectionMinusXpos * cosTheta;
var intersectionMinusXposSinTheta = (intersectionMinusXpos * sinTheta); var intersectionMinusXposSinTheta = intersectionMinusXpos * sinTheta;
var ySinTheta = _position.Y * sinTheta; var ySinTheta = _position.Y * sinTheta;
var yCosTheta = _position.Y * cosTheta; var yCosTheta = _position.Y * cosTheta;
var slopeCosTheta = line.B * cosTheta; var slopeCosTheta = line.B * cosTheta;
var slopeSinTheta = line.B * sinTheta; var slopeSinTheta = line.B * sinTheta;
var a1 = minorSquared * Math.Pow(slopeCosTheta - sinTheta, 2); var slopeCosThetaMinusSinTheta = slopeCosTheta - sinTheta;
var b1 = minorSquared * (slopeCosTheta - sinTheta) * (intersectionMinusXposCosTheta + ySinTheta) * 2; var intersectionMinusXposCosThetaPlusYSinTheta = intersectionMinusXposCosTheta + ySinTheta;
var c1 = minorSquared * Math.Pow(intersectionMinusXposCosTheta + ySinTheta, 2);
var a2 = majorSquared * Math.Pow(slopeSinTheta + cosTheta, 2); var slopeCosThetaMinusSinThetaPow2 = Math.Pow(slopeCosThetaMinusSinTheta, 2);
var b2 = majorSquared * (slopeSinTheta + cosTheta) * (intersectionMinusXposSinTheta - yCosTheta) * 2; var ser = intersectionMinusXposCosThetaPlusYSinTheta * (slopeCosThetaMinusSinTheta) * 2;
var c2 = majorSquared * Math.Pow(intersectionMinusXposSinTheta - yCosTheta, 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 a = a1 + a2;
var b = b1 + b2; var b = b1 + b2;
var c = c1 + c2 - LCM; var c = c1 + c2 - lcm;
var y = CoreMaths.SolveQuadratic(a, b, c); var y = CoreMaths.SolveQuadratic(a, b, c);
return y.Select(y => new Point(line.B * y!.Value + line.C, y.Value)).ToList(); return y.Select(y => new Point(line.B * y + line.C, y)).ToList();
} }
} }

View File

@ -1,7 +1,6 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // This code was generated by a tool.
// Runtime Version:4.0.30319.42000
// //
// Changes to this file may cause incorrect behavior and will be lost if // Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated. // the code is regenerated.

View File

@ -1 +0,0 @@
04bd4ca88629d5173ee0b51ca8fd93faa8aa5ffb

View File

@ -1,4 +1,4 @@
#pragma checksum "..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "F00A131DD7A3DD8BE845A0DF7A7CAC5E61751361" #pragma checksum "..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "1F75E03F780127AE90566E2C2C23D77355CE45A9"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // This code was generated by a tool.