给定起点和终点的法线,如何计算 3D 三次 Bézier 曲线上点的法线?

发布于 2024-10-09 13:51:10 字数 893 浏览 5 评论 0 原文

我正在尝试使用单个 3D 三次贝塞尔曲线来渲染“3D 功能区”来描述它(功能区的宽度是某个常数)。第一个和最后一个控制点有一个与之关联的法线向量(它们总是垂直于这些点处的切线,并描述这些点处丝带的表面法线),并且我试图将法线向量平滑地插值到曲线的走向。

例如,给定一条形成字母“C”的曲线,第一个和最后一个控制点的表面法线均指向上方,丝带应开始平坦,与地面平行,缓慢转动,然后再次平坦,面向与第一个控制点的方法相同。为了“顺利”地做到这一点,它必须在曲线的一半处面向外。目前(对于本例),我只能使所有表面朝上(而不是在中间朝外),这会在中间产生一个丑陋的过渡。

这很难解释,我在下面附上了这个示例的一些图像,其中包含它当前的样子(所有表面朝上,中间急剧翻转)以及它应该是什么样子(平滑过渡,表面缓慢旋转)。银色面代表正面,黑色面代表背面。

不正确,目前的样子:

正确的功能区 http://img211.imageshack.us/ img211/4659/ribbonin Correct.th.png

正确,它应该是什么样子:

不正确的功能区 http://img515.imageshack.us/img515/2673/ribbon Correct.th.png

我真正需要的是能够计算这个“混合法线向量” 3D 三次贝塞尔曲线上的任何点,我可以毫无问题地生成多边形,但我无法弄清楚如何让它们如图所示平滑地旋转。完全不知道如何进行!

I'm trying to render a "3D ribbon" using a single 3D cubic Bézier curve to describe it (the width of the ribbon is some constant). The first and last control points have a normal vector associated with them (which are always perpendicular to the tangents at those points, and describe the surface normal of the ribbon at those points), and I'm trying to smoothly interpolate the normal vector over the course of the curve.

For example, given a curve which forms the letter 'C', with the first and last control points both having surface normals pointing upwards, the ribbon should start flat, parallel to the ground, slowly turn, and then end flat again, facing the same way as the first control point. To do this "smoothly", it would have to face outwards half-way through the curve. At the moment (for this case), I've only been able to get all the surfaces facing upwards (and not outwards in the middle), which creates an ugly transition in the middle.

It's quite hard to explain, I've attached some images below of this example with what it currently looks like (all surfaces facing upwards, sharp flip in the middle) and what it should look like (smooth transition, surfaces slowly rotate round). Silver faces represent the front, black faces the back.

Incorrect, what it currently looks like:

Correct Ribbon http://img211.imageshack.us/img211/4659/ribbonincorrect.th.png

Correct, what it should look like:

Incorrect Ribbon http://img515.imageshack.us/img515/2673/ribboncorrect.th.png

All I really need is to be able to calculate this "hybrid normal vector" for any point on the 3D cubic bézier curve, and I can generate the polygons no problem, but I can't work out how to get them to smoothly rotate round as depicted. Completely stuck as to how to proceed!

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

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

发布评论

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

评论(1

萧瑟寒风 2024-10-16 13:51:10

您可以使用 这个答案,评估 t=0(或固定 t,无论您选择哪个)时的法线将为您提供平滑的过渡。

像这样:

alt text

(想象一下沿着蓝红色边框的人行道)

编辑

好的,这是我通过另一种方式得到的:

alt text

过程很简单:

让你的参数化函数:

f[t] := { x[t], y[t], z[t] }  

计算切向量求导数:

f'[t] := { x'[t], y'[t], z'[t] }  

选择您的起始(和结束法线向量)例如:

n[0] = {0, 0, 1};

现在定义另一个函数作为导数和法线的向量积:

cp[t_] := CrossProduct[f'[t], n[0]];  

就是这样。

我的四边形的点位于:

 {f[t] - cp[t]/3, 
  f[t] + cp[t]/3, 
  f[t + dt] + cp[t + dt]/3, 
  f[t + dt] - cp[t + dt]/3}  

其中 dt 是你喜欢的增量。

更复杂的方法可能会考虑曲线路径长度,但我猜这是算法的第二次迭代。

哈!

You may use the algorithm explained in the first part of this answer, evaluating the normals at t=0 (or a fixed t, whichever you choose) will give you a smooth transition.

Like this:

alt text

(Imagine your sidewalk along the blue-red border)

Edit

Ok, this is what I got by another way:

alt text

The procedure is simple:

Have your parametrized function:

f[t] := { x[t], y[t], z[t] }  

Calculate the tangent vector by taking derivatives:

f'[t] := { x'[t], y'[t], z'[t] }  

Chose your starting (and ending normal vector) for example:

n[0] = {0, 0, 1};

Now define another function as the vector product of the derivative and your normal:

cp[t_] := CrossProduct[f'[t], n[0]];  

And that's it.

The points of my quadrilaterals lie in:

 {f[t] - cp[t]/3, 
  f[t] + cp[t]/3, 
  f[t + dt] + cp[t + dt]/3, 
  f[t + dt] - cp[t + dt]/3}  

where dt is the increment you like.

A more sophisticated approach may account for the curve path length, but I guess that is the second iteration of the algorithm.

HTH!

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