如何计算贝塞尔曲线上的控制点?
我确实有一条贝塞尔曲线,在某个点上,我想要第二条贝塞尔曲线以平滑的方式“分支”第一条曲线。除了计算交点(贝塞尔曲线后面的百分比)之外,我还需要控制点(切线和权重)。 交点是使用以下 javascript 计算的:(
getBezier = function getBez(percent,p1,cp1,cp2,p2) {
function b1(t) { return t*t*t }
function b2(t) { return 3*t*t*(1-t) }
function b3(t) { return 3*t*(1-t)*(1-t) }
function b4(t) { return (1-t)*(1-t)*(1-t) }
var pos = {x:0,y:0};
pos.x = p1.x*b1(percent) + cp1.x*b2(percent) + cp2.x*b3(percent) + p2.x*b4(percent);
pos.y = p1.y*b1(percent) + cp1.y*b2(percent) + cp2.y*b3(percent) + p2.y*b4(percent);
return pos;
}
非 IE 浏览器可以在 http://www. iscriptdesign.com -> 教程 -> 组和路径)。 我现在需要的是分支点的控制点或(切线和权重)(我不知道从哪里开始,我希望有人可以指出一些代码或数学方程,如果可能的话作为来自相同参数的函数如上面的 getBezier 函数)。
I do have a bezier curve, and at a certain point, I want a second bezier curve "branching off" the first curve in a smooth manner. Together with calculating the intersection point (with a percentage following the Bezier curve), I need also the control point (the tangent and weight).
The intersection point is calculated with the following piece of javascript:
getBezier = function getBez(percent,p1,cp1,cp2,p2) {
function b1(t) { return t*t*t }
function b2(t) { return 3*t*t*(1-t) }
function b3(t) { return 3*t*(1-t)*(1-t) }
function b4(t) { return (1-t)*(1-t)*(1-t) }
var pos = {x:0,y:0};
pos.x = p1.x*b1(percent) + cp1.x*b2(percent) + cp2.x*b3(percent) + p2.x*b4(percent);
pos.y = p1.y*b1(percent) + cp1.y*b2(percent) + cp2.y*b3(percent) + p2.y*b4(percent);
return pos;
}
(Non IE browsers can see it in action at http://www.iscriptdesign.com -> Tutorial -> Groups & Paths).
All I need now is the controlpoint or (tangent and weight) for the branchpoint ( I don't have a clue where to start, and I hope somebody can point to some code, or mathematical equation, if possible as function from the same parameters as the getBezier function above).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
发现并实现它:
de-Casteljau
算法被证明是最快的可实现解决方案。目前它位于:iScriptDesign(教程 -> Spit Bezier)。
Found and implemented it:
de-Casteljau
algorithm turned out to be the fastest implementable solution. It is currently present under:iScriptDesign (Tutorial ->Spit Bezier).
示例用法(我想,我需要@drjerry的帮助)
我有一个css3计时函数,这称为ease-in-out:
cubic-bezier(.42,0,.58,1)
。从图形上看,这看起来像: http://cubic-bezier.com/#.42 ,0,.58,1我想创建一个新的计时函数,它只是该图的下半部分,然后是上半部分。
所以下半部分是
ease-in
:cubic-bezier(.42,0,1,1)
。以图形方式表示: http://cubic-bezier.com/#.42,0,1 ,1上半部分是
ease-out
:cubic-bezier(0,0,.58,1)
。以图形方式表示: http://cubic-bezier.com/#0,0,.58 ,1所以现在让我困惑的是,根据 iScriptDesign 的脚本,它告诉我它们是不同的。
iScriptDeisgn 表示
ease-in-out
的开始部分(即ease-in
)是:cubic-bezier(.21, 0, .355, .25)
。以图形方式表示: http://cubic-bezier.com/#.21,0 ,.35,.25iScriptDeisgn 表示
ease-in-out
的结尾部分(即ease-out
)是:cubic-贝塞尔曲线(.145,.25,.29,.5)
。以图形方式表示: http://cubic-bezier.com/#.14, .25,.29,.5为什么iScriptDesign split函数返回的
ease-in
和ease-out
与真实的ease不同-in
和真正的ease-out
?我不明白。本示例的代码。
因此
split50percent
设置为:与
easeInOutSine
相同easeInOutSine
:.44,.05,.55,.95easeInSine
:0.47, 0, 0.745, 0.715easeOutSine
:0.39、0.575、0.565、1easeInSine
:.22,.03,.36,.26easeOutSine
:.14,.24,.28,.48Example usage (I think, i need help from @drjerry)
I have a css3 timing function, this is called ease-in-out:
cubic-bezier(.42,0,.58,1)
. Graphically this looks like: http://cubic-bezier.com/#.42,0,.58,1I want to make a new timing function that is just the bottom half and then top half of this graph.
So the bottom half is
ease-in
:cubic-bezier(.42,0,1,1)
. Graphically: http://cubic-bezier.com/#.42,0,1,1And the top half is
ease-out
:cubic-bezier(0,0,.58,1)
. Graphically: http://cubic-bezier.com/#0,0,.58,1So now what confuses me is that according to the script at iScriptDesign it tells me they are different.
iScriptDeisgn says the starting half of
ease-in-out
is (which isease-in
) is:cubic-bezier(.21, 0, .355, .25)
. Graphically: http://cubic-bezier.com/#.21,0,.35,.25iScriptDeisgn says the ending half of
ease-in-out
is (which isease-out
) is:cubic-bezier(.145, .25, .29, .5)
. Graphically: http://cubic-bezier.com/#.14,.25,.29,.5Why is the
ease-in
andease-out
returned by the iScriptDesign split function different from the realease-in
and realease-out
? I don't get it.Code for this example.
So
split50percent
is set to:Same thing with
easeInOutSine
easeInOutSine
:.44,.05,.55,.95easeInSine
:0.47, 0, 0.745, 0.715easeOutSine
:0.39, 0.575, 0.565, 1easeInSine
:.22,.03,.36,.26easeOutSine
:.14,.24,.28,.48