Subsections

3 Condition Functions

Baraff & Witkin used condition functions as an indirect way of defining energy and forces. Their condition functions are almost the same as energy formulas, since $ E=\frac{k}{2}{\bf C}^T{\bf C}$ , where $ {\bf C}$ is the condition function. For the scalar condition functions (shear and bend), $ E=\frac{k}{2}C^2$ , and the condition function is hence basically just the squart-root of the energy, except that it can be positive or negative.

The condition functions were defined explicitly in the paper. Energy and forces can also be easily calculated, if the derivatives of the condition functions are known. However, the paper didn't provide explicit equations for the derivatives or second derivatives.

Macri made a good attempt at deriving the equations for the derivatives and second derivatives. I found two major shortcomings in his approach, however. First, he made reference to tensors and other mathematical constructs that aren't really necessary for the derivation. Second, I found an error in his derivation for the bend condition.

3.1 Per-Triangle Quantities

To begin, I will define a few quantities that will help with explanation of the stretch and shear conditions. These quantities are defined for a triangle using points $ {\bf x}_0$ , $ {\bf x}_1$ , and $ {\bf x}_2$ . The triangle's area in $ u$ /$ v$ space is given by

$\displaystyle a$ $\displaystyle = \frac{1}{2} \begin{Vmatrix}\begin{pmatrix}\Delta u_1 \\ \Delta ...
...\times \begin{pmatrix}\Delta u_2 \\ \Delta v_2 \\ 0 \end{pmatrix} \end{Vmatrix}$ (1)

The $ {\bf {\hat w}}_u$ and $ {\bf {\hat w}}_v$ vectors represent the directions of the $ u$ and $ v$ axes in world space, as seen within a single triangle. They are defined by

$\displaystyle {\bf {\hat w}}_u$ $\displaystyle = \frac{ {\bf w}_u}{\begin{Vmatrix}{\bf w}_u\end{Vmatrix}}$ $\displaystyle {\bf {\hat w}}_v$ $\displaystyle = \frac{ {\bf w}_v}{\begin{Vmatrix}{\bf w}_v\end{Vmatrix}}$ (2)

$\displaystyle {\bf w}_u$ $\displaystyle = \frac{ ({\bf x}_1 - {\bf x}_0) \Delta v_2 - ({\bf x}_2 - {\bf x}_0) \Delta v_1} {\Delta u_1 \Delta v_2 - \Delta u_2 \Delta v_1}$ (3)
$\displaystyle {\bf w}_v$ $\displaystyle = \frac{ -({\bf x}_1 - {\bf x}_0) \Delta u_2 + ({\bf x}_2 - {\bf x}_0) \Delta u_1} {\Delta u_1 \Delta v_2 - \Delta u_2 \Delta v_1}$ (4)

The first derivatives of the unnormalised vectors $ {\bf w}_u$ and $ {\bf w}_v$ are given by

$\displaystyle \frac{\partial {\bf w}_u}{\partial {\bf x}_m}$ $\displaystyle = \frac{\partial {\bf w}_{u_x}}{\partial {\bf x}_{m_x}} {\bf I}$ (5)
$\displaystyle \frac{\partial {\bf w}_{u_x}}{\partial {\bf x}_{0_x}}$ $\displaystyle = \frac{\Delta v_1 - \Delta v_2}{\Delta u_1\Delta v_2 - \Delta u_2\Delta v_1}$ (6)
$\displaystyle \frac{\partial {\bf w}_{u_x}}{\partial {\bf x}_{1_x}}$ $\displaystyle = \frac{\Delta v_2}{\Delta u_1\Delta v_2 - \Delta u_2\Delta v_1}$ (7)
$\displaystyle \frac{\partial {\bf w}_{u_x}}{\partial {\bf x}_{2_x}}$ $\displaystyle = \frac{-\Delta v_1}{\Delta u_1\Delta v_2 - \Delta u_2\Delta v_1}$ (8)

