简体   繁体   English

将单个贝塞尔曲线拟合到 3D 中的 4 个点

[英]Fitting a single bezier curve to 4 points in 3D

Is there an easy method of curve-fitting a single segment of a bezier curve to 4 points in 3D?是否有一种简单的方法可以将贝塞尔曲线的单段曲线拟合为 3D 中的 4 个点?

Here's an example of what I'm trying to do:这是我正在尝试做的一个例子:

bezier_1

And here's another picture of the resulting Bezier handles for the segment:这是该段生成的 Bezier 句柄的另一张图片:

bezier_2

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

What's the best way of going about this?解决这个问题的最佳方法是什么?

To make single Bezier curve passing through needed points, you should know parameters t for these points.要使单个贝塞尔曲线通过所需的点,您应该知道这些点的参数t

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似乎您没有关于曲线的附加信息,因此作为第一个近似值,您可以先将参数t=1/3分配给第一个点,将参数t=2/3分配给第二个点,然后计算贝塞尔曲线的控制点以提供P(1/3) == InternalPoint1 and P(2/3) == InternalPoint2

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 .如果第一个内部点靠近起点,这种假设可能会导致奇怪的曲线形式,因此在一般情况下,粗略评估参数是值得的 - 例如,使用对P0-P3, P0-P1, P2-P3之间的距离比.

Some more info and picture in linked answer链接答案中的更多信息和图片

Excerpt from my Delphi function with some pseudocode从我的 Delphi 函数中摘录一些伪代码

  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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM