65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
|
using LensSimulatorCore.Shapes;
|
||
|
using static System.Double;
|
||
|
|
||
|
namespace LensSimulatorCore.Optical;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Contains the function to find intersection of two Lines.
|
||
|
/// </summary>
|
||
|
class FlatSurface : Surface
|
||
|
{
|
||
|
public override void UpdateSurfacePositions()
|
||
|
{
|
||
|
SideSign = IsFront ? -1 : 1;
|
||
|
_face = new Line(0, SideSign * Parent.Depth / 2);
|
||
|
}
|
||
|
|
||
|
//This line is defined as x = by+c. It will need converting to y = bx+c.
|
||
|
private Line _face;
|
||
|
|
||
|
/// <summary>
|
||
|
/// This function takes a PointVector and checks if there a collision between itself and a Line.
|
||
|
/// </summary>
|
||
|
/// <param name="pointVector">A PointVector where (1,0) is 0 rad.</param>
|
||
|
/// <returns></returns>
|
||
|
public override Point FindIntersection(PointVector pointVector)
|
||
|
{
|
||
|
//Converts point vector to a line.
|
||
|
Line line = pointVector.ToLine();
|
||
|
//This is where the conversion takes place to make it y = bx + c.
|
||
|
Line surfaceLine = new Line(1 / _face.B, (1 / _face.B) * _face.C);
|
||
|
|
||
|
double x, y, t, u;
|
||
|
|
||
|
//If C is infinity it means the line is vertical and can be solved by inserting x into the equation.
|
||
|
if (IsInfinity(surfaceLine.C))
|
||
|
{
|
||
|
y = (line.B * _face.C) + line.C;
|
||
|
x = _face.C;
|
||
|
}
|
||
|
else //If not it means it is angled and therefore needs solving by substitution.
|
||
|
{
|
||
|
t = line.B + surfaceLine.B;
|
||
|
u = line.C + surfaceLine.C;
|
||
|
|
||
|
x = t / u;
|
||
|
y = (line.B * x) + line.C;
|
||
|
}
|
||
|
|
||
|
return new Point(x, y);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Generates a PolyLine, which can be merged with another to make a full element shape.
|
||
|
/// </summary>
|
||
|
public override void GeneratePolyLine()
|
||
|
{
|
||
|
PolyLine.Add(new Point(-SideSign * Parent.Depth / 2, SideSign * -Parent.Diameter / 2));
|
||
|
PolyLine.Add(new Point(-SideSign * Parent.Depth / 2, SideSign * Parent.Diameter / 2));
|
||
|
}
|
||
|
|
||
|
protected FlatSurface(Element parent) : base(parent)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|