Example #1
0
 /// <summary>
 /// Returns true if the supplied point is inside a hull with
 /// planes whose normal vectors point to the inside of the hull.
 /// The optional offset parameter is measured in normal direction,
 /// i.e. a positive offset makes the hull smaller.
 /// </summary>
 public static bool IsInsideInwardHull(this V2d point, Hull2d hull, double offset = 0.0)
 {
     for (int i = 0; i < hull.PlaneCount; i++)
     {
         if (hull.PlaneArray[i].Height(point) < offset)
         {
             return(false);
         }
     }
     return(true);
 }
Example #2
0
        public void TransformInto(Trafo2d trafo, ref Hull2d hull)
        {
            int count = PlaneCount;
            var invTr = trafo.Backward.Transposed;

            for (int i = 0; i < count; i++)
            {
                hull.PlaneArray[i]
                    = new Plane2d(
                          invTr.TransformDir(PlaneArray[i].Normal).Normalized,
                          trafo.Forward.TransformPos(PlaneArray[i].Point));
            }
        }
Example #3
0
        public Hull2d Transformed(Trafo2d trafo)
        {
            int count = PlaneCount;
            var hull  = new Hull2d(new Plane2d[count]);
            var invTr = trafo.Backward.Transposed;

            for (int i = 0; i < count; i++)
            {
                hull.PlaneArray[i]
                    = new Plane2d(
                          invTr.TransformDir(PlaneArray[i].Normal).Normalized,
                          trafo.Forward.TransformPos(PlaneArray[i].Point));
            }
            return(hull);
        }
Example #4
0
        /// <summary>
        /// Returns unordered set of corners of this hull.
        /// </summary>
        public static HashSet <V2d> ComputeCorners(this Hull2d hull)
        {
            var corners = new HashSet <V2d>();
            int count   = hull.PlaneArray.Length;

            for (var i0 = 0; i0 < count; i0++)
            {
                for (var i1 = i0 + 1; i1 < count; i1++)
                {
                    if (hull.PlaneArray[i0].Intersects(hull.PlaneArray[i1], out V2d temp))
                    {
                        if (temp.IsNaN || temp.AnyInfinity)
                        {
                            continue;
                        }

                        var inside = true;
                        for (var j = 0; j < count; j++)
                        {
                            if (j == i0 || j == i1)
                            {
                                continue;
                            }
                            var h = hull.PlaneArray[j].Height(temp);
                            if (h > 0)
                            {
                                inside = false; break;
                            }
                        }

                        if (inside)
                        {
                            corners.Add(temp);
                        }
                    }
                }
            }

            return(corners);
        }
Example #5
0
 public Hull2d(Hull2d hull)
 {
     PlaneArray = hull.PlaneArray.Copy();
 }