$\displaystyle \frac{\partial {\bf w}_v}{\partial {\bf x}_m}$ $\displaystyle = \frac{\partial {\bf w}_{v_x}}{\partial {\bf x}_{m_x}} {\bf I}$ (9)
$\displaystyle \frac{\partial {\bf w}_{v_x}}{\partial {\bf x}_{0_x}}$ $\displaystyle = \frac{\Delta u_2 - \Delta u_1}{\Delta u_1\Delta v_2 - \Delta u_2\Delta v_1}$ (10)
$\displaystyle \frac{\partial {\bf w}_{v_x}}{\partial {\bf x}_{1_x}}$ $\displaystyle = \frac{-\Delta u_2}{\Delta u_1\Delta v_2 - \Delta u_2\Delta v_1}$ (11)
$\displaystyle \frac{\partial {\bf w}_{v_x}}{\partial {\bf x}_{2_x}}$ $\displaystyle = \frac{\Delta u_1}{\Delta u_1\Delta v_2 - \Delta u_2\Delta v_1}$ (12)

The second derivatives of $ {\bf w}_u$ and $ {\bf w}_v$ are all zero.

3.2 Stretch Condition

Baraff & Witkin define the stretch condition function as a vector $ {\bf C}$ . Two special parameters are defined for stretch, $ b_u$ and $ b_v$ . These represent the desired stretchiness of the cloth in the $ u$ and $ v$ directions. A $ b_u$ value below one will result in the cloth trying to compress in the $ u$ direction, while a $ b_u$ value above one will result in the cloth trying to stretch in the $ u$ direction.

$\displaystyle {\bf C}= \begin{pmatrix}C_u\\ C_v\end{pmatrix} =$ $\displaystyle \alpha \begin{pmatrix}\begin{Vmatrix}{\bf w}_u\end{Vmatrix} - b_u \\ \begin{Vmatrix}{\bf w}_v\end{Vmatrix} - b_v \end{pmatrix}$ (13)

Baraff & Witkin defined $ \alpha=a$ , the area of the triangle. We define $ \alpha=a^\frac{3}{4}$ , for reasons described later.

The first and second derivatives of the stretch condition function are

$\displaystyle \frac{\partial C_u}{\partial {\bf x}_m}$ $\displaystyle = \alpha \frac{\partial {\bf w}_{u_x}}{\partial {\bf x}_{m_x}} {\bf {\hat w}}_u$ (14)
$\displaystyle \frac{\partial^2 C_u}{\partial {\bf x}_m \partial {\bf x}_n}$ $\displaystyle = \frac{\alpha}{\begin{Vmatrix}{\bf w}_u\end{Vmatrix}} \frac{\par...
...rtial {\bf x}_{n_x}} \left( {\bf I}- {\bf {\hat w}}_u{\bf {\hat w}}_u^T \right)$ (15)
$\displaystyle \frac{\partial C_v}{\partial {\bf x}_m}$ $\displaystyle = \alpha \frac{\partial {\bf w}_{v_x}}{\partial {\bf x}_{m_x}} {\bf {\hat w}}_v$ (16)
$\displaystyle \frac{\partial^2 C_v}{\partial {\bf x}_m \partial {\bf x}_n}$ $\displaystyle = \frac{\alpha}{\begin{Vmatrix}{\bf w}_v\end{Vmatrix}} \frac{\par...
...rtial {\bf x}_{n_x}} \left( {\bf I}- {\bf {\hat w}}_v{\bf {\hat w}}_v^T \right)$ (17)

These second derivatives exhibit some symmetry, since $ \frac{\partial^2 C_u}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}}
=
\frac{\partial^2 C_u}{\partial {\bf x}_{n_t} \partial {\bf x}_{m_s}}
$ . Consequently, the $ 3\times3$ matrix $ \frac{\partial^2 C_u}{\partial {\bf x}_m \partial {\bf x}_n}
=
\frac{\partial^2 C_u}{\partial {\bf x}_n \partial {\bf x}_m}
^T$ . To avoid any tensors when applying Baraff & Witkin's equation (8) to the shear equations, remember that

