计算Bezier曲线的中点

我有一个通过三点绘制Bezier Curve的函数。 我已经有2点(开始和结束) – A和B.我如何计算这两点之间的中点,因为中点总是比这两点的线性函数略高或低一点。

示例

在此处输入图像描述

任何公式,想法都会很棒!

我想这就是你要找的东西:

http://blog.sklambert.com/finding-the-control-points-of-a-bezier-curve/

它详细介绍了计算贝塞尔曲线上的各个点。

您可能还对您的应用程序的这个更具体的示例感兴趣:

http://www.codeproject.com/Articles/223159/Midpoint-Algorithm-Divide-and-Conquer-Method-for-D

如果你真的想进入它,那么我建议这个入门:

http://pomax.github.io/bezierinfo/

贝塞尔曲线比简单弧更复杂。 对于弧线,您可以使用以下公式:

 R = H/2 + W^2/8H 

……这绝对不适用于Bezier曲线。 例如,在二次贝塞尔曲线上,要计算一个点,您必须使用:

在此处输入图像描述

来源: http : //en.wikipedia.org/wiki/B%C3%A9zier_curve , 二次贝塞尔曲线:计算点

下面是我用来获得四边形贝塞尔曲线的控制点。 它应该适用于控制点在曲线上的问题。 它在Swift中,但您应该能够轻松地将其转换为另一种语言。 基本上在线的中点(其点是point1和point2),我计算出具有给定长度的垂直线。 顺时针参数确定该点应该落在哪一侧。

 func getControlPointWithPoint1(point1:CGPoint, point2:CGPoint, length:CGFloat, clockwise:Bool) -> CGPoint { let angle = getAngleWithPoint1(point1, point2:point2) let direction = clockwise ? 1 : -1 let perpendicularAngle = angle + (CGFloat(direction) * CGFloat((M_PI / 2))) let midPoint = getMidPointWithPoint1(point1, point2:point2) return CGPointMake(midPoint.x + (cos(perpendicularAngle) * length), midPoint.y + (sin(perpendicularAngle) * length)) } func getAngleWithPoint1(point1:CGPoint, point2:CGPoint) -> CGFloat { return atan2((point2.y - point1.y), (point2.x - point1.x)) } func getMidPointWithPoint1(point1:CGPoint, point2:CGPoint) -> CGPoint { return CGPointMake((point1.x + point2.x) / 2, (point1.y + point2.y) / 2) } 

下面是它如何映射到您的图表字母:

 c = getControlPointWithPoint1(a, point2:b, length:h, clockwise:true) 

按照Mark的回答,这是C#中的片段

 public static Path DrawBezeireUsingTwoPoints(Point startPoint, Point endPoint) { Path path = new Path(); PathFigure pathFigure = new PathFigure(); // Set up the Path to insert the segments PathGeometry pathGeometry = new PathGeometry(); BezierSegment bezeireSeg; // Draw an ellipse passing by the 2 points and let the path cross it Point beziereMidPoint = CalculateBezierePoint(startPoint, endPoint, true); bezeireSeg = new BezierSegment(startPoint, beziereMidPoint, endPoint, true); pathFigure.StartPoint = startPoint; pathFigure.IsClosed = false; pathFigure.Segments.Add(bezeireSeg); pathGeometry.Figures.Add(pathFigure); path.Data = pathGeometry; path.Stroke = Brushes.Brown; path.StrokeThickness = 2; return path; }