我认为这是您要寻找的:
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
Run Code Online (Sandbox Code Playgroud)
...对于贝塞尔曲线绝对不起作用。例如,在二次贝塞尔曲线上,要计算一个点,必须使用:
资料来源: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)
}
Run Code Online (Sandbox Code Playgroud)
下面是它如何映射到您的图表字母:
c = getControlPointWithPoint1(a, point2:b, length:h, clockwise:true)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5130 次 |
最近记录: |