寻找贝塞尔曲线的顶点
我正在使用 Flex,尽管我认为这是一个独立于语言的问题。我正在尝试使用 3 个点绘制一条曲线,使用 curveTo (二次贝塞尔函数,我不相信 Flex 有任何其他函数,如果有,请纠正我!)点 1 和 3 是“节点”,点2 是拖动手柄。
我想要的不是线向点 2 弯曲,而是实际上穿过它。我设法通过侥幸让它工作 - 通过将(点 1 和 3 之间的线的中点之间的距离)和点 2 加倍。
但这并没有把它放在线的顶点上,只是在附近的某个地方到它。
有人有什么想法吗?
安德鲁
I'm working in flex, although I reckon this is a language independent problem. I'm trying to draw a curve using 3 points, using curveTo (a quadratic bezier function, I don't believe Flex has any other, if it does, please correct me!) Points 1 and 3 are "nodes", with point 2 being a drag handle.
What I want is not for the line to curve towards point 2 but in fact pass through it. I've managed to get this working by fluking it - by doubling the (distance between the midpoint of a line between Points 1 and 3) and Point 2.
This doesn't put it on the Apex of the line though, just somewhere close to it.
Anyone any ideas?
Andrew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
二次贝塞尔曲线使用以下公式计算,
其中 P0、P1 和 P2 是您指定的 3 个点。曲线从 P0 开始,到 P2 结束
t 的范围为 0 到 1
应在 t = 0.5 时达到顶点
因此尝试将 P0、P2 和 t = 0.5 插入公式中,使其等于以下点:
你想要的顶点是并从公式中提取 P1
the quadric bezier curve is calculate using the formula
where P0,P1 and P2 are the 3 points you specify. The curve starts in P0 and ends in P2
t ranges from 0 to 1
the apex should be reached at t = 0.5
so try to insert P0, P2 and t = 0.5 into the formula set it equal to the point where
you want the apex to be and extract P1 from the formula
使用以下公式:
B'(t) = 3 (1 - t) 2 (P1 - P0) + 6 (1 - t) t (P2 - P1) + 3 t2 (P3 - P2)
您可以使用导数来查找最大值和最小值。
Us this formula:
B'(t) = 3 (1 - t) 2 (P1 - P0) + 6 (1 - t) t (P2 - P1) + 3 t2 (P3 - P2)
You can use the derivative to find maximums and minimums.
Bezier 样条线不会通过其控制点,但 Catmull Rom 样条线会通过。
B(t) = ((2*P1)+(-P0+P2)*t + (2*P0-5*P1+4*P2-P3)*t*t + (-P0+3* P1-3*P2+P3)*t*t*t )) / 2
虽然这是三次样条而不是二次样条。你可以尝试制作
P1=P2
A Bezier spline will not pass through its control points, but a Catmull Rom spline will.
B(t) = ((2*P1)+(-P0+P2)*t + (2*P0-5*P1+4*P2-P3)*t*t + (-P0+3*P1-3*P2+P3)*t*t*t )) / 2
Although this is a cubic rather than quadratic spline. You could try making
P1=P2