Cloth Bending Constraint

Please don't post Bullet support questions here, use the above forums instead.
Erin Catto
Posts: 316
Joined: Fri Jul 01, 2005 5:29 am
Location: Irvine

Cloth Bending Constraint

Post by Erin Catto »

I would like to have a cloth bending constraint that can handle a non-zero rest angle. The constraint should not allow reflection of the vertices the negative rest angle. There is one bending constraint per edge shared by two triangles, so there are four vertices involved, some of which may be kinematic. I came up with this constraint:

sin(theta) = dot(cross(normal1, normal2), edge)
cos(theta) = dot(normal1, normal2)

C = atan2(sin(theta), cos(theta)) - theta_rest

The constraint is easy to write but the Jacobian is quite nasty because the normals are a function of the various vertex positions.

My current thinking is to simply rotate the two far vertices (of the shared triangles) about the middle edge.

Has anyone attempted this or seen such an approach in the literature?
clanzotti
Posts: 15
Joined: Tue Jul 26, 2005 10:11 am

Re: Cloth Bending Constraint

Post by clanzotti »

Hi Erin,

You may want to look at the Bridson's implementation:

http://www-graphics.stanford.edu/~fedki ... 003-06.pdf

Regards,

Carlo Lanzotti

Erin Catto wrote:I would like to have a cloth bending constraint that can handle a non-zero rest angle. The constraint should not allow reflection of the vertices the negative rest angle. There is one bending constraint per edge shared by two triangles, so there are four vertices involved, some of which may be kinematic. I came up with this constraint:

sin(theta) = dot(cross(normal1, normal2), edge)
cos(theta) = dot(normal1, normal2)

C = atan2(sin(theta), cos(theta)) - theta_rest

The constraint is easy to write but the Jacobian is quite nasty because the normals are a function of the various vertex positions.

My current thinking is to simply rotate the two far vertices (of the shared triangles) about the middle edge.

Has anyone attempted this or seen such an approach in the literature?
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Post by Dirk Gregorius »

I think Raigan implement something also based on atan2 a while ago, though in 2D. He seemed very pleased with the results. There should be some posts on this in the forum.

Out of personal interesst? Where do you see the advantage in your constraint over other implementations? I think the constraint C(n1, n2) = n1 * n2 is the worst formulation, since it can flip and also for a restangle of zero the constraint might be numerical instable. From the back of my head the rule of thumb was to use a constraint based on the dot product (cos) for othogonal vectors and something like sin(theta) = |n1 x n2| for vectors that should be constrained to be parallel. The justification is in the free books of two spanish guys, but I can't find the link at the moment. I can dig it out if somebody is interessted. My personal experience with bending constraints is that the win in quality of your cloth simulation doesn't outweight the extra overhead.



Cheers,
-Dirk
Antonio Martini
Posts: 126
Joined: Wed Jul 27, 2005 10:28 am
Location: SCEE London

Post by Antonio Martini »

Dirk Gregorius wrote: My personal experience with bending constraints is that the win in quality of your cloth simulation doesn't outweight the extra overhead.
Cheers,
-Dirk
you can just use a fast bending constraint where the rest curvature is zero, this is usually almost everywhere on the cloth and use the more complicated type elsewhere. There number of iterations doesn't need to be the same for the entire cloth/set of constraints. Given a set of constraints of any type, we can partition it in subsets accordingly to the desired level of stiffness and type(this usually depends on the location of the subcloth and constraint type) and solve these subsets once every n iterations. so you can have different cloth area with different solving accuracy and the same is valid for constraint types.

cheers,
Antonio
raigan2
Posts: 197
Joined: Sat Aug 19, 2006 11:52 pm

Post by raigan2 »

My angle constraint is: C = (atan2(n2) - atan2(n1)) - theta = 0

This is in 2D, so it's constraining two linesegs which share a vertex (instead of two triangles which share an edge), and the normals n1,n2 are the perp()'d lineseg vectors (instead of the crossproduct of triangle edges).

Actually, I started out using the perp'd lineseg vectors, but soon realized that it was simpler to just use the lineseg vectors themselves. I'm not sure if you could do something analogous in 3D.

This angle constraint behaves _really_ well (though it may be more due to the solver than the formulation of this particular constraint), you can set it to be perfectly rigid (turning the two linesegs into a single rigid shape).. it's much better than anything else I've tried. Start in any arbitrary configuration and they'll snap together regardless of the initial error!

The Jacobian is (found via LiveMath):

points p1,p2,p3
let vA = p1-p2, vB = p3-p2
constraint is C = atan2(vB) - atan2(vA) - theta

dC/dp1 = Perp(vA) * ( -1 / ( ((vA.y/vA.x)^2 + 1)*(vA.x^2) ) )
dC/dp3 = Perp(vB) * ( -1 / ( ((vB.y/vB.x)^2 + 1)*(vB.x^2) ) )
dC/dp2 = -(dC/dp1) - (dC/dp3)

It's possible that the denominator terms on the right can be simplified/reduced to vector operations -- the program I'm using to derive the Jacobians prefers scalars, so I've been treating each vector component as a seperate scalar, it's a bit awkward ;)

The only problem is that when p2.x == p1.x or p2.x == p3.x, things are undefined; currently I'm simply skipping/ignoring the constraint when this happens (similar to when a distance constraint finds a current length of 0, thus the direction of projection is undefined).

This hasn't caused any problems so far, it may simply be due to the fact that the program I'm using only supports arctan(y/x), which is undefined for the same cases. Frankly I have very little theoretical understanding of trig functions or the difference between the implementation of atan() and atan2().

It seems to me that there should be a simple fix to this problem: rotate everything 90deg, solve in that space, then rotate the solutions back. Haven't tried this yet though, as so far the problem case doesn't happen much in practice (and skipping the constraint in those cases seems to "work").

Just to be sure, atan2(v) = atan2(v.y,v.x)

Finally, would it be possible to reduce your 3D constraint into 2D? It seems like you could simply use the shared edge between triangles as the normal of a plane, and constrain the angles in that plane. I guess the problem is how to distribute the correction between the two vertices which form the shared edge..

raigan