public static double get_angle(Point a, Point b) { double a2_x = a.X + 5; double a2_y = a.Y; Point a2 = new Point(a2_x, a2_y); Point Vec_1 = a.Vector(a2); Point Vec_2 = a.Vector(b); double cross = HelperMethods.CrossProduct(Vec_1, Vec_2); double dot = HelperMethods.dotProduct(Vec_1, Vec_2); //dot = x1*x2 + y1*y2 # dot product //det = x1*y2 - y1*x2 # determinant == cross product //angle = atan2(det, dot) # atan2(y, x) or atan2(sin, cos) //and you may want to normalize it to the range 0 .. 2 * Pi: // if (angle < 0) angle += 2 * M_PI; double angle = Math.Atan2(cross, dot) * (180 / Math.PI); if (angle < 0) { // law darbt fo2 fe (180 / Math.PI) // law tel3 el angle < 0 , add 360 // law msh darbt fo2 fe (180 / Math.PI) // law tel3 el angle < 0 , add (2 * math.PI) angle += 360; } return(angle); }
public static double distOfPointFromSegment(Point a, Point b, Point p) { Point VectorAB = a.Vector(b); Point VectorAP = a.Vector(p); double crossProduct = CrossProduct(VectorAB, VectorAP); double DistanceAB = Math.Sqrt(((b.Y - a.Y) * (b.Y - a.Y)) + ((b.X - a.X) * (b.X - a.X))); double height = crossProduct / DistanceAB; return(Math.Abs(height)); }
public static bool PointOnRay(Point p, Point a, Point b) { if (a.Equals(b)) { return(true); } if (a.Equals(p)) { return(true); } var q = a.Vector(p).Normalize(); var w = a.Vector(b).Normalize(); return(q.Equals(w)); }
public static double CalculateAngle(Point a, Point b, Point c) { Point vecBA = b.Vector(a); Point vecBC = b.Vector(c); double crossProduct = CrossProduct(vecBA, vecBC); double dotProduct = DotProduct(vecBA, vecBC); double radianAngle = Math.Atan2(crossProduct, dotProduct); if (radianAngle < 0) { radianAngle += Math.PI * 2; } double degreeAngle = radianAngle * 180 / Math.PI; return(degreeAngle); }
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); }