public static bool PointOnSegment(Point p, Point a, Point b) { if (a.Equals(b)) { return(p.Equals(a)); } if (b.X == a.X) { return(p.X == a.X && (p.Y >= Math.Min(a.Y, b.Y) && p.Y <= Math.Max(a.Y, b.Y))); } if (b.Y == a.Y) { return(p.Y == a.Y && (p.X >= Math.Min(a.X, b.X) && p.X <= Math.Max(a.X, b.X))); } double tx = (p.X - a.X) / (b.X - a.X); double ty = (p.Y - a.Y) / (b.Y - a.Y); return(Math.Abs(tx - ty) <= Constants.Epsilon && tx <= 1 && tx >= 0); }
public static double getAngle(Point a, Point b, Point c) { if (a.Equals(b) || b.Equals(c)) { return(10); } Point VecB = a.Vector(b); Point VecC = b.Vector(c); double ang = Math.Acos(dot(VecB, VecC) / (VecB.Magnitude() * VecC.Magnitude())); double angB = Math.Atan2(VecB.Y, VecB.X); double angC = Math.Atan2(VecC.Y, VecC.X); angB += (angB < 0 ? 2 * Math.PI : 0); angC += (angC < 0 ? 2 * Math.PI : 0); if (Math.Abs(angC - angB - ang) > 1e-6) { ang = ang - 2; } ang = (angC - angB) + ((angC - angB) < 0 ? 2 * Math.PI : 0); return(ang); }