Example #1
0
        public static Tuple<Point, Point> GetControlPoints_Middle(Point end1, Point end2, Point end3, double percentAlong12 = .25, double percentAlong23 = .25)
        {
            // Just use the 3D overload
            var retVal = GetControlPoints_Middle(end1.ToPoint3D(), end2.ToPoint3D(), end3.ToPoint3D(), percentAlong12, percentAlong23);

            // Convert the response back to 2D
            return Tuple.Create(retVal.Item1.ToPoint2D(), retVal.Item2.ToPoint2D());
        }
Example #2
0
        private void Test2Segments2D(Point end1, Point end2, Point end3)
        {
            // Control points for 2
            var controlPoints = BezierUtil.GetControlPoints_Middle(end1, end2, end3, trkSingleLine2Segments2DPercent.Value, trkSingleLine2Segments2DPercent.Value);

            Point3D[] allEndPoints = new[] { end1, end2, end3 }.Select(o => o.ToPoint3D()).ToArray();

            var segment12 = new BezierSegment3D(0, 1, new[] { end1.ToPoint3D(), controlPoints.Item1.ToPoint3D() }, allEndPoints);
            var segment23 = new BezierSegment3D(1, 2, new[] { controlPoints.Item2.ToPoint3D(), end3.ToPoint3D() }, allEndPoints);

            // Calculate the beziers
            Point3D[] bezierPoints12 = BezierUtil.GetPoints(100, segment12);
            Point3D[] bezierPoints23 = BezierUtil.GetPoints(100, segment23);

            #region Draw

            PrepFor2D();

            foreach (var bezier in new[] { Tuple.Create(segment12, bezierPoints12), Tuple.Create(segment23, bezierPoints23) })
            {
                // Main Line
                for (int cntr = 0; cntr < bezier.Item2.Length - 1; cntr++)
                {
                    AddLine(bezier.Item2[cntr].ToPoint2D(), bezier.Item2[cntr + 1].ToPoint2D(), _mainLineB, 3);
                }

                if (chkShowDots.IsChecked.Value)
                {
                    foreach (Point3D point in bezier.Item2)
                    {
                        AddDot(point.ToPoint2D(), _mainLineB, 8);
                    }

                    // Control Lines
                    Point[] allPoints = UtilityCore.Iterate<Point3D>(bezier.Item1.EndPoint0, bezier.Item1.ControlPoints, bezier.Item1.EndPoint1).Select(o => o.ToPoint2D()).ToArray();

                    for (int cntr = 0; cntr < allPoints.Length - 1; cntr++)
                    {
                        AddLine(allPoints[cntr], allPoints[cntr + 1], _controlLineB, 1);
                    }

                    for (int cntr = 0; cntr < bezier.Item1.ControlPoints.Length; cntr++)
                    {
                        AddDot(bezier.Item1.ControlPoints[cntr].ToPoint2D(), _controlPointB);
                    }
                }
            }

            // End Points
            if (chkShowDots.IsChecked.Value)
            {
                AddDot(end1, _endPointB);
                AddDot(end2, _endPointB);
                AddDot(end3, _endPointB);
            }

            #endregion
        }