通过三个给定点绘制二次贝塞尔曲线 [英] Draw a quadratic Bézier curve through three given points

查看:691
本文介绍了通过三个给定点绘制二次贝塞尔曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在2D中有三个点,我想绘制一条通过它们的二次贝塞尔曲线.如何计算中间控制点(如QuadTo中的x1y1)?我从大学就知道线性代数,但是对此需要一些简单的帮助.

I have three points in 2D and I want to draw a quadratic Bézier curve passing through them. How do I calculate the middle control point (x1 and y1 as in quadTo)? I know linear algebra from college but need some simple help on this.

如何计算中间控制点,以便曲线也通过它?

How can I calculate the middle control point so that the curve passes through it as well?

推荐答案

让P0,P1,P2为控制点,而Pc为您希望曲线通过的固定点.

Let P0, P1, P2 be the control points, and Pc be your fixed point you want the curve to pass through.

然后贝塞尔曲线定义为

P(t) = P0*t^2 + P1*2*t*(1-t) + P2*(1-t)^2

...其中t从零到1.

...where t goes from zero to 1.

您的问题有无数的答案,因为对于任何t值,它都可能通过您的观点.因此,只需选择一个,如t = 0.5,然后求解P1:

There are an infinite number of answers to your question, since it might pass through your point for any value of t... So just pick one, like t=0.5, and solve for P1:

Pc = P0*.25 + P1*2*.25 + P2*.25

P1 = (Pc - P0*.25 - P2*.25)/.5

   = 2*Pc - P0/2 - P2/2

那里的"P"值是(x,y)对,所以只需对x一次应用方程式,对y一次应用方程式:

There the "P" values are (x,y) pairs, so just apply the equation once for x and once for y:

x1 = 2*xc - x0/2 - x2/2
y1 = 2*yc - y0/2 - y2/2

...其中(xc,yc)是您要通过的点,(x0,y0)是起点,(x2,y2)是终点.这样,您将在t = 0.5时通过(xc,yc)的贝塞尔曲线.

...where (xc,yc) is the point you want it to pass through, (x0,y0) is the start point, and (x2,y2) is the end point. This will give you a Bezier that passes through (xc,yc) at t=0.5.

这篇关于通过三个给定点绘制二次贝塞尔曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