在 3D 中给定 N 个点时,如何创建三次贝塞尔曲线? [英] How to create a cubic bezier curve when given N points in 3D?

查看:39
本文介绍了在 3D 中给定 N 个点时,如何创建三次贝塞尔曲线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,当仅知道曲线上的点时,我需要找出三次贝塞尔曲线的控制点所在的位置,这些点可以位于 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.

推荐答案

让我看看我是否理解你:你想要一个内插贝塞尔曲线,通过一组给定的点 P0 P1 ...
但绘制为贝塞尔曲线,函数类似于

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

也就是要导出两个贝塞尔控制点Cj,Dj对于每件 Pj -- Pj+1 ?

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

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

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

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

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

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

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 )

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

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

这篇关于在 3D 中给定 N 个点时,如何创建三次贝塞尔曲线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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