在3D中将单个贝塞尔曲线拟合到4个点 [英] Fitting a single bezier curve to 4 points in 3D

查看:72
本文介绍了在3D中将单个贝塞尔曲线拟合到4个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种简便的方法可以将贝塞尔曲线的单个线段拟合为3D的4个点?

Is there an easy method of curve-fitting a single segment of a bezier curve to 4 points in 3D?

这是我要做的事的一个例子:

Here's an example of what I'm trying to do:

这是该段所产生的Bezier句柄的另一张图片:

And here's another picture of the resulting Bezier handles for the segment:

在这种情况下,我尝试用手将贝塞尔曲线对齐,以使其与4个给定点相交,并导致尽可能短的曲线.理想情况下,我想以某种方式以编程方式执行此操作-我在网上找到了一些算法可以执行此操作,但是其中大多数似乎是用于创建具有任意数量的线段的曲线...而我只需要拟合一个单段(两个点,两个控制点)到3D中的四个点尽可能接近.

In this case, I've attempted to line up the bezier by hand so that it intersects with the 4 given points and results in the shortest curve possible. Ideally, I'd like to do this programmatically somehow- I've found a few algorithms online that do this, but most of them seem to be for creating curves with an arbitrary number of segments... whereas I just need to fit a single segment (two points, two control points) to four points in 3D as closely as possible.

解决此问题的最佳方法是什么?

What's the best way of going about this?

推荐答案

要使贝塞尔曲线穿过所需的点,您应该知道这些点的参数 t .

To make single Bezier curve passing through needed points, you should know parameters t for these points.

似乎没有关于曲线的其他信息,因此,在第一次逼近时,可以先将参数 t = 1/3 分配给第一个点,然后将参数 t = 2/3 到第二点,然后计算Bezier曲线的控制点以提供 P(1/3)== InternalPoint1和P(2/3)== InternalPoint2

Seems you have no additional information about curve, so as first appriximation you can a priopi assign parameter t=1/3 to the first point and parameter t=2/3 to the second point, then calculate control points for Bezier curve to provide P(1/3) == InternalPoint1 and P(2/3) == InternalPoint2

如果第一个内部点位于起点附近,则这种假设可能会导致曲线形成怪异的曲线,因此在一般情况下,值得粗略地评估参数-例如,使用对之间的距离比 P0-P3,P0-P1,P2-P3 .

If the first internal point lies close to start point, such assumption might cause weird curve form, so in general case it is worth to roughly evaluate parameters - for example, using distance ratio between pairs P0-P3, P0-P1, P2-P3.

链接的答案

我的Delphi函数摘录中包含一些伪代码

Excerpt from my Delphi function with some pseudocode

  procedure CalcBezierFromPoints(SrcPt: 4 source points
                                 BezPt: 4 resulting control points
                                 t1: Double = 1 / 3; t2: Double = 2 / 3);
 var
    tt1, tt2: Double;
    Det, a11, a12, a21, a22, b1, b2: Double;
begin
   //start and end points remains the same
   BezPt[0] := SrcPt[0];
   BezPt[3] := SrcPt[3];

   //auxiliary values
   tt1 := 1 - t1;
   tt2 := 1 - t2;

   //Solution of linear equation system
   a11 := 3 * tt1 * tt1 * t1;
   a12 := 3 * tt1 * t1 * t1;
   a21 := 3 * tt2 * tt2 * t2;
   a22 := 3 * tt2 * t2 * t2;
   Det := a11 * a22 - a12 * a21;

   b1 := SrcPt[1].X - SrcPt[0].X * tt1 * tt1 * tt1 - SrcPt[3].X * t1 * t1 * t1;
   b2 := SrcPt[2].X - SrcPt[0].X * tt2 * tt2 * tt2 - SrcPt[3].X * t2 * t2 * t2;
   BezPt[1].X := Round((b1 * a22 - b2 * a12) / Det);
   BezPt[2].X := Round((-b1 * a21 + b2 * a11) / Det);

  //the same for Y and Z components
end;

这篇关于在3D中将单个贝塞尔曲线拟合到4个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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