3点参数插值曲线 [英] 3 point parametric interpolation curve

查看:151
本文介绍了3点参数插值曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制一个3点参数样条曲线,如本网页所示。这不是一个贝塞尔曲线。积分必须都在曲线上。



http://www.doc.ic.ac.uk/~dfg/AndysSplineTutorial/Parametrics.html



我需要两个同时的方程式,x和y有一个公共变量(t = 0-1)。不知道如何用数学创造它们。任何帮助,将不胜感激。谢谢。

I would like to draw a 3 point parametric spline as demonstrated at this webpage. This is not a bezier curve. The points must all be on the curve.

"http://www.doc.ic.ac.uk/~dfg/AndysSplineTutorial/Parametrics.html"

I need two simultanious equations, x and y with a common variable(t = 0-1). Don''t know how to create them from the mathematics. Any help would be appreciated. thanks.

推荐答案

http://www.extremeoptimization .com / QuickStart / CSharp / CubicSplines.aspx [ ^ ]



通过一组带有Bezier基元的2D点绘制平滑曲线 [ ^ ]



和一些免费的源代码示例 http://www.codeforge.com/s/ 0 / parametric-cubic-spline [ ^ ]
http://www.extremeoptimization.com/QuickStart/CSharp/CubicSplines.aspx[^]

Draw a Smooth Curve through a Set of 2D Points with Bezier Primitives[^]

and some free source examples http://www.codeforge.com/s/0/parametric-cubic-spline[^]


退出简单:提供的等式(您链接的页面)是矢量,让我们写它(为简单起见)

It is quite simple: the equation (the page you linked) provided is vectorial, let''s write it (for simplicity)
P(0)={x0,y0}={a0,b0};
P(s)={xs,ys}={a2*s*s+a1*s+a0, b2*s*s+b1*s+b0}
P(1)={x1,y1}={a2+a1+a0, b2+b1+b0}



其中P(0),P(s),P(1)是已知(0< s< 1)。

我们必须找到六个参数 a2,a1,a0,b2,b1,b0 。将计算限制为 x (y是相同的):


Where the P(0), P(s), P(1) are known (0<s<1).
We have to find the six parameters a2,a1,a0, b2,b1,b0. Limiting computation to x (y is the same):

x0 = a0
x1 = a2+a1+x0 => a1 = x1-x0-a2
xs = a2*s*s+x1*s-x0*s-a2*s+x0 => a2 = (xs-x0+(x0-x1)*s)/(s-s*s)



a2 使用第二个等式计算 a1 的值。

现在 a2,a1,a0 (并且以相同的方式 b2,b1,b0 )已知并且您可以计算 P(t)= {x(t),y(t )} = {a2 * t * t + a1 * t + a0,b2 * t * t + b1 * t + b0} 每个 0< t< 1

(我希望它是正确的......)


With a2 value you compute a1 using the second equation.
Now a2,a1,a0 (and in the same way b2,b1,b0) are known and you may compute P(t) = {x(t), y(t)} = {a2*t*t+a1*t+a0, b2*t*t+b1*t+b0} for each 0<t<1.
(I hope it is correct...)


引用网站中的某些公式不正确。特别是 1 的结果公式是错误的。



你必须明白你可以自由选择t 1 对于你的P 1 :通过改变你选择的P 1 的t 1 ,曲线的形状也会有所不同。 />


假设你有三个定义点:

- 在P 0 开始(t = 0)

- 结束(t = 1)在P 2

- 在开始和结束之间的点P 1 你还决定在 1 (例如0.5)。



给定这四个参数(P 0 ,P 2 ,P 1 ,t 1 ),所需的曲线系数为:

a 0 = A

a 1 = B - t 1 C

a 2 = C - B

其中

A = P 0

B =(P 1 - P < sub> 0 )/((1 - t 1 )t 1

C =(P 2 - P 0 )/(1 - t 1



如果在2D中工作,每个系数由两个值组成,每个轴一个 - 在3D中工作,每个系数由每个轴上的3个值组成。



例如对于每个轴系数值,将点P u 的相应轴值加上参数t 1 值设置为上面的公式。



然后你将参数t从0扫到1并计算要绘制的曲线点P(t)。



伪代码:

Some formulas in the referenced web site are not correct. Especially the result formula for a1 is wrong.

You must understand that you have the freedom to chose the t1 for your P1: by varying t1 for your chosen P1, the shape of the curve will vary too.

Assuming you have three defined points:
- start (t = 0) at P0
- end (t = 1) at P2
- a point P1 between start and end where you also decide for a t1 (e.g. 0.5).

Given these four parameters (P0, P2, P1, t1), the needed curve coefficients are:
a0 = A
a1 = B - t1 C
a2 = C - B
Where
A = P0
B = (P1 - P0) / ((1 - t1) t1)
C = (P2 - P0) / (1 - t1)

If working in 2D, each coefficient consists of two values, one for each axis - working in 3D, each coefficient consists of 3 values, on per axis.

E.g. for each axis coeficient value, you set the respective axis value of the points Pu plus the parameter t1 value into the formulas above.

Then you sweep the parameter t from 0 to 1 and calculate the curve points P(t) to draw.

pseudo code:
class Formula
{
    private Point a0;
    private Point a1;
    private Point a2;

    private Point A(Point p0, Point p1, Point p2, double t1) { return p0; }
    private Point B(Point p0, Point p1, Point p2, double t1) { double d = 1/((1-t1)*t1); return (p1-p0)*d; }
    private Point C(Point p0, Point p1, Point p2, double t1) { return d = 1/(1-t1); return (p2-p0)*d; }

    public Formula(Point p0, Point p1, point p2, double t1)
    {
       Point a = A(p0, p1, p2, t1);
       Point b = B(p0, p1, p2, t1);
       Point c = C(p0, p1, p2, t1);

       a0 = a;
       a1 = b-c*t1;
       a2 = c-b;
    }
    public Point P(double t) { return ((a2*t)+a1)*t+a0; }
}
...
var start = new Point(0,2); // p0
var end   = new Point(7,6); // p2
var p1    = new Point(2,3); // p1
double t1 = 0.5;
var Formula curve = new Formula(start, p1, end, t1);
...
int steps = 100;
double step = 1.0/(double)steps;
Point curr = p0;
foreach(int i = 1; i <= steps; ++i)
{
   Point next = curve.P(step*(double)i);
   Draw(curr, next);
   curr = next;
}





干杯

Andi



Cheers
Andi


这篇关于3点参数插值曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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