Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calculating parameters for defining subsections of quadratic bezier curves

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

I have two questions:

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

(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.

like image 875
jedierikb Avatar asked Apr 16 '10 21:04

jedierikb


People also ask

How do you find the Bezier curve of a quadratic equation?

So, Quadratic bezier curve is given by, B(t) = (1-t) BP0,P1(t) + t BP1,P2(t), 0 < t < 1.

How can degree defined based on control points in Bezier curve?

Properties of Bezier Curves They are contained in the convex hull of their defining control points. The degree of the polynomial defining the curve segment is one less that the number of defining polygon point. Therefore, for 4 control points, the degree of the polynomial is 3, i.e. cubic polynomial.

What is the difference between a cubic Bezier curve and a quadratic Bezier curve?

Difference between Bezier and Quadratic CurveA cubic Bezier curve has 2 control points, whereas the quadratic Bezier curve only has 1 control point.


2 Answers

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

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

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

where vx is the x component of v.

According to the quadratic formula,

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

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

Part 2

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].

like image 127
outis Avatar answered Sep 29 '22 23:09

outis


The t equation is wrong, you need to use eq(1)

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

and solve it using the the quadratic formula for the roots (2).

           -b ± √(b^2 - 4ac)
  (2)  x = -----------------
              2a

Where

a = ax-2bx+cx
b = 2(bx-ax)
c = ax - x
like image 41
Alex Arm. Avatar answered Sep 29 '22 23:09

Alex Arm.