利用者:Genio84/gsoc2016/offset

提供: wiki
< 利用者:Genio84
2016年7月15日 (金) 22:15時点におけるwiki>Genio84による版 (The 3D case)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

Offset tool

Question: How do you offset a Bezier curve with another Bezier curve?

Answer: You don't (in most cases).


Why does this happen? The reason has to do with what Bezier curves are, and therefore what they are not. A detailed explanation can be found in [1]. The TL;DR version is that is that Bezier curves are polynomials, but their offsets are not (usually).

The solution is to cheat.

Lets have a look at how Blender handles the Bezier curves. For a given spline, Blender stores the coordinates of the handles of that spline. It then interpolates the Bezier curve inbetween those handles, one pair at a time, and shows this information to the user. It does not store these interpolated points. To make this computation, Blender takes into account four points: both control points, and two handle points. You may be thinking "But two handles have six points. What happens to the other two?". If you only have two handles in a spline, they are simply ignored. If you have more handles, these are used in further computations. However, no matter how many handles you may have in your splines, there are always two handle points that will never be used for computations: the left handle point of the first handle, and the right handle point of the last handle.

Given this, one way to approach the problem would be to offset the handles on the intended direction, the intended amount (as specified by the user).

The approach I just described is similar to the Tiller-Hanson algorithm. You can find nice pictures in [2].

All that is required now is to sort out the mathematical details.

The intended direction

The problem this section addresses is the following:

Problem 1.1
Given two Bezier handles, obtain the offset direction.


The first problem is regarding the definition of offset direction. Intuitively, one would almost say it is the direction one expects the curve to offset, leading us back to the beginning. So let's simplify the problem.

The 2D case

In 2D, the problem is trivial. The offset direction is either in, or out, according to the normal at the curve on that point.

The 3D case

Now this is where the problem becomes interesting. In 3D, you do not have a normal vector. You have a normal plane!

That means any vector on that plane could be used, but it would be impossible for the user to pick correctly the direction using only mouse input! Therefore, we need to make a decision regarding which vector to use.

But what if, despite being on 3D space, we cheated and said that locally, very near the handle, we were on 2D space. That would solve it. But what does the 2D space look like near the handle? For simplicity, let's consider that it is the plane that contains the control point, the handle point used in the interpolation process, and the first interpolated point of the spline.

Intersect the normal plane with the tangent plane and voilá! We get the offset direction

Solution 1.2
Intersect the normal plane with the tangent plane at the handle.