/**
         *  Sample the given points as a Bezier path.
         */
        public void SamplePoints(Point3DList sourcePoints, double minSqrDistance, double maxSqrDistance, double scale)
        {
            if (sourcePoints.Count < 2)
            {
                return;
            }

            Stack <Point3D> samplePoints = new Stack <Point3D>();

            samplePoints.Push(sourcePoints[0]);

            Point3D potentialSamplePoint = sourcePoints[1];

            int i = 2;

            for (i = 2; i < sourcePoints.Count; i++)
            {
                if (
                    ((potentialSamplePoint.Position - sourcePoints[i].Position).LengthSquared > minSqrDistance) &&
                    ((samplePoints.Peek().Position - sourcePoints[i].Position).LengthSquared > maxSqrDistance))
                {
                    samplePoints.Push(potentialSamplePoint);
                }

                potentialSamplePoint = sourcePoints[i];
            }

            //now handle last bit of curve
            Point3D p1 = samplePoints.Pop();  //last sample point
            Point3D p0 = samplePoints.Peek(); //second last sample point


            Vector3d posT      = (p0.Position - potentialSamplePoint.Position).Normalized();
            double   pos_d2    = (potentialSamplePoint.Position - p1.Position).Length;
            double   pos_d1    = (p1.Position - p0.Position).Length;
            double   pos_scale = ((pos_d1 - pos_d2) / 2f);
            Vector3d pos_      = p1.Position + posT * pos_scale;

            Vector3d normT   = (p0.Normal - potentialSamplePoint.Normal).Normalized();
            double   norm_d2 = (potentialSamplePoint.Normal - p1.Normal).Length;
            double   norm_d1 = (p1.Normal - p0.Normal).Length;
            Vector3d norm_   = p1.Normal + normT * ((norm_d1 - norm_d2) / 2);


            samplePoints.Push(new Point3D(pos_, norm_, p1.Color.GetStepColor(p0.Color, pos_scale)));
            samplePoints.Push(potentialSamplePoint);
            Point3DList l = new Point3DList(samplePoints.Count);

            l.AddRange(samplePoints);
            Interpolate(l, scale);
        }
        /**
         *  This gets the drawing points of a bezier curve, using recursive division,
         *  which results in less points for the same accuracy as the above implementation.
         */
        public Point3DList GetDrawingPoints2()
        {
            Point3DList drawingPoints = new Point3DList();

            for (int curveIndex = 0; curveIndex < curveCount; curveIndex++)
            {
                Point3DList bezierCurveDrawingPoints = FindDrawingPoints(curveIndex);

                if (curveIndex != 0)
                {
                    //remove the fist point, as it coincides with the last point of the previous Bezier curve.
                    bezierCurveDrawingPoints.RemoveAt(0);
                }

                drawingPoints.AddRange(bezierCurveDrawingPoints);
            }

            return(drawingPoints);
        }
Beispiel #3
0
        /// <summary>
        /// Get a interpolated list of this list composed od "count" point
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        public Point3DList GetInterpolatedList(int count)
        {
            Point3DList ret = new Point3DList(count);

            if (count == 0)
            {
                return(ret);
            }
            else if (count == Count)
            {
                ret.AddRange(this);
            }
            else
            {
                double max = Max.Y;
                double d   = (max - Min.Y) / count;
                for (int i = 0; i < count; i++)
                {
                    Point3D p = GetInterpolateByY(max - i * d, i == 0);
                    ret.Add(p);
                }
            }
            return(ret);
        }
 /**
  *  Sets the control points of this Bezier path.
  *  Points 0-3 forms the first Bezier curve, points
  *  3-6 forms the second curve, etc.
  */
 public void SetControlPoints(Point3DList newControlPoints)
 {
     controlPoints.Clear();
     controlPoints.AddRange(newControlPoints);
     curveCount = (controlPoints.Count - 1) / 3;
 }