Testwiki:Reference desk/Archives/Mathematics/2024 February 2

From testwiki
Revision as of 01:08, 17 February 2024 by imported>Scsbot (edited by robot: archiving February 2)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Template:Error:not substituted

{| width = "100%"

|- ! colspan="3" align="center" | Mathematics desk |- ! width="20%" align="left" | < February 1 ! width="25%" align="center"|<< Jan | February | Mar >> ! width="20%" align="right" |Current desk > |}

Welcome to the Wikipedia Mathematics Reference Desk Archives
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


February 2

Draw a segment of a cubic function exactly using a cubic Bezier curve

http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Second-order_curve_is_a_parabolic_segment describes how a segment of a parabola or quadratic curve on a Cartesian plane can be drawn exactly with a quadratic Bezier curve.

Is it possible to draw a segment of a cubic curve exactly with one (preferably) or more cubic Bezier curves?

I.e. given f(x) = ax³ + bx² + cx + d, and endpoints (p, f(p)) and (q, f(q)), what are the coordinates of the two control points?

Thanks, cmɢʟeeτaʟκ 15:18, 2 February 2024 (UTC)

With a cubic Bezier curve P(t)=(1t)3P0+3(1t)2tP1+3(1t)t2P2+t3P3, in order for you to be able to represent f(x)=ax3+bx2+cx+d, you need to have it so that f(Px(t))=Py(t) for all t. I don't specify a domain on t here but regardless of the domain we can just assume that in order to do so, we need for the coefficients of f(Px(t)) to match those of Py(t). We have to solve for four unknowns here, which are the coordinates of P1=(x1,y1) and P2=(x2,y2), since P0=(p,f(p)) and P3=(q,f(q)).
If you expand Px(t) into a third-order polynomial, you can notice that f(Px(t))=aPx(t)3+bPx(t)2+cPx(t)+d is a ninth-order polynomial, while Py(t) is third-order. The coefficient of the ninth-order term is just that of the third-order term of Px(t) cubed, which means that said third-order term must be 0 in order to match coefficients. In other words, Px(t) is at most quadratic. When this is the case, f(Px(t))=aPx(t)3+bPx(t)2+cPx(t)+d is still sixth-order, with the sixth-order term being the second-order term of Px(t) cubed. Again, to match coefficients, this means that the second order term is also 0, and Px(t) is at most linear. This time, coefficient matching works, and you can get that x1=2p/3+q/3 and x2=p/3+2q/3. In other words, the control points would be equidistantly spaced along the x-axis, which isn't particularly surprising. Px(t) is naturally equal to p+(qp)t.
The next part is finding values of y1 and y2. I don't know of any tricks here, I just found the values of y1 and y2 manually. After expanding f(p+(qp)t) and Py(t), through direct comparison I found the values
y1=ap2q+b(p2/3+2pq/3)+c(2p/3+q/3)+d
y2=apq2+b(q2/3+2pq/3)+c(p/3+2q/3)+d
Or in other words, the two control points are:
(2p+q3,ap2q+b(p2+2pq3)+c(2p+q3)+d), (p+2q3,apq2+b(q2+2pq3)+c(p+2q3)+d)
GalacticShoe (talk) 00:49, 3 February 2024 (UTC)
Graphs showing the relationship between the roots, and turning, stationary and inflection points of a cubic polynomial, and its first and second derivatives Template:Done
Thank you so much, Template:Ping that's exactly what I needed. Cheers, cmɢʟeeτaʟκ 07:56, 3 February 2024 (UTC)
Glad I could be of help :) GalacticShoe (talk) 08:00, 3 February 2024 (UTC)
Here's a somewhat different take on the problem giving an equivalent result: Write
F(t)=A(1t)3+3Bt(1t)2+3Ct2(1t)+Dt3.
Then:
F(t)=3A(1t)2+3B(1t)26Bt(1t)+6Ct(1t)3Ct2+3Dt2,
F(t)=6A(1t)12B(1t)+6Bt12Ct+6C(1t)+6Dt,
F(t)=6A+18B18C+6D.
Evaluate at t=0 to get
F(0)=A,
F(0)=3A+3B,
F(0)=6A12B+6C,
F(0)=6A+18B18C+6D.
You can easily solve for A, B, C, D in terms of F and its derivatives at 0:
A=F(0),
B=F(0)+13F(0),
C=F(0)+23F(0)+16F(0),
D=F(0)+F(0)+12F(0)+16F(0)
Note that the last expression is the third order Maclaurin approximation for F(1), and this is exact since F is a cubic polynomial. If
(x,y)=(Fx(t),Fy(t))
is any cubic parametric curve then these formulas generate the endpoints and control points from t=0 to t=1. In particular, if the curve is y=f(x) from x=P to x=Q, where f is a cubic polynomial, take
Fx(t)=P(1t)+Qt,Fy(t)=f(x)=f(P(1t)+Qt).
Then:
Fx(0)=P,
Fx(0)=(QP),
Fx(0)=Fx(0)=0,
Fy(0)=f(P),
Fy(0)=(QP)f(P),
Fy(0)=(QP)2f(P),
Fy(0)=(QP)3f(P).
This gives the endpoints and control points as:
(P,f(P)),
(2P+Q3,f(P)+(QP)3f(P)),
(P+2Q3,f(P)+2(QP)3f(P)+(QP)26f(P)),
(Q,f(P)+(QP)f(P)+(QP)22f(P)+(QP)36f(P)).
The expression for the y-coordinate at Q is the Taylor series approximation of f(Q), and it's exact since f is a cubic polynomial. I don't think it would be hard to generalize these formulas to nth order Bezier curves, and you might say that the expressions for the y coordinates are actually generalizations of Taylor appromations since the last one is, in fact, the actual Taylor approximation. Since the formulas use derivatives instead of coefficients, you can use them to generate accurate Bezier approximations for any parametric curve of sufficient smoothness. --RDBury (talk) 11:08, 4 February 2024 (UTC)
Thank you very much for the general solution, Template:Ping cmɢʟeeτaʟκ 16:37, 4 February 2024 (UTC)