$\displaystyle \frac{\partial^2 {\bf C}({\bf x})}{\partial {\bf x}_m \partial {\bf x}_n} {\bf C}({\bf x})$ $\displaystyle = \frac{\partial^2 C_u}{\partial {\bf x}_m \partial {\bf x}_n} C_u+ \frac{\partial^2 C_v}{\partial {\bf x}_m \partial {\bf x}_n} C_v$ (18)

3.3 Shear Condition

Baraff & Witkin define the shear condition function as a scalar. This scalar is essentially the dot product of the $ u$ axis with the $ v$ axis in world space. If no shear is occurring, the axes are perpendicular and the condition function is zero. If shear is occurring, the condition function is equivalent to the cosine of the angle between them, weighted by the triangle's area in $ u$ / $ v$ space.

$\displaystyle C$ $\displaystyle = \alpha {\bf w}_u\cdot {\bf w}_v$ (19)

Baraff & Witkin's condition assumes that $ {\bf w}_u$ and $ {\bf w}_v$ are approximately unit vectors. If $ b_u$ and $ b_v$ are both equal to one, then this approximation is a fair one. If, however, $ b_u$ or $ b_v$ are not equal to one, the approximation may give rise to some strange behaviour. I have not had a chance to investigate the effects of varying $ b_u$ or $ b_v$ .

Since we know the derivatives of $ {\bf w}_u$ and $ {\bf w}_v$ , taking the derivative of this condition function is trivial.

$\displaystyle \frac{\partial C}{\partial {\bf x}_{m_s}}$ $\displaystyle = \alpha \left( \frac{\partial {\bf w}_u}{\partial {\bf x}_{m_s}}...
... w}_v+ {\bf w}_u\cdot \frac{\partial {\bf w}_v}{\partial {\bf x}_{m_s}} \right)$ (20)
  $\displaystyle = \alpha \left( \frac{\partial {\bf w}_{u_x}}{\partial {\bf x}_{m...
...s}+ {\bf w}_{u_s} \frac{\partial {\bf w}_{v_x}}{\partial {\bf x}_{m_x}} \right)$ (21)

$\displaystyle \frac{\partial^2 C}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}}$    
$\displaystyle =$ $\displaystyle \,\alpha \biggl( \frac{\partial^2 {\bf w}_u}{\partial {\bf x}_{m_...
...artial {\bf x}_{m_s}} \cdot \frac{\partial {\bf w}_v}{\partial {\bf x}_{n_t}} +$    
  $\displaystyle \frac{\partial {\bf w}_u}{\partial {\bf x}_{n_t}} \cdot \frac{\pa...
...ac{\partial^2 {\bf w}_u}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}} \biggr)$ (22)
$\displaystyle =$   (23)

These second derivatives exhibit even more symmetry than the stretch condition. Like the stretch condition, $ \frac{\partial^2 C}{\partial {\bf x}_m \partial {\bf x}_n}
=
\frac{\partial^2 C}{\partial {\bf x}_n \partial {\bf x}_m}
^T$ but beyond that, the $ \frac{\partial^2 C}{\partial {\bf x}_m \partial {\bf x}_n}
$ is actually just an identity matrix multiplied by a scalar.

3.4 Bend Condition

Baraff & Witkin define the bend condition in terms of two adjoining triangles. I have labelled the unit normals of these triangles as $ {\bf {\hat n}}^A$ and $ {\bf {\hat n}}^B$ , rather than Baraff & Witkin's $ {\bf n}_1$ or $ {\bf n}_2$ . The unit vector parallel to their common edge is labelled $ {\bf {\hat e}}$ . Quantities associated with the normals or the common edge receive a superscript $ A$ , $ B$ or $ e$ .

