问题描述
假设我有一个Bezier曲线,其中有两个固定端点,一个端点位于 x(0),y(1)
,另一个端点位于 x(1),y(0)代码>(左下角和右上角)现在,我们有两个控制点,它们可以位于x(0),x(1),y(0)和y(1)之间的任何位置.对于这个问题,我只想说控制点#1在x(0.1)y(0.6)处,而控制点#2在x(0.9)和y(0.4)处.(这假设一个从左上方"坐标系)
Let's say I have a Bezier curve with two fixed endpoints, one at x(0), y(1)
and one at x(1), y(0)
(bottom left corner and upper right corner)Now let's say I have two control points, which can be at any locations between x(0), x(1), y(0), and y(1). For this question, I'll just say that control point #1 is at x(0.1) y(0.6) and control point #2 is at x(0.9) and at y(0.4). (This assumes a "from upper left" coordinate system)
这是我们曲线的一个小例子:
Here's a small illustration of our curve:
现在假设我的y位置为0.7.该数学公式看起来如何确定对应的x位置到y(0.7)的点是什么?我该怎么办?
Now let's say I'm given a y position of 0.7. What would the math look like to figure out what the corresponding x position is to the point at y(0.7)? How would I do this?
抱歉,这个问题不属于这里,但我认为这是编码中经常遇到的问题,很可能你们中的许多人都在寻找我想要的答案.
Sorry if this question doesn't belong here, but I figured this is a common problem faced in coding and that it's likely that many of you have the answer I'm looking for.
推荐答案
您具有函数 X(t)
和 Y(t)
的三次方程,其中t
是曲线参数(曲线上点的范围为 0..1
).在伯恩斯坦多项式基础上(曲线定义的常用形式):
You have cubic equation for functions X(t)
and Y(t)
where t
is curve parameter (range 0..1
for points on curve). In Bernstein polynomial basis (usual form for curve definition):
X(t) = P0.X*(1-t)^3+3*P1.X*(1-t)^2*t+3*P2.X*(1-t)*t^2+P3.X*t^3
Y(t) = P0.Y*(1-t)^3+3*P1.Y*(1-t)^2*t+3*P2.Y*(1-t)*t^2+P3.Y*t^3
具有 Y
值,我们可以找到相应的 t
参数-请注意,在 0..1
.Y分量的幂表示:
Having Y
value, we can find corresponding t
parameters - note there might be from 0 to 3 possible roots in range 0..1
. Representation of Y-component in power basis:
Y(t) = P0.Y*(1-t)^3+3*P1.Y*(1-t)^2*t+3*P2.Y*(1-t)*t^2+P3.Y*t^3 =
t^3*(P3Y-3P2Y+3P1Y-P0Y) + t^2*(3P2Y-6P1Y+3P0Y) + t^2*(3P1Y-3P0Y) + (P0Y) =
t^3*a + t^2*b + t^2*c + d' = y_position
最后的三次方程是:
t^3*a + t^2*b + t^2*c + d = 0
where
a = P3.Y-3*P2.Y+3*P1.Y-P0.Y
b = 3*P2.Y-6*P1.Y+3*P0.Y
c = 3*P1.Y-3*P0.Y
d = P0.Y - y_position
求解三次方程,以计算 t
(也许有些值用于波浪曲线)
Solve cubic equation to calculate t
(perhaps some values for wavy curves)
然后为给定的 t
计算相应的 X
值:
Then for given t
calculate corresponding X
value:
X(t) = P0.X*(1-t)^3+3*P1.X*(1-t)^2*t+3*P2.X*(1-t)*t^2+P3.X*t^3
这篇关于给定具有固定端点的三次方贝塞尔曲线,当给定y位置进行检查时,如何找到沿该点的x位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!