Hi,
I am working on an implementation of strain based dynamics, but am stuck understanding how one part of it operates.
In Strain Based Dynamics a constraint is derived so that Green's Strain Tensor is a function of the relative locations of the points of a tetrahedron or triangle, and this then drives the position corrections for the points. For triangles, the formulation requires that the relative points be converted into a 2D coordinate system local to the triangle.
This transform is provided as:
Q = [n1,n2]'*(x1-x0,x2-x0)
Where n1 and n2 are normal tangent vectors, to the triangle defined by points x0, x1 & x2.
The strain tensor is then computed as S = Q^-1'*P'*P*Q^-1, Where P is the edges of the triangle ([x1-x0,x2-x0])
I know that this *does* work, as I have worked through an example and can see the resulting tensor and its rotation invariance in 3D, but I can't see *how*.
I think most of the confusion arises from not understanding what 'Q' is now. What does this technique do: [n1,n2]'*(x1-x0,x2-x0) ? I am supposing its something like forming a set of basis vectors, but I've not seen anything like it.
Further, the tensor is now defined as Q^-1'*P'*P*Q^1, whereas before (for untransformed coordinates) it was (P*Q^-1)'*(P*Q^-1).
Has anyone been looking at this who can explain geometrically what is going on?
Sj
How does the Strain Based Dynamics material transform work?
-
- Posts: 9
- Joined: Mon Jun 06, 2016 9:34 pm
-
- Posts: 122
- Joined: Thu May 05, 2011 11:47 am
Re: How does the Strain Based Dynamics material transform wo
I have written an implementation of strain based dynamics chapter 12 in a new book Game Engine Gems 3 (http://www.gameenginegems.com/geg3.php). Complete source code is given with it which you may checkout. Also read up details in the book chapter that may also help with your understanding.sebjf wrote:I am working on an implementation of strain based dynamics, but am stuck understanding how one part of it operates.
Let me address your concerns.
OK let me clarify it for you what I understood. Basically you have you two sets of positions. One initial positions (stored in Q also known as material coordinates) and another current positions (which are your corrected current positions stored in P).sebjf wrote:I think most of the confusion arises from not understanding what 'Q' is now.
n1 and n2 are two unit vectors that are obtained from two world space tangent vectors (tu and tv) which are themselves obtained from the texture coordinates (uv). When we calculate [(x1-x0),(x2-x0)], we are essentially transforming our coordinates in the triangles material frame. We do this for both current positions (P) as well as for material coordinates (Q) so thatsebjf wrote:What does this technique do: [n1,n2]'*(x1-x0,x2-x0)
1) We can identify the relative change. Any new positions can then be given in the local frame of triangle by simply multiplying with the resulting matrix.
2) We can then get the inverse of Q and P because in 2D P and Q are non-square and their inverses are not well defined.
I think you are not understanding it correctly. Read pages 3 and 4 of paper. For 2D case, the tensor is defined as Qinv'P'PQinv (' is transpose) this you can derive yourself fromsebjf wrote:Further, the tensor is now defined as Q^-1'*P'*P*Q^1, whereas before (for untransformed coordinates) it was (P*Q^-1)'*(P*Q^-1).
eq. 7 which says
F=PQinv
G=F'F-I
S=F'F (see page 4 first para where S is given in the form of rest stretches)
S=(PQinv)'(PQinv)
=Qinv'P'PQinv (using property of transpose (AB)' = B'A')
Once again you may lookup the complete source code for both 2D as well as 3D cases in the GEG3 chapter I wrote. In addition, Jan Bender's Position based Dynamics library also contains an implementation of strain based dynamics that was done largely at the same time when I wrote mine. That can also help with your understanding.
-
- Posts: 9
- Joined: Mon Jun 06, 2016 9:34 pm
Re: How does the Strain Based Dynamics material transform wo
Hi mobeen,
Thank you very much, that was quite helpful.
- it was actually that book that helped me get this far!
I have looked at others' source code, and it has helped (especially where there are unfamiliar notations). In this case though I just lost the 'link' between the operations and what was happening to the geometry conceptually.
So in fact you could say that:
N = [n1,n2]'
Q & P = [x1-x0,x2-x0]
and
= (N*Q)^-1'*P'*P*(N*Q)^-1
= (Q^-1*N^-1)'*P'*P*(Q^-1*N^-1)
= N^-1'*Q^-1'*P'*P*Q^-1*N^-1
(Obviously you can't *actually* say that because N and Q are noninvertible, but it illustrates the thought process... the transformation by the tangents just wraps the original formulation.)
Have I understood that correctly?
Though this still leaves me wondering how the transformation by the tangents works. I think my difficulties with this are because I'm trying to draw analogies between this operation and the use of basis vectors I am familiar with (where a matrix of basis vectors is the same as a transform from Basis->Global, so the inverse of the same matrix converts from Global->Basis).
I at first imagined that eqn. 38 is doing something similar, but I should probably work through an example to see what really happens to the points during this operation.
Thanks again!
Sj
Thank you very much, that was quite helpful.
Yes I have a copy thank youI have written an implementation of strain based dynamics chapter 12 in a new book Game Engine Gems 3
![Very Happy :D](./images/smilies/icon_biggrin.gif)
I have looked at others' source code, and it has helped (especially where there are unfamiliar notations). In this case though I just lost the 'link' between the operations and what was happening to the geometry conceptually.
Of course! That is me being stupid. I forgot that you had to invert the terms when taking the transpose of a bracketed statement.=Qinv'P'PQinv (using property of transpose (AB)' = B'A')
I think this is beginning to make sense. So instead of the transformation by the tangents forming some 'magic matrix' which both converts into texture space and provides the deformation gradient, we could look at it more as a convenience transformation into a coordinate system that makes the solution numerically viable:we are essentially transforming our coordinates in the triangles material frame. We do this for both current positions (P) as well as for material coordinates (Q)
So in fact you could say that:
N = [n1,n2]'
Q & P = [x1-x0,x2-x0]
and
= (N*Q)^-1'*P'*P*(N*Q)^-1
= (Q^-1*N^-1)'*P'*P*(Q^-1*N^-1)
= N^-1'*Q^-1'*P'*P*Q^-1*N^-1
(Obviously you can't *actually* say that because N and Q are noninvertible, but it illustrates the thought process... the transformation by the tangents just wraps the original formulation.)
Have I understood that correctly?
Though this still leaves me wondering how the transformation by the tangents works. I think my difficulties with this are because I'm trying to draw analogies between this operation and the use of basis vectors I am familiar with (where a matrix of basis vectors is the same as a transform from Basis->Global, so the inverse of the same matrix converts from Global->Basis).
I at first imagined that eqn. 38 is doing something similar, but I should probably work through an example to see what really happens to the points during this operation.
Thanks again!
Sj
-
- Posts: 122
- Joined: Thu May 05, 2011 11:47 am
Re: How does the Strain Based Dynamics material transform wo
Yessebjf wrote:Have I understood that correctly?
OK. Let me elaborate from what I understand. For the triangular element, we are trying to come up with a material frame (a basis) so that we could covert a given attribute in the triangles coordinate system with x0 being the origin. For this paragraph, we are dealing with material coordinates. The idea behind doing P=[x1-x0, x2-x0] is to assume that x0 is the origin of the triangle material frame. Now from our knowledge of triangles, we know that we can use a set of parameters (u,v or s,t) texture coordinates to linearly interpolate an attribute in the u,s (weft) and v,t(warp) direction on the triangle. We calculate U=[uv1-uv0, uv2-uv0] again assuming the first value (uv0) as origin. If we wanted to interpolate an attribute on triangle, we would multiply it with U matrix. To get any attribute in the uv parameterization frame, we would multiply it with Uinv. We get the inverse matrix of U and then obtain our tangent matrix by multiplying P with Uinv. This is essentially finding the relative change between the triangles material coordinates with respect to the uv parametrization frame. This is what introduces the anisotropicity in the model that is the force distribution is not symmetric but it varies in the u and v directions subject to how the uv coordinates and material coordinates vary. The tangent matrix is then multiplied with the material coordinates (P matrix) to obtain the Qinv matrix.sebjf wrote:Though this still leaves me wondering how the transformation by the tangents works.
Now the good thing with this is that all required matrices are fixed so we can precalculate the Qinv matrix once at initialization. At runtime, we just obtain the new P matrix by using current positions, and then simply multiply with Qinv matrix to get the strain values for a given triangle element.
Hope it helps. I had a hard time figuring things out but after a couple of reads and some help from these forums, I managed to finally understand how it works. I do hope the accompanying demo and book chapter helps you in your understanding of SBD.
Regards,
Mobeen
-
- Posts: 9
- Joined: Mon Jun 06, 2016 9:34 pm
Re: How does the Strain Based Dynamics material transform wo
Thank you mobeen,
That was helpful again!
That is, [n1,n2]'*(x1-x0,x2-x0) is essentially using the dot product to project each edge into each tangent, forming a 2x2 matrix indicating the extents of each edge, along n1 and n2. When multiplying by the inverse of a similar matrix for a deformed point, the result is deformation of the extents of each edge, in each tangent.
Using UV coordinates allows the weft and warp directions to be easily controlled by the designer, but this is actually separate from how [n1,n2] functions - any two tangets could be chosen, so long as they are orthogonal.
Is that right? I have done a quick example and it seems to hold, but it was only one!
Sj
That was helpful again!
OK I think I have this. So rather than thinking of [n1,n2] as a set of basis vectors that transform between two similar coordinate systems, we should consider it like a transform that performs a projection. The transform takes the edges and projects them into the basis, expressing the coordinates as a set of extents.Now from our knowledge of triangles, we know that we can use a set of parameters (u,v or s,t) texture coordinates to linearly interpolate an attribute in the u,s (weft) and v,t(warp) direction on the triangle.
That is, [n1,n2]'*(x1-x0,x2-x0) is essentially using the dot product to project each edge into each tangent, forming a 2x2 matrix indicating the extents of each edge, along n1 and n2. When multiplying by the inverse of a similar matrix for a deformed point, the result is deformation of the extents of each edge, in each tangent.
Using UV coordinates allows the weft and warp directions to be easily controlled by the designer, but this is actually separate from how [n1,n2] functions - any two tangets could be chosen, so long as they are orthogonal.
Is that right? I have done a quick example and it seems to hold, but it was only one!
Sj
-
- Posts: 122
- Joined: Thu May 05, 2011 11:47 am
Re: How does the Strain Based Dynamics material transform wo
Hmm I dont think so. We used the uv coordinates of our triangle to get the tangents. I dont think the orthogonality is necessary here between tu and tv. From what I see, we are multiplying here ( [n1,n2]'*(x1-x0,x2-x0) ) to get a square matrix so that we may get the inverse of it which is stored as Qinvsebjf wrote:any two tangets could be chosen, so long as they are orthogonal.
-
- Posts: 9
- Joined: Mon Jun 06, 2016 9:34 pm
Re: How does the Strain Based Dynamics material transform wo
Hi mobeen,
My thinking for the tangents went like this:
The authors placed no constraints on the UVs, so we could say that uv1 = [1,0] and uv2 = [0,1]. This case would lead to the tangents being the edges of the triangle.
The appendix says
tu = e1
and
tv = normalise(cross(triangle_normal, tu))
I have tried this and it works for recovering the strain tensor (though I have not yet done the corrections with it!). However, I was too general saying any orthogonal vectors, I tried a few more examples and found the vectors had to be co-planar with the edges, otherwise there are consistent, but odd, offsets in the resulting tensor.
I am glad I understand what Q is doing now though, since that was originally the bit I wanted to get before going any further.
Thanks again,
Sj
My thinking for the tangents went like this:
The authors placed no constraints on the UVs, so we could say that uv1 = [1,0] and uv2 = [0,1]. This case would lead to the tangents being the edges of the triangle.
The appendix says
So in principle you could also say:To make sure tu and tv are normal to each other, the latter can alternatively be computed as the cross product of tu with the triangle normal.
tu = e1
and
tv = normalise(cross(triangle_normal, tu))
I have tried this and it works for recovering the strain tensor (though I have not yet done the corrections with it!). However, I was too general saying any orthogonal vectors, I tried a few more examples and found the vectors had to be co-planar with the edges, otherwise there are consistent, but odd, offsets in the resulting tensor.
I think I oversimplified a bit here as well and this doesn't really hold as I look closer. I am still wondering if this works based on the relationship between edge lengths. I noted that the inner product P'P, is essentially a 2x2 matrix of dot products of the triangle edges (and should be invariant to any translation/rotation in the global frame). I tried to write down and expand the operation Q^-1'P'PQ^-1 to see what the relationship between these were, but the terms became too unwieldly and I gave up! In any case, I think I would have to understand a lot more about strain tensors before I saw how the aforementioned equation would assemble one.When multiplying by the inverse of a similar matrix for a deformed point, the result is deformation of the extents of each edge, in each tangent.
I am glad I understand what Q is doing now though, since that was originally the bit I wanted to get before going any further.
Thanks again,
Sj