Example #1
0
        public Point GetPoint(SplinePositionReference positionReference)
        {
            double s = (1 - this.tension) / 2;

            Point[] points = this.controlPoints.ToArray();

            int    cpIndex = positionReference.ControlPoint;
            double t       = positionReference.T;

            if (cpIndex < 0 || cpIndex >= points.Length - 1 || t < 0 || t > 1)
            {
                return(default(Point));
            }

            Point p1, p2, p3, p4;

            if (cpIndex == 0)
            {
                if (points.Length > 2)
                {
                    p1 = new Point(points[0].X - (points[1].X - points[0].X), points[0].Y - (points[1].Y - points[0].Y));
                    p2 = points[0];
                    p3 = points[1];
                    p4 = points[2];
                }
                else
                {
                    p1 = new Point(points[0].X - (points[1].X - points[0].X), points[0].Y - (points[1].Y - points[0].Y));
                    p2 = points[0];
                    p3 = points[1];
                    p4 = new Point(points[points.Length - 1].X - (points[points.Length - 2].X - points[points.Length - 1].X),
                                   points[points.Length - 1].Y - (points[points.Length - 2].Y - points[points.Length - 1].Y));
                }
            }
            else if (cpIndex < points.Length - 2)
            {
                p1 = points[cpIndex - 1];
                p2 = points[cpIndex];
                p3 = points[cpIndex + 1];
                p4 = points[cpIndex + 2];
            }
            else
            {
                p1 = points[points.Length - 3];
                p2 = points[points.Length - 2];
                p3 = points[points.Length - 1];
                p4 = new Point(points[points.Length - 1].X - (points[points.Length - 2].X - points[points.Length - 1].X),
                               points[points.Length - 1].Y - (points[points.Length - 2].Y - points[points.Length - 1].Y));
            }

            return(CalculateCardinalSplinePoint(s, t, p1, p2, p3, p4));
        }
        public double GetLength(SplinePositionReference positionReference)
        {
            if (positionReference.ControlPoint < 0)
            {
                return(0.0);
            }
            else if (positionReference.ControlPoint >= this.sampledPointsLengths.Length - 1)
            {
                return(this.sampledPointsLengths[this.sampledPointsLengths.Length - 1]);
            }

            // Interpolate
            double t     = positionReference.T;
            int    index = positionReference.ControlPoint;

            return(this.sampledPointsLengths[index] * (1 - t) + this.sampledPointsLengths[index + 1] * t);
        }
        public Point GetPoint(SplinePositionReference positionReference)
        {
            if (positionReference.ControlPoint < 0)
            {
                return(this.sampledPoints[0]);
            }
            else if (positionReference.ControlPoint >= this.sampledPointsLengths.Length - 1)
            {
                return(this.sampledPoints[this.sampledPoints.Length - 1]);
            }

            // Interpolate
            double t     = positionReference.T;
            int    index = positionReference.ControlPoint;

            return(new Point(this.sampledPoints[index].X * (1 - t) + this.sampledPoints[index + 1].X * t,
                             this.sampledPoints[index].Y * (1 - t) + this.sampledPoints[index + 1].Y * t));
        }