Exemplo n.º 1
0
        /// <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.");
            }
        }
Exemplo n.º 2
0
        /// <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));
        }
Exemplo n.º 3
0
 public static bool ApproximateEquals(this Plane2d a, Plane2d b, double tolerance) =>
 ApproximateEquals(a.Normal, b.Normal, tolerance) &&
 ApproximateEquals(a.Distance, b.Distance, tolerance);
Exemplo n.º 4
0
 public static bool ApproximateEquals(this Plane2d a, Plane2d b)
 => ApproximateEquals(a, b, Constant <double> .PositiveTinyValue);
Exemplo n.º 5
0
 public bool Equals(Plane2d other)
 => Normal.Equals(other.Normal) && Distance.Equals(other.Distance);