Skip to main content
Back transform
Source Link
Julien Guertault
  • 4.4k
  • 2
  • 24
  • 47

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:

for each vertex v
{
    float h = GetPositionOnAxis(v);
    matrix4 M = ComputeTransformFromAxisToSpline(hv);
    v = ApplyTransform(v, M);
}

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

matrix4 ComputeTransformFromAxisToSpline(floatvector3 hv)
{
    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.

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:

for each vertex v
{
    float h = GetPositionOnAxis(v);
    matrix4 M = ComputeTransformFromAxisToSpline(h);
    v = ApplyTransform(v, M);
}

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

matrix4 ComputeTransformFromAxisToSpline(float h)
{
    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);
}

$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.

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:

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:

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.

Source Link
Julien Guertault
  • 4.4k
  • 2
  • 24
  • 47

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:

for each vertex v
{
    float h = GetPositionOnAxis(v);
    matrix4 M = ComputeTransformFromAxisToSpline(h);
    v = ApplyTransform(v, M);
}

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

matrix4 ComputeTransformFromAxisToSpline(float h)
{
    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);
}

$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.