private void GetStartEndPoints(out Point start, out Point end, out double startAngle) { start = null; end = null; startAngle = -1; // Find the first point so we sweep in a counter-clockwise manner. double angle1 = Point.GetRadianStandardAngleWithCenter(theCircle.center, endpoint1); double angle2 = Point.GetRadianStandardAngleWithCenter(theCircle.center, endpoint2); // Define to vectors: vect1: A----->B // vect2: B----->C // Cross product vect1 and vect2. // If the result is positive, the sequence A-->B-->C is Counter-clockwise. // If the result is negative, the sequence A-->B-->C is clockwise. Point vect1 = Point.MakeVector(this.middlePoint, this.endpoint1); Point vect2 = Point.MakeVector(this.endpoint2, this.middlePoint); if (Point.CrossProduct(vect1, vect2) > 0) { start = endpoint1; end = endpoint2; startAngle = angle1; } else { start = endpoint2; end = endpoint1; startAngle = angle2; } }
public static bool CounterClockwise(Point A, Point B, Point C) { // Define two vectors: vect1: A----->B // vect2: B----->C // Cross product vect1 and vect2. // If the result is negative, the sequence A-->B-->C is Counter-clockwise. // If the result is positive, the sequence A-->B-->C is clockwise. Point vect1 = Point.MakeVector(A, B); Point vect2 = Point.MakeVector(B, C); return(Point.CrossProduct(vect1, vect2) < 0); }
// // Return True if the polygon is convex. // http://blog.csharphelper.com/2010/01/04/determine-whether-a-polygon-is-convex-in-c.aspx // protected static bool IsConcavePolygon(List <Point> orderedPts) { // For each set of three adjacent points A, B, C, // find the dot product AB · BC. If the sign of // all the dot products is the same, the angles // are all positive or negative (depending on the // order in which we visit them) so the polygon // is convex. bool got_negative = false; bool got_positive = false; int B, C; for (int A = 0; A < orderedPts.Count; A++) { B = (A + 1) % orderedPts.Count; C = (B + 1) % orderedPts.Count; // Create normalized vectors and find the cross-product. Point vec1 = Point.MakeVector(orderedPts[A], orderedPts[B]); Point vec2 = Point.MakeVector(orderedPts[B], orderedPts[C]); double cross_product = Point.CrossProduct(vec1, vec2); if (cross_product < 0) { got_negative = true; } else if (cross_product > 0) { got_positive = true; } if (got_negative && got_positive) { return(true); } } // If we got this far, the polygon is convex. return(false); }