public Point Intersect(Line line) { if (IsParallel(line)) { return(new Point(double.NaN, double.NaN)); } Vector a = new Vector(line.a, this.a); Vector b = new Vector(line.b, this.b); Vector c = new Vector(line.c, this.c); return(new Point(-c.GetDotProduct(b) / a.GetDotProduct(b), -a.GetDotProduct(c) / a.GetDotProduct(b))); }
public static Point[] OrderClockwise(params Point[] points) { for (int i = 0; i < points.Length; ++i) { if (points[0] > points[i]) { Point forSwap = points[0]; points[0] = points[i]; points[i] = forSwap; } } for (int i = 1; i < points.Length; ++i) { for (int j = i + 1; j < points.Length; ++j) { Vector toI = new Vector(points[0], points[i]); Vector toJ = new Vector(points[0], points[j]); if (toI.GetDotProduct(toJ) > 0) { Point forSwap = points[i]; points[i] = points[j]; points[j] = forSwap; } } } return(points); }