当给定 3D 中的 N 个点时,如何创建三次贝塞尔曲线?

发布于 2024-09-15 08:42:40 字数 109 浏览 2 评论 0原文

因此,当只知道曲线上的点时,我需要找出三次贝塞尔曲线的控制点在哪里,这些点可以位于 3D 中。如果我可以对曲线上任意数量的点执行此操作,那就太理想了。我发现的大部分内容只涉及 2D,或者只涉及 4 个点。

So I need to find out where the control points would be for a cubic bezier curve when only knowing points on the curve, the points can lie in 3D. It would be ideal if I could do this for any number of points on the curve. Most of what I have found deals only with 2D, or only for 4 points.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以往的大感动 2024-09-22 08:42:40

让我看看我是否理解你:
你想要一条插值贝塞尔曲线,
经过一组给定的点 P0 P1 ...
但绘制为贝塞尔曲线,具有这样的函数

bezier4( nstep, Pj, Cj, Dj, Pj+1 )  -- control points Cj, Dj

即,您想要导出两个贝塞尔控制点Cj,Dj
对于每件 Pj - Pj+1 ?

导出此类控制点的一种方法是使用 Bernstein 多项式基础

b0(t) = (1-t)^3
b1(t) = 3 (1-t)^2 t,
b2(t) = 3 (1-t) t^2
b3(t) = t^3

bezier4(t) = b0(t) P0  +  b1(t) C0  +  b2(t) D0  +  b3(t) P1
= P0 at t=0, tangent --> C0
= P1 at t=1,  tangent <-- D0

并查找或导出插值(又名 Catmull-Rom 样条)
经过 P-1 P0 P1 P2:

b0(t) P0
+ b1(t) (P0 + (P1 - P-1) / 6)
+ b2(t) (P1 - (P2 - P0) / 6)
+ b3(t) P1
= P0 at t=0, P1 at t=1

我们希望 bezier4(t) 与 CatmullRom(t) 完全相同,因此:

C0 = P0 + (P1 - P-1) / 6
D0 = P1 - (P2 - P0) / 6

给定 N 个点 P0 P1 ...(在 2d 3d ...anyd 中),取它们一次 4 个;
对于每个 4,该公式为您提供 2 个控制点 Cj、Dj

bezier4( nstep, Pj, Cj, Dj, Pj+1 )

这是否有意义,是您想要的吗?
(为了获得赏金,我会将一些 Python / numpy 拼凑在一起。)

Let me see if I understand you:
you want an interpolating Bezier curve,
going through a given set of points P0 P1 ...
but drawn as Bezier curves, with a function like

bezier4( nstep, Pj, Cj, Dj, Pj+1 )  -- control points Cj, Dj

That is, you want to derive two Bezier control points Cj, Dj
for each piece Pj -- Pj+1 ?

One way of deriving such control points is to use the Bernstein polynomial basis

b0(t) = (1-t)^3
b1(t) = 3 (1-t)^2 t,
b2(t) = 3 (1-t) t^2
b3(t) = t^3

bezier4(t) = b0(t) P0  +  b1(t) C0  +  b2(t) D0  +  b3(t) P1
= P0 at t=0, tangent --> C0
= P1 at t=1,  tangent <-- D0

and look up or derive the interpolating aka Catmull-Rom spline
that goes through P-1 P0 P1 P2:

b0(t) P0
+ b1(t) (P0 + (P1 - P-1) / 6)
+ b2(t) (P1 - (P2 - P0) / 6)
+ b3(t) P1
= P0 at t=0, P1 at t=1

We want bezier4(t) to be exactly the same curve as CatmullRom(t), so:

C0 = P0 + (P1 - P-1) / 6
D0 = P1 - (P2 - P0) / 6

Given N points P0 P1 ... (in 2d 3d ... anyd), take them 4 at a time;
for each 4, that formula gives you 2 control points Cj, Dj for

bezier4( nstep, Pj, Cj, Dj, Pj+1 )

Does this make sense, is it what you want ?
(For a bounty, I'd cobble some Python / numpy together.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文