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,46 +1,65 @@
// See https://aka.ms/new-console-template for more information
using System.Diagnostics;
using LensSimulatorCore;
using LensSimulatorCore.Optical;
using LensSimulatorCore.Shapes;
using LensSimulatorCore.Workspace;
namespace ImplementationTest;
var ellipse = new Ellipse(0.2,3,4,new Point(1,3));
var result = ellipse.GetIntersectionPoints(new Line(-2, 3));
var ListOfPointsOnCircle = (double n) =>
internal class Program
{
List<Point> points = new List<Point>();
for (int i = 0; i < n; i++)
static void Main(string[] args)
{
var radians = Math.PI * 2 / n * i;
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 x = Math.Cos(radians);
var y = Math.Sin(radians);
points.Add(new Point(x, y));
}
var ListOfPointsOnCircle = (double n) =>
{
List<Point> points = new List<Point>();
for (int i = 0; i < n; i++)
{
var radians = Math.PI * 2 / n * i;
var x = Math.Cos(radians);
var y = Math.Sin(radians);
points.Add(new Point(x, y));
}
return points;
};
return points;
};
var test = ListOfPointsOnCircle(8);
var test = ListOfPointsOnCircle(8);
var sellmeier = new SellmeierCoefficients(1.03961212, 0.00600069867, 0.231792344, 0.0200179144, 0, 103);
var sellmeier = new SellmeierCoefficients(1.03961212, 0.00600069867, 0.231792344, 0.0200179144, 0, 103);
var material = new Material(sellmeier);
var material = new Material(sellmeier);
var s = new Stopwatch(); s.Start();
var s = new Stopwatch(); s.Start();
var reflectivity = material.Reflectivity(45, 1.00027717, 450);
var transmissivity = material.Transmissivity(45, 1.00027717, 450);
var reflectivity = material.Reflectivity(45, 1.00027717, 450);
var transmissivity = material.Transmissivity(45, 1.00027717, 450);
s.Stop();
var time = s.ElapsedMilliseconds;
s.Stop();
var time = s.ElapsedMilliseconds;
Console.Write("F");
Console.Write("F");
}
}

View File

@ -29,9 +29,9 @@ public static class CoreMaths
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;
if (discriminant < 0)

View File

@ -1,3 +1,4 @@
using System.Drawing;
using LensSimulatorCore.MathsLib;
using LensSimulatorCore.Shapes;
@ -22,36 +23,49 @@ public class Ellipse
{
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 lcm = majorSquared * minorSquared;
var intersectionMinusXpos = line.C - _position.X;
var intersectionMinusXposCosTheta = (intersectionMinusXpos * cosTheta);
var intersectionMinusXposSinTheta = (intersectionMinusXpos * sinTheta);
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 slopeCosThetaMinusSinTheta = slopeCosTheta - sinTheta;
var intersectionMinusXposCosThetaPlusYSinTheta = intersectionMinusXposCosTheta + ySinTheta;
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 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 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();
return y.Select(y => new Point(line.B * y + line.C, y)).ToList();
}
}

View File

@ -1,7 +1,6 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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
// 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>
// This code was generated by a tool.