开发者

How to calculate the normal of points on a 3D cubic Bézier curve given normals for its start and end points?

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 r开发者_如何学Pythonepresent 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!


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:

How to calculate the normal of points on a 3D cubic Bézier curve given normals for its start and end points?

(Imagine your sidewalk along the blue-red border)

Edit

Ok, this is what I got by another way:

How to calculate the normal of points on a 3D cubic Bézier curve given normals for its start and end points?

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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