|
@@ -13,23 +13,48 @@ namespace bbiwarg.Utility
|
|
|
below = 2
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Line lass which represents a infinity line in 2 dimensional space.
|
|
|
+ /// </summary>
|
|
|
public class Line2D
|
|
|
{
|
|
|
+ /// <summary>
|
|
|
+ /// one point on the line
|
|
|
+ /// </summary>
|
|
|
public Vector2D PointOnLine { get; private set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// direction vector of the line
|
|
|
+ /// </summary>
|
|
|
public Vector2D Direction { get; private set; }
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Standard constructor which sets the essential attributes
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="pointOnLine"><see cref="PointOnLine"/></param>
|
|
|
+ /// <param name="direction"><see cref="Direction"/></param>
|
|
|
public Line2D(Vector2D pointOnLine, Vector2D direction)
|
|
|
{
|
|
|
PointOnLine = pointOnLine;
|
|
|
Direction = direction.normalize();
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Computes angle between current and an second line in degrees.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="line">second line</param>
|
|
|
+ /// <returns>angle between this and line in degrees</returns>
|
|
|
public float getAngleBetween(Line2D line)
|
|
|
{
|
|
|
float angle = Direction.getAngleBetween(line.Direction);
|
|
|
return Math.Min(angle, 180 - angle);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Calculates whether a point is above, below or on this line
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="point">point which is used to compute the side</param>
|
|
|
+ /// <returns>LineSide.above iff point is above this, LineSide.below iff point is below this, LineSide.onLine iff point is on this line</returns>
|
|
|
public LineSide onSide(Vector2D point)
|
|
|
{
|
|
|
float yPerX = Direction.Y / Direction.X;
|
|
@@ -40,6 +65,11 @@ namespace bbiwarg.Utility
|
|
|
else return LineSide.onLine;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Projects a point on this line.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="point">point which is projected</param>
|
|
|
+ /// <returns>th point on the line with minimal distance to input point</returns>
|
|
|
public Vector2D projectToLine(Vector2D point)
|
|
|
{
|
|
|
float px = point.X, py = point.Y, dx = Direction.X, dy = Direction.Y, ox = PointOnLine.X, oy = PointOnLine.Y;
|
|
@@ -55,7 +85,12 @@ namespace bbiwarg.Utility
|
|
|
|
|
|
return new Vector2D(newX, newY);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Computes the intersection of two lines, iff the lines do not intersect it returns null
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="line">the second line</param>
|
|
|
+ /// <returns>the intersection or null iff the lines do not intersect</returns>
|
|
|
public Vector2D getIntersection(Line2D line)
|
|
|
{
|
|
|
Vector2D p = PointOnLine;
|