Example #1
0
        List <ICustomPoint> SplitSegment(ISegment segment, double accuracy, double step, int segmentNum)
        {
            Point startPoint           = segment.GetCurvePoint(0);
            Point lastPoint            = segment.GetCurvePoint(1);
            List <ICustomPoint> result = new List <ICustomPoint>()
            {
                new CustomPoint(segmentNum, 0, startPoint)
            };

            double t      = 0;
            double startT = t;

            while (t < 1)
            {
                double nextT = t + step;
                if (nextT > 1)
                {
                    nextT = 1;
                }
                Point currentPoint = segment.GetCurvePoint(t);
                Point nextPoint    = segment.GetCurvePoint(nextT);

                double length     = (currentPoint - startPoint).Length;
                double nextLength = (nextPoint - startPoint).Length;

                if ((length < accuracy && nextLength > accuracy) || nextLength < length)
                {
                    result.Add(new CustomPoint(segmentNum, nextT, nextPoint));
                    startPoint = nextPoint;
                    startT     = nextT;
                }
                t = nextT;
            }

            if (result.Count > 1 && (lastPoint - result.Last().GetPoint()).Length < lastPartAccuracy * accuracy)
            {
                result.RemoveAt(result.Count - 1);
                double middleT = (1 + result.Last().GetT()) / 2;
                result.Add(new CustomPoint(segmentNum, middleT, segment.GetCurvePoint(middleT)));
            }

            result.Add(new CustomPoint(segmentNum, 1, lastPoint));

            return(result);
        }
Example #2
0
        private void ShowNormal_Click(object sender, RoutedEventArgs e)
        {
            if (model == null)
            {
                MessageBox.Show("No model is imported");
                return;
            }

            string[] debugParams = textBox_Debug.Text.Split(';');
            int      segmentNum  = 0;
            double   t           = 0;
            double   multiplier  = 0;

            try
            {
                segmentNum = int.Parse(debugParams[0]);
                t          = double.Parse(debugParams[1], CultureInfo.InvariantCulture);
                multiplier = double.Parse(debugParams[2], CultureInfo.InvariantCulture);
            }
            catch
            {
                MessageBox.Show("Wrong format in debug parameters.\nFormat is:\n    <segment number>;<t value>;<multiplier value>");
                return;
            }

            ISegment chosenSegment    = model.GetCanvasData().ElementAt(segmentNum);
            Point    pointOnSegment   = chosenSegment.GetCurvePoint(t);
            Normal   normalForSegment = chosenSegment.GetNormal(t);

            if (t == 0)
            {
                int prevSegmentNum = segmentNum == 0 ? model.GetCanvasData().Count() - 1 : segmentNum - 1;
                normalForSegment = normalForSegment.Combine(model.GetCanvasData().ElementAt(prevSegmentNum).GetNormal(1));
            }
            else if (t == 1)
            {
                int nextSegmentNum = segmentNum == model.GetCanvasData().Count() - 1 ? 0 : segmentNum + 1;
                normalForSegment = model.GetCanvasData().ElementAt(nextSegmentNum).GetNormal(0).Combine(normalForSegment);
            }
            ISegment normalSegment = new Segment(new BezierCurve(), new List <Point>()
            {
                pointOnSegment,
                new Point(pointOnSegment.X + multiplier * normalForSegment.Dx(), pointOnSegment.Y + multiplier * normalForSegment.Dy())
            });

            View.VisibleDataSettings settings = new View.VisibleDataSettings();
            settings.Brush    = Brushes.Blue;
            settings.Thikness = 1;
            IMidSurface debugSurface = new MidSurface();

            debugSurface.Add(normalSegment);
            View.VisibleData visible_data = new View.VisibleData(debugSurface, settings);
            view.Paint(visible_data);
        }
Example #3
0
 public Point GetCurvePoint(double t)
 {
     return(segment.GetCurvePoint(t));
 }