三次贝塞尔曲线-给定X可获得Y [英] Cubic bezier curves - get Y for given X
问题描述
我有三次贝塞尔曲线,其中给出了第一个点和最后一个点(即P0(0,0)和P3(1,1)).
其他两点的定义如下:cubic-bezier(0.25,0.1,0.25,1.0)(X1,Y1,X2,Y2,而且这些值分别不得小于或大于0或1)
现在,假设只有一个,我该怎么做才能获得给定X的Y坐标? (我知道在某些情况下可以有多个值,但我们将它们放在一边.我不是在这里进行火箭科学,我只是想每秒能够多次获得Y来进行转换)
I have a cubic bezier curve where the first and last points are given (namely P0(0,0) and P3(1,1)).
The other two points are defined like this: cubic-bezier(0.25, 0.1, 0.25, 1.0) (X1, Y1, X2, Y2, also those values must not be smaller or larger than 0 or 1, respectively)
Now what would I have to do to get the Y coordinate for a given X, assuming there's only one? (I know that under certain circumstances there can be multiple values, but let's just put them aside. I'm not doing rocket science over here, I just want to be able to get Y multiple times per second to do transitions)
我设法对此进行了总结:给定x的y坐标立方贝塞尔曲线,但我不明白xTarget代表什么.
哦,这也不是什么功课,我对互联网上没有三次方贝塞尔曲线的可理解之处感到恼火.
I managed to dig up this: y coordinate for a given x cubic bezier, but I don't understand what xTarget stands for.
Oh, also this is no homework whatsoever, I'm just a bit annoyed at the fact that there's no comprehensible stuff about cubic bezier curves on the internet.
推荐答案
如果有
P0 = (X0,Y0)
P1 = (X1,Y1)
P2 = (X2,Y2)
P3 = (X3,Y3)
然后对于[0,1]
中的任何t
,您都会在坐标给出的曲线上得到一个点
Then for any t
in [0,1]
you get a point on the curve given by the coordinates
X(t) = (1-t)^3 * X0 + 3*(1-t)^2 * t * X1 + 3*(1-t) * t^2 * X2 + t^3 * X3
Y(t) = (1-t)^3 * Y0 + 3*(1-t)^2 * t * Y1 + 3*(1-t) * t^2 * Y2 + t^3 * Y3
如果为您提供了x
值,则需要找到[0,1]
中的哪些t
值对应于曲线上的该点,然后使用这些t
值来找到y
坐标.
If you are given an x
value, then you need to find which t
values in [0,1]
correspond to that point on the curve, then use those t
values to find the y
coordinate.
在上面的X(t)
公式中,将左侧设置为x
值,然后插入X0
,X1
,X2
,X3
.这为您提供了变量为t
的三次多项式.您可以为t
解决此问题,然后将该t
值插入Y(t)
公式以获得y
坐标.
In the X(t)
equation above, set the left side to your x
value and plug in X0
, X1
, X2
, X3
. This leaves you with a cubic polynomial with variable t
. You solve this for t
, then plug that t
value into the Y(t)
equation to get the y
coordinate.
解决三次多项式是棘手的,但是可以通过谨慎地使用其中一种方法来解决解决三次多项式.
Solving the cubic polynomial is tricky but can be done by carefully using one of the methods to solve a cubic polynomial.
这篇关于三次贝塞尔曲线-给定X可获得Y的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!