Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
957 views
in Technique[技术] by (71.8m points)

math - Explain - Formula to curve through a control point

I have a question regarding formula curving through a control point. As you know, HTML Canvas has quadraticCurveTo(x1, y1, x2, y2) with x1 and x2 being the control point.

However when you try to draw a stroke using it, the stroke will never touch the control point.

So we have this formula:

x1 = xt * 2 - (x0 + x2) / 2;
y1 = yt * 2 - (y0 + y2) / 2;

(xt, yt) = the point you want to curve through. t for tangent as it is 90 degrees perpendicular at that point.

This recalculates the control point position.

I got this formula from a book, however the book doesn't explain how it is been derived. I tried google around but in vain.

Anyone knows how this formula is derived?

Thanks, Venn.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Quadratic Bezier curve is described by equations:

x(t) = x0 * (1-t)^2 + 2 * x1 * t * (1 - t) + x2 * t^2 (and similar for y(t)).

If we apply parameter value t = 1/2 (in some way - middle of the curve), we will get your formula:

x(t=1/2) = xt = x0 * 1/4 + 2 * x1 * 1/4 + x2 * 1/4

then

x1/2 = xt - (x0 + x2)/4

x1 = 2 * xt - (x0 + x2)/2


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...