如何将三次曲线的两个控制点转换为二次曲线的单个控制点? [英] How do I convert the 2 control points of a cubic curve to the single control point of a quadratic curve?

查看:58
本文介绍了如何将三次曲线的两个控制点转换为二次曲线的单个控制点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网上搜索后,我在各个论坛中看到许多人都在暗示用二次曲线近似三次曲线.但是我找不到公式.

Having searched the web, I see various people in various forums alluding to approximating a cubic curve with a quadratic one. But I can't find the formula.

这是我想要的:

输入:startX,startY,control1X,control1Y,control2X,control2Y,endX,endY输出:startX,startY,controlX,controlY,endX,endY

input: startX, startY, control1X, control1Y, control2X, control2Y, endX, endY output: startX, startY, controlX, controlY, endX, endY

实际上,由于起点和终点是相同的,所以我真正需要的只是...

Actually, since the starting and ending points will be the same, all I really need is...

输入:startX,startY,control1X,control1Y,control2X,control2Y,endX,endY输出:controlX,controlY

input: startX, startY, control1X, control1Y, control2X, control2Y, endX, endY output: controlX, controlY

推荐答案

如上所述,从4个控制点到3个控制点通常是一个近似值.只有一种情况是精确的-三次贝塞尔曲线实际上是一个度数升高的二次贝塞尔曲线.

As mentioned, going from 4 control points to 3 is normally going to be an approximation. There's only one case where it will be exact - when the cubic bezier curve is actually a degree-elevated quadratic bezier curve.

您可以使用度数升高方程来得出近似值.很简单,结果通常很好.

You can use the degree elevation equations to come up with an approximation. It's simple, and the results are usually pretty good.

我们称三次Q0..Q3的控制点和二次P0..P2的控制点.然后,对于度数升高,公式为:

Let's call the control points of the cubic Q0..Q3 and the control points of the quadratic P0..P2. Then for degree elevation, the equations are:

Q0 = P0
Q1 = 1/3 P0 + 2/3 P1
Q2 = 2/3 P1 + 1/3 P2
Q3 = P2

在您的情况下,您有Q0..Q3,并且正在求解P0..P2.根据上面的公式,有两种方法可以计算P1:

In your case you have Q0..Q3 and you're solving for P0..P2. There are two ways to compute P1 from the equations above:

P1 = 3/2 Q1 - 1/2 Q0
P1 = 3/2 Q2 - 1/2 Q3

如果这是度高的三次方,则两个方程将为P1给出相同的答案.既然不太可能,那么最好的选择就是将它们平均化.因此,

If this is a degree-elevated cubic, then both equations will give the same answer for P1. Since it's likely not, your best bet is to average them. So,

P1 = -1/4 Q0 + 3/4 Q1 + 3/4 Q2 - 1/4 Q3

要翻译成您的条款,

controlX = -0.25*startX + .75*control1X + .75*control2X -0.25*endX

Y的计算方法类似-尺寸是独立的,因此适用于3d(或n-d).

Y is computed similarly - the dimensions are independent, so this works for 3d (or n-d).

这是一个近似值.如果需要更好的近似值,一种获得方法是通过使用deCastlejau算法细分初始三次方,然后对每个线段进行度缩减.如果您需要更好的连续性,则可以使用其他一些近似方法,这些方法不那么快捷和肮脏.

This will be an approximation. If you need a better approximation, one way to get it is by subdividing the initial cubic using the deCastlejau algorithm, and then degree-reduce each segment. If you need better continuity, there are other approximation methods that are less quick and dirty.

这篇关于如何将三次曲线的两个控制点转换为二次曲线的单个控制点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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