Beispiel #1
0
        public static List <HandCurve> Combine(HandCurve handCurve1, HandCurve handCurve2)
        {
            if (!(handCurve1.curve is OpenCurve))
            {
                throw new System.Exception("handCurve1 must be open");
            }
            if (!(handCurve2.curve is OpenCurve))
            {
                throw new System.Exception("handCurve2 must be open");
            }

            (OpenCurve curve1, OpenCurve curve2) = AdjustOrientation((OpenCurve)handCurve1.curve, (OpenCurve)handCurve2.curve);

            List <HandCurve>        newHandCurves = new List <HandCurve>();
            IReadOnlyList <Vector3> points1       = curve1.GetPoints();
            IReadOnlyList <Vector3> points2       = curve2.GetPoints();

            if (Vector3.Distance(points1.Last(), points2.First()) < collision)
            {
                OpenCurve newCurve = curve1.Concat(curve2);
                bool      closed   = newCurve.DistanceOfFirstAndLast() < collision;
                newHandCurves.Add(new HandCurve(newCurve.ChangeClosed(closed), selected: true));
            }

            return(newHandCurves);
        }
Beispiel #2
0
        public HandCurve DeepCopy()
        {
            IReadOnlyList <Vector3> points = ListVector3Copy(this.curve.GetPoints());
            HandCurve curve = new HandCurve(Curve.Create(this.closed, points), segment: this.segment);

            curve.selected = this.selected;
            curve.position = Vector3Copy(this.position);
            curve.rotation = QuaternionCopy(this.rotation);
            return(curve);
        }
Beispiel #3
0
        private HandCurve CutKnot(int num)
        {
            IReadOnlyList <Vector3> points    = this.curve.GetPoints();
            List <Vector3>          newPoints = new List <Vector3>();

            for (int i = num + 1; i < Length(); i++)
            {
                newPoints.Add(points[i]);
            }

            for (int i = 0; i < num; i++)
            {
                newPoints.Add(points[i]);
            }

            HandCurve cutKnot = new HandCurve(new OpenCurve(newPoints), selected: true);

            return(cutKnot);
        }
Beispiel #4
0
        private (HandCurve, HandCurve) CutCurve(int num)
        {
            IReadOnlyList <Vector3> points     = this.curve.GetPoints();
            List <Vector3>          newPoints1 = new List <Vector3>();
            List <Vector3>          newPoints2 = new List <Vector3>();

            for (int i = 0; i < num; i++)
            {
                newPoints1.Add(points[i]);
            }

            for (int i = num + 1; i < Length(); i++)
            {
                newPoints2.Add(points[i]);
            }

            HandCurve newCurve1 = new HandCurve(new OpenCurve(newPoints1), selected: true);
            HandCurve newCurve2 = new HandCurve(new OpenCurve(newPoints2), selected: true);

            return(newCurve1, newCurve2);
        }
Beispiel #5
0
        public float CurveDistance(HandCurve other)
        {
            IReadOnlyList <Vector3> thisPoints  = this.curve.GetPoints();
            IReadOnlyList <Vector3> otherPoints = other.curve.GetPoints();
            float min  = float.PositiveInfinity;
            int   n1   = this.Length();
            int   n2   = other.Length();
            int   end1 = this.closed ? n1 - 1 : n1 - 2;
            int   end2 = other.closed ? n2 - 1 : n2 - 2;

            for (int i = 0; i <= end1; i++)
            {
                for (int j = 0; j <= end2; j++)
                {
                    float dist = SegmentDist.SSDist(thisPoints[i], thisPoints[(i + 1) % n1], otherPoints[j], otherPoints[(j + 1) % n2]);
                    if (dist < min)
                    {
                        min = dist;
                    }
                }
            }

            return(min);
        }