private BezierSubdivision TangentIntersectionApproximation(Neuron neuron, out double length) { var firstPoint = neuron.Nucleus.Pos; var lastPoint = neuron.Terminal.Nucleus.Pos; var dir = Math.Sign(neuron.Terminal.Nucleus.SegmentIndex - neuron.Nucleus.SegmentIndex); var line1 = Line2.FromPoints(neuron.Nucleus.PathPoint, _path[neuron.Nucleus.SegmentIndex + dir]); var line2 = Line2.FromPoints(neuron.Terminal.Nucleus.PathPoint, _path[neuron.Terminal.Nucleus.SegmentIndex - dir]); BezierSubdivision bs; if (Line2.Intersection(line1, line2, out var intersection)) { bs = new BezierSubdivision(new List <Vector2> { firstPoint, intersection, lastPoint }); length = bs.SubdividedApproximationLength(); } else { bs = new BezierSubdivision(new List <Vector2> { firstPoint, lastPoint }); length = Vector2.Distance(firstPoint, lastPoint); } return(bs); }
public void Test4() { List <Vector2> points = new List <Vector2> { new Vector2(0, 0), new Vector2(100, 100), new Vector2(200, 0) }; BezierSubdivision subdivision = new BezierSubdivision(points); var length = new SliderPath(PathType.Bezier, points.ToArray()).Distance; var length2 = subdivision.SubdividedApproximationLength(0.25); Assert.AreEqual(length, length2, 0.001); Assert.AreEqual(0.5, subdivision.LengthToT(length / 2), 0.01); Assert.AreEqual(1, subdivision.LengthToT(length), 0.01); Assert.AreEqual(0, subdivision.LengthToT(0), 0.01); }
private static BezierSubdivision DoubleMiddleApproximation(Neuron neuron, Vector2 middlePoint, out double length) { var firstPoint = neuron.Nucleus.Pos; var lastPoint = neuron.Terminal.Nucleus.Pos; var average = (firstPoint + lastPoint) / 2; var doubleMiddlePoint = average + (middlePoint - average) * 2; var bs = new BezierSubdivision(new List <Vector2> { firstPoint, doubleMiddlePoint, lastPoint }); length = bs.SubdividedApproximationLength(); return(bs); }