/// <summary> /// Creates circle from three points. /// </summary> public Circle2d(V2d a, V2d b, V2d c) { var l0 = new Plane2d((b - a).Normalized, (a + b) * 0.5); var l1 = new Plane2d((c - b).Normalized, (b + c) * 0.5); if (l0.Intersects(l1, out Center)) { Radius = (a - Center).Length; } else { throw new Exception("Cannot construct circle because given points are collinear."); } }
/// <summary> /// Creates an inward hull (i.e. a hull whose normal vectors point /// inside) from a counter-clockwise enumerated array of polygon /// points. /// </summary> public static Hull2d ToInwardHull(this V2d[] polygon, int pointCount = 0) { if (pointCount == 0) { pointCount = polygon.Length; } var planeArray = new Plane2d[pointCount]; var p0 = polygon[pointCount - 1]; for (int i = 0; i < pointCount; i++) { var p1 = polygon[i]; planeArray[i] = new Plane2d((p1 - p0).Rot90.Normalized, p0); p0 = p1; } return(new Hull2d(planeArray)); }
public static bool ApproximateEquals(this Plane2d a, Plane2d b, double tolerance) => ApproximateEquals(a.Normal, b.Normal, tolerance) && ApproximateEquals(a.Distance, b.Distance, tolerance);
public static bool ApproximateEquals(this Plane2d a, Plane2d b) => ApproximateEquals(a, b, Constant <double> .PositiveTinyValue);
public bool Equals(Plane2d other) => Normal.Equals(other.Normal) && Distance.Equals(other.Distance);