public Line(Point origin, Point direction) : this() { Origin = origin; Direction = direction; Normal = direction.Perp(); Ax = Normal.X; By = Normal.Y; C = Point.Dot(-PointAtDistance((Real)1.0), Normal); }
public static int DetermineSide(Line line, Point normal, Point point) { Real value = Point.Dot(line.Normal, point) + line.C; if (Math.Abs(value) < MathHelper.Epsilon) { return(0); } else if (value < 0) { return(-1); } else //if (value > 0) { return(1); } }
public static Line FromTwoPoints(Point point1, Point point2) { return(new Line(point1, point2 - point1)); }
public static int DetermineSide(Line line, Point point) { return(DetermineSide(line, line.Normal, point)); }
public Point PointAtDistance(Real distance) { return(Origin + distance * Point.Normalize(Direction)); }
/// <summary> /// Returns a positive number if c is to the left of the line going from a to b. /// </summary> /// <returns>Positive number if point is left, negative if point is right, /// and 0 if points are collinear.</returns> public static double Area(ref Point a, ref Point b, ref Point c) { return(a.X * (b.Y - c.Y) + b.X * (c.Y - a.Y) + c.X * (a.Y - b.Y)); }
/// <summary> /// Returns a positive number if c is to the left of the line going from a to b. /// </summary> /// <returns>Positive number if point is left, negative if point is right, /// and 0 if points are collinear.</returns> public static double Area(Point a, Point b, Point c) { return(Area(ref a, ref b, ref c)); }
public static bool Collinear(ref Point a, ref Point b, ref Point c, double tolerance) { return(MathHelper.DoubleInRange(Area(ref a, ref b, ref c), -tolerance, tolerance)); }
/// <summary> /// Determines if three vertices are collinear (ie. on a straight line) /// </summary> /// <param name="a">First vertex</param> /// <param name="b">Second vertex</param> /// <param name="c">Third vertex</param> /// <returns></returns> public static bool Collinear(ref Point a, ref Point b, ref Point c) { return(Collinear(ref a, ref b, ref c, 0)); }