计算参数的定义二次贝塞尔曲线小节小节、塞尔、曲线、定义

2023-09-11 02:14:54 作者:诗与远方

我所描述的(STARTX,startY)到(anchorX,anchorY)结束的二次贝塞尔曲线,并使用控制点由(controlX,controlY)。

I have a quadratic bezier curve described as (startX, startY) to (anchorX, anchorY) and using a control point (controlX, controlY).

我有两个问题:

(1)我想该曲线上确定的基础上的X点y点。

(1) I want to determine y points on that curve based on an x point.

(2)然后,给定一个线段上我贝塞尔(我的贝塞尔曲线(STARTX',startY,anchorX在两个中间点定义,anchorY')),我想知道的是,控制点线段,使其准确地重叠原始贝塞尔

(2) Then, given a line-segment on my bezier (defined by two intermediary points on my bezier curve (startX', startY', anchorX', anchorY')), I want to know the control point for that line-segment so that it overlaps the original bezier exactly.

为什么呢?我希望这个信息的优化。我抽签水平贝济耶。当贝济耶是比屏幕大,性能会受到影响,因为渲染引擎最终渲染超越什么是可见的范围。在这个问题的答案将让我呈现的是可见的。

Why? I want this information for an optimization. I am drawing lots of horizontal beziers. When the beziers are larger than the screen, performance suffers because the rendering engine ends up rendering beyond the extents of what is visible. The answers to this question will let me just render what is visible.

推荐答案

该公式为二次贝塞尔是:

Part 1

The formula for a quadratic Bezier is:

B(t) = a(1-t)2    + 2bt(1-t)   + ct2
     = a(1-2t+t2) + 2bt - 2bt2 + ct2
     = (a-2b+c)t2+2(b-a)t + a

在这里大胆表示载体。随着 B X (T)给出,我们有:

where bold indicates a vector. With Bx(t) given, we have:

x = (ax-2bx+cx)t2+2(bx-ax)t + ax

其中, v X 是的X分量v

据二次方程式,

     -2(bx-ax) ± 2√((bx-ax)2 - ax(ax-2bx+cx))
t = -----------------------------------------
             (2ax(ax-2bx+cx))

     ax-bx ± √(bx2 - axcx)
  = ----------------------
         ax(ax-2bx+cx)

假设的溶液存在,它插入吨回原始方程式得到的乙的(t)的其他成分在一个给定的x

Assuming a solution exists, plug that t back into the original equation to get the other components of B(t) at a given x.

而不是产生第二贝塞尔曲线与第一部分重合(我不喜欢捣鼓符号现在),你可以简单地限制你的参数参数域到合适的子区间[0, 1。也就是说,使用第1部分找到T的值x的两个不同的值;把这些t值i和j。绘制 B (T)在t∈[I,J]。等价地,画 B (T(JI)+ I)在t∈[0,1]。

Rather than producing a second Bezier curve that coincides with part of the first (I don't feel like crunching symbols right now), you can simply limit the domain of your parametric parameter to a proper sub-interval of [0,1]. That is, use part 1 to find the values of t for two different values of x; call these t-values i and j. Draw B(t) for t ∈ [i,j]. Equivalently, draw B(t(j-i)+i) for t ∈ [0,1].