<p>I have no knowledge of the literature on the topic, but I did something very similar to what you're asking some time ago: I wanted to generate lathe meshes and bend them according to a spline. I think the same technique could be adapted to your case quite easily.</p>

<p>First you would need to define what your default axis is: if the input mesh corresponds to the case when the spline curve is a straight line, where is that line in 3D? It could be defined arbitrarily as the Y axis, the PCA of the mesh, or some manually defined axis.</p>

<p>The algorithm is then:</p>

<pre class="lang-c prettyprint-override"><code>for each vertex v
{
    matrix4 M = ComputeTransformFromAxisToSpline(v);
    v = ApplyTransform(v, M);
}
</code></pre>

<p>The tricky part is obviously to define a transform $M$. You could do something like:</p>

<pre class="lang-c prettyprint-override"><code>matrix4 ComputeTransformFromAxisToSpline(vector3 v)
{
    float h = GetPositionOnAxis(v, originalAxis);
    vector3 p1 = GetPointOnSpline(h);
    vector3 p2 = GetPointOnSpline(h + dh); // dh is a small delta
    vector3 u = normalize(p2 - p1);

    // Define an orthogonal basis
    vector3 v = v0;
    vector3 w = normalize(cross(u, v));
    vector3 v = normalize(cross(w, u));

    return MakeTransform(u, v, w, p1) * MakeTranslation(originalAxis, -h);
}
</code></pre>

<p>$v_0$ is going to be the problem. I have tried two approaches:</p>

<ul>
<li>Use an absolute value, like an axis orthogonal to the default axis. This will work only if the spline never gets parallel to that axis. It may also lead to undesired shapes.</li>
<li>Start with an absolute value for the points at $h=0$, then reuse the previous $v$ for bigger $h$ values. This means you have to treat vertices ordered by $h$. In my case this was trivial because I was generating the vertices, but in your case that would probably mean to sort them. The result is a mesh that will tend to twist in curves, which may or may not be desirable.</li>
</ul>

<p>Another possibility would be to define the orientation by having more information in the curve, but I haven't tried that approach as I was already satisfied with the result.</p>

CC BY-SA 3.0
2016-07-07T09:08:06.480Z
There is a less understood trick to handle the flip of the spline direction, it happens because you use a naive local approach to the problem. But it is quite easy to find all the locations where the flip will occour than its just a matter of saying okay this segment is reversed.
joojaa
CC BY-SA 3.0
2016-07-07T09:25:53.757Z
Interesting. In my case the flip was never a problem though. I had to handle the case when the spline was backtracking, but that was easy to detect and then just a matter of switching a sign.
Julien Guertault
CC BY-SA 3.0
2016-07-07T07:35:05.870Z
2016-07-07T07:42:51.123Z
2016-07-07T07:42:51.123Z
Julien Guertault
<p>Given a set of vertices, transforming them to fit onto some spline curve.
For example 3D modelling software has extrude along curve and Unreal Engine has a spline mesh component that takes some mesh and stretches it along a defined curve.</p>

<p>Is there some branch of mathematics or theory that looks into this?</p>

CC BY-SA 3.0
2016-07-06T06:50:04.203Z
Many animation tools have such functions, such as mayas curve deformer. But thenagain your question is a bit vague in terms of what you want as you may in fact want to know about spline patches such as nurbs surfaces that indeed have a quite wide mathematical research behind them.
joojaa
<transformations><computational-geometry><curve>
How to deform some mesh so that it fits along a spline curve?
Arch
# How to deform some mesh so that it fits along a spline curve?

(Asked by: username_0 on 2016-07-06)

Given a set of vertices, transforming them to fit onto some spline curve.
For example 3D modelling software has extrude along curve and Unreal Engine has a spline mesh component that takes some mesh and stretches it along a defined curve.

Is there some branch of mathematics or theory that looks into this?

**Tags:** transformations, computational-geometry, curve

> **Comments:**
> **username_1**: Many animation tools have such functions, such as mayas curve deformer. But thenagain your question is a bit vague in terms of what you want as you may in fact want to know about spline patches such as nurbs surfaces that indeed have a quite wide mathematical research behind them.  

---

## 1 answers

### Answer by username_2 on 2016-07-07. Score: 2 | Accepted answer

I have no knowledge of the literature on the topic, but I did something very similar to what you're asking some time ago: I wanted to generate lathe meshes and bend them according to a spline. I think the same technique could be adapted to your case quite easily.

First you would need to define what your default axis is: if the input mesh corresponds to the case when the spline curve is a straight line, where is that line in 3D? It could be defined arbitrarily as the Y axis, the PCA of the mesh, or some manually defined axis.

The algorithm is then:

```c
for each vertex v
{
    matrix4 M = ComputeTransformFromAxisToSpline(v);
    v = ApplyTransform(v, M);
}

```

The tricky part is obviously to define a transform $M$. You could do something like:

```c
matrix4 ComputeTransformFromAxisToSpline(vector3 v)
{
    float h = GetPositionOnAxis(v, originalAxis);
    vector3 p1 = GetPointOnSpline(h);
    vector3 p2 = GetPointOnSpline(h + dh); // dh is a small delta
    vector3 u = normalize(p2 - p1);

    // Define an orthogonal basis
    vector3 v = v0;
    vector3 w = normalize(cross(u, v));
    vector3 v = normalize(cross(w, u));

    return MakeTransform(u, v, w, p1) * MakeTranslation(originalAxis, -h);
}

```

$v\_0$ is going to be the problem. I have tried two approaches:

* Use an absolute value, like an axis orthogonal to the default axis. This will work only if the spline never gets parallel to that axis. It may also lead to undesired shapes.
* Start with an absolute value for the points at $h=0$, then reuse the previous $v$ for bigger $h$ values. This means you have to treat vertices ordered by $h$. In my case this was trivial because I was generating the vertices, but in your case that would probably mean to sort them. The result is a mesh that will tend to twist in curves, which may or may not be desirable.

Another possibility would be to define the orientation by having more information in the curve, but I haven't tried that approach as I was already satisfied with the result.

> **Comments:**
> **username_1**: There is a less understood trick to handle the flip of the spline direction, it happens because you use a naive local approach to the problem. But it is quite easy to find all the locations where the flip will occour than its just a matter of saying okay this segment is reversed.  
> **username_2**: Interesting. In my case the flip was never a problem though. I had to handle the case when the spline was backtracking, but that was easy to detect and then just a matter of switching a sign.  

---

