2DLightPathSimulator/LensSimulatorCore/Shapes/Shapes.cs

75 lines
1.4 KiB
C#
Raw Normal View History

2023-06-06 22:56:56 +00:00
namespace LensSimulatorCore.Shapes;
public struct Line
{
public double B { get; set; }
public double C { get; set; }
public Line(double b, double c)
{
B = b;
C = c;
}
}
public class Point
{
public Point(double x, double y)
{
X = x;
Y = y;
}
public double X { get; set; }
public double Y { get; set; }
/// <summary>
/// Converts an angle in Radians to a Vector.
/// </summary>
/// <param name="angle"></param>
/// <returns></returns>
public static Point AngleToVector(double angle)
{
return new(Math.Cos(-angle), Math.Sin(-angle));
}
}
public struct PointVector
{
public PointVector(Point point, Point vector)
{
Point = point;
Vector = vector;
}
public Point Point { get; set; }
public Point Vector { get; set; }
public Line ToLine()
{
var angle = -Math.Atan2(this.Vector.Y, this.Vector.X);
var b = Math.Tan(angle);
var c = this.Point.Y - (this.Point.X * b);
return new Line(b, c);
}
}
/// <summary>
/// A circle as defined by (x - a)² + (y - b)² = r².
/// </summary>
//public struct Circle
//{
// public double Radius { get; set; }
//
// public Point Position { get; set; }
//
// public Circle(double radius, Point position)
// {
// Radius = radius;
// Position = position;
// }
//}