$\displaystyle {\bf {\hat n}}^A$ $\displaystyle = \frac{{\bf n}^A}{\begin{Vmatrix}{\bf n}^A\end{Vmatrix}}$ $\displaystyle {\bf {\hat n}}^B$ $\displaystyle = \frac{{\bf n}^B}{\begin{Vmatrix}{\bf n}^B\end{Vmatrix}}$ $\displaystyle {\bf {\hat e}}$ $\displaystyle = \frac{{\bf e}}{\begin{Vmatrix}{\bf e}\end{Vmatrix}}$ (24)

$\displaystyle {\bf n}^A$ $\displaystyle = ({\bf x}_2 - {\bf x}_0) \times ({\bf x}_1 - {\bf x}_0)$ (25)
$\displaystyle {\bf n}^B$ $\displaystyle = ({\bf x}_1 - {\bf x}_3) \times ({\bf x}_2 - {\bf x}_3)$ (26)
$\displaystyle {\bf e}$ $\displaystyle = {\bf x}_1 - {\bf x}_2$ (27)

The scalar bend condition $ C$ is defined quite simply as the angle between the two edges, $ \theta$ .

$\displaystyle \cos \theta$ $\displaystyle = {\bf {\hat n}}^A \cdot {\bf {\hat n}}^B$ (28)
$\displaystyle \sin \theta$ $\displaystyle = ({\bf {\hat n}}^A \times {\bf {\hat n}}^B) \cdot {\bf {\hat e}}$ (29)
$\displaystyle C = \theta$ $\displaystyle = \arctan \frac{\sin \theta}{\cos \theta}$ (30)

Macri defined $ C$ using the $ \arccos$ function, which is incorrect and will only yield positive values for $ \theta$ . My definition of $ C$ will yield both positive and negative values if implemented using the atan2 function.

In order to find the derivatives of $ C$ , we need the derivatives of the quantities seen so far. The first and second derivatives of $ {\bf n}^A$ , $ {\bf n}^B$ and $ {\bf e}$ are shown below, using auxiliary variables $ {\bf q}_m$ . The derivatives of $ {\bf q}_m$ are straightforward to derive.

$\displaystyle \frac{\partial {\bf n}^A}{\partial {\bf x}_{m_s}}$ $\displaystyle = S_s({\bf q}^A_m)$ (31)
$\displaystyle \frac{\partial {\bf n}^B}{\partial {\bf x}_{m_s}}$ $\displaystyle = S_s({\bf q}^B_m)$ (32)
$\displaystyle \frac{\partial {\bf e}}{\partial {\bf x}_{m_s}}$ $\displaystyle = q^e_m {\bf I}_s$ (33)

$\displaystyle {\bf q}^A$ $\displaystyle = \{ {\bf x}_2 - {\bf x}_1, {\bf x}_0 - {\bf x}_2, {\bf x}_1 - {\bf x}_0, {\bf0} \}$ (34)
$\displaystyle {\bf q}^B$ $\displaystyle = \{ {\bf0}, {\bf x}_2 - {\bf x}_3, {\bf x}_3 - {\bf x}_1, {\bf x}_1 - {\bf x}_2 \}$ (35)
$\displaystyle q^e$ $\displaystyle = \{ 0, 1, -1, 0 \}$ (36)

$\displaystyle \frac{\partial^2 {\bf n}^A}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}}$ $\displaystyle = S_s\left( \frac{\partial {\bf q}^A_m}{\partial {\bf x}_{n_t}} \right)$ (37)
$\displaystyle \frac{\partial^2 {\bf n}^B}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}}$ $\displaystyle = S_s\left( \frac{\partial {\bf q}^B_m}{\partial {\bf x}_{n_t}} \right)$ (38)
$\displaystyle \frac{\partial^2 {\bf e}}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}}$ $\displaystyle = {\bf0}$ (39)

Using Baraff & Witkin's assumption that the normal and edge vectors have constant magnitude,

$\displaystyle \frac{\partial {\bf {\hat n}}^A}{\partial {\bf x}_{m_s}}$ $\displaystyle = \frac{1}{\begin{Vmatrix}{\bf n}^A\end{Vmatrix}} \frac{\partial {\bf n}^A}{\partial {\bf x}_{m_s}}$ (40)
$\displaystyle \frac{\partial {\bf {\hat n}}^B}{\partial {\bf x}_{m_s}}$ $\displaystyle = \frac{1}{\begin{Vmatrix}{\bf n}^B\end{Vmatrix}} \frac{\partial {\bf n}^B}{\partial {\bf x}_{m_s}}$ (41)
$\displaystyle \frac{\partial {\bf {\hat e}}}{\partial {\bf x}_{m_s}}$ $\displaystyle = \frac{1}{\begin{Vmatrix}{\bf e}\end{Vmatrix}} \frac{\partial {\bf e}}{\partial {\bf x}_{m_s}}$ (42)

$\displaystyle \frac{\partial^2 {\bf {\hat n}}^A}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}}$ $\displaystyle = \frac{1}{\begin{Vmatrix}{\bf n}^A\end{Vmatrix}} \frac{\partial^2 {\bf n}^A}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}}$ (43)
$\displaystyle \frac{\partial {\bf {\hat n}}^B}{\partial {\bf x}_{m_s}} {{\bf x}_{n_t}}$ $\displaystyle = \frac{1}{\begin{Vmatrix}{\bf n}^B\end{Vmatrix}} \frac{\partial^2 {\bf n}^B}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}}$ (44)
$\displaystyle \frac{\partial^2 {\bf {\hat e}}}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}}$ $\displaystyle = {\bf0}$ (45)

Given the derivatives of the normal and edge vectors, the first and second derivatives of $ \cos \theta$ and $ \sin \theta$ are trivial to calculate.

$\displaystyle \frac{\partial \cos \theta }{\partial {\bf x}_{m_s}} =$ $\displaystyle \frac{\partial {\bf {\hat n}}^A \cdot {\bf {\hat n}}^B }{\partial {\bf x}_{m_s}}$ (46)
$\displaystyle =$ $\displaystyle \frac{\partial {\bf {\hat n}}^A}{\partial {\bf x}_{m_s}} \cdot {\...
...{\bf {\hat n}}^A \cdot \frac{\partial {\bf {\hat n}}^B}{\partial {\bf x}_{m_s}}$ (47)

$\displaystyle \frac{\partial \sin \theta }{\partial {\bf x}_{m_s}} =$ $\displaystyle \frac{\partial ({\bf {\hat n}}^A \times {\bf {\hat n}}^B) \cdot {\bf {\hat e}}}{\partial {\bf x}_{m_s}}$ (48)
$\displaystyle =$ $\displaystyle \left( \frac{\partial {\bf {\hat n}}^A}{\partial {\bf x}_{m_s}} \...
...\partial {\bf {\hat n}}^B}{\partial {\bf x}_{m_s}} \right) \cdot {\bf {\hat e}}$    
  $\displaystyle + ({\bf {\hat n}}^A \times {\bf {\hat n}}^B) \cdot \frac{\partial {\bf {\hat e}}}{\partial {\bf x}_{m_s}}$ (49)

$\displaystyle \frac{\partial^2 \cos \theta}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}} =$ $\displaystyle \frac{\partial^2 {\bf {\hat n}}^A}{\partial {\bf x}_{m_s} \partia...
...l {\bf x}_{n_t}} \cdot \frac{\partial {\bf {\hat n}}^A}{\partial {\bf x}_{m_s}}$    
  $\displaystyle + \frac{\partial {\bf {\hat n}}^A}{\partial {\bf x}_{n_t}} \cdot ...
...rac{\partial^2 {\bf {\hat n}}^B}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}}$ (50)

$\displaystyle \frac{\partial^2 \sin \theta}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}}$    
$\displaystyle =$ $\displaystyle \bigg( \frac{\partial^2 {\bf {\hat n}}^A}{\partial {\bf x}_{m_s} ...
... {\bf x}_{m_s}} \times \frac{\partial {\bf {\hat n}}^B}{\partial {\bf x}_{n_t}}$    
  $\displaystyle + \frac{\partial {\bf {\hat n}}^A}{\partial {\bf x}_{n_t}} \times...
...}^B}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}} \bigg) \cdot {\bf {\hat e}}$    
  $\displaystyle + \left( \frac{\partial {\bf {\hat n}}^A}{\partial {\bf x}_{m_s}}...
... x}_{m_s}} \right) \cdot \frac{\partial {\bf {\hat e}}}{\partial {\bf x}_{n_t}}$    
  $\displaystyle + \left( \frac{\partial {\bf {\hat n}}^A}{\partial {\bf x}_{n_t}}...
... x}_{n_t}} \right) \cdot \frac{\partial {\bf {\hat e}}}{\partial {\bf x}_{m_s}}$    
  $\displaystyle + ({\bf {\hat n}}^A \times {\bf {\hat n}}^B) \frac{\partial^2 {\bf {\hat e}}}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}}$ (51)

Finally, we can differentiate equation (30) to obtain the derivatives of $ C$ .

$\displaystyle \frac{\partial C}{\partial {\bf x}_{m_s}} =$ $\displaystyle \frac{\partial \theta}{\partial {\bf x}_{m_s}}$ (52)
$\displaystyle =$ $\displaystyle \frac{1}{\sin^2 \theta + \cos^2 \theta}$    
  $\displaystyle \times \left(\cos \theta \frac{\partial \sin \theta}{\partial {\b...
...m_s}} - \sin \theta \frac{\partial \cos \theta}{\partial {\bf x}_{m_s}} \right)$ (53)
$\displaystyle =$ $\displaystyle \cos \theta \frac{\partial \sin \theta}{\partial {\bf x}_{m_s}} - \sin \theta \frac{\partial \cos \theta}{\partial {\bf x}_{m_s}}$ (54)

Note that the second derivative formula below starts from (53), including the denominator term.

  $\displaystyle \frac{\partial^2 C}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}} = \frac{\partial^2 \theta}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}}$ (55)
  $\displaystyle = \frac{1}{(\sin^2 \theta + \cos^2 \theta)^2}$    
  $\displaystyle \times \Bigg[ (\sin^2 \theta + \cos^2 \theta) \bigg(\cos \theta \frac{\partial^2 \sin \theta}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}}$    
  $\displaystyle - \sin \theta \frac{\partial^2 \cos \theta}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}} \bigg)$    
  $\displaystyle + (\sin^2 \theta - \cos^2 \theta) \left( \frac{\partial \sin \the...
...tial {\bf x}_{m_s}} \frac{\partial \sin \theta}{\partial {\bf x}_{n_t}} \right)$    
  $\displaystyle + 2 \sin\theta \cos\theta \left( \frac{\partial \cos \theta}{\par...
...bf x}_{m_s}} \frac{\partial \sin \theta}{\partial {\bf x}_{n_t}} \right) \Bigg]$ (56)
  $\displaystyle = \cos \theta \frac{\partial^2 \sin \theta}{\partial {\bf x}_{m_s...
...ta \frac{\partial^2 \cos \theta}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}}$    
  $\displaystyle + (\sin^2 \theta - \cos^2 \theta) \left( \frac{\partial \sin \the...
...tial {\bf x}_{m_s}} \frac{\partial \sin \theta}{\partial {\bf x}_{n_t}} \right)$    
  $\displaystyle + 2 \sin\theta \cos\theta \left( \frac{\partial \cos \theta}{\par...
...tial {\bf x}_{m_s}} \frac{\partial \sin \theta}{\partial {\bf x}_{n_t}} \right)$ (57)

In a manner similar to the stretch condition, $ \frac{\partial^2 C}{\partial {\bf x}_{m_s} \partial {\bf x}_{n_t}}
=
\frac{\partial^2 C}{\partial {\bf x}_{n_t} \partial {\bf x}_{m_s}}
$ and the $ 3\times3$ matrix is symmetric. The second derivatives of $ \cos \theta$ and $ \sin \theta$ are likewise symmetric.