constraineddyn

Upload: moon-ryul-jung

Post on 08-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 constrainedDyn

    1/10

  • 8/7/2019 constrainedDyn

    2/10

    2 BY MOON-RYUL JUNG

    suggested in the literature, that of Choi and Ko (2002) seems to be the simplest and clearest.

    Also, this work was exceptionally well-received in 2002 Siggraph, because of a lively

    animation demo and is well-known in the field of cloth simulation. This paper presents theChoi and Ko model, but uses different notions to make the presentation clearer. Moreover,

    the model of Choi and Ko incorporate artificial and ad hoc manipulations to the basic

    particle model in order to make the system matrix of the linearized motion equation positive

    definite. The positive definite of the system matrix is needed in order to use the conjugate

    gradient method to solve the linear system derived in the implicit integration method of the

    motion equation. But the positive definiteness of the system matrix is not required when

    we use other methods than the conjugate gradient method to solve the linear system. So, in

    this paper, As will be shown later, the configuration of cloth in this model is defined only

    in terms of the positions of the vertices. The particle model suggested by Breen et al uses

    angle values to measure bending and shearing of the cloth. But the particle model of Choi

    and Ko represents bending and shearing only by means of positions of the vertices. In this

    respect, the Choi and Ko model is the simplest and easy to implement.

    The two dimensional array of the particle model can be represented by an array particle[][]as follows:

    struct particleType {float mass;

    float pos[3];

    float vel[3];

    }struct particleType particle[100][100];

    In the above, we assumed that the cloth particle model has the maximum of 100 * 100

    vertices. You can access the field variables of the structure by particle[i][j].pos, parti-

    cle[i][k].vel, etc.first and second neighborhoods

    In the particle model, each vertex is assigned its neighborhood, as shown in Figure 1.

    The neighborhood of a vertex is the set of vertices whose motion influences that of the

    vertex. Typically, only the first and second neighborhood are used. The first and second

    neighborhoods of vertex (i, j), N1(i, j) and N1(i, j), are defined as follows.

    N1(i, j) = {(i 1, j 1), (i 1, j), (i 1, j + 1), (i, j 1),

    (i, j + 1), (i + 1, j 1), (i + 1, j), (i + 1, j + 1)}

    N2(i, j) = {(i 2, j 2), (i 2, j), (i + 2, j + 2), (i, j 2),

    (i, j + 2), (i + 2, j 2), (i + 2, j), (i + 2, j + 2)}

    But in the case of vertices on or near the boundary of the particle model, some neighbor-

    hoods do not exist. In the above representation, this can be detected easily. If(i 1) < 0or (i + 1) > (M1) or (j1) < 0 or (j + 1) > N1, there are no first neighbors to thevertex (i, j) at the corresponding indices. Similarly, if(i 2) < 0 or (i + 2) > (M 1)or (j 2) < 0 or (j + 2) > N 1, there are no second neighbors to the vertex (i, j) atthe corresponding indices.

    motion equation

  • 8/7/2019 constrainedDyn

    3/10

    HW7: CONSTRAINED DYNAMICS OF CLOTH MOTION 3

    To simplify the representation of the motion equation, each vertex is referred to by a one-

    dimensional index i. Note that any two-dimensional index (i, j) can be converted to the

    corresponding one dimensional index.

    The motion equation of each particle xi is described as follows:

    mixi =

    jN12(i)

    fij +

    jN12(i)

    [kd(vi vj)] + mig(1)

    Here N12(i) = N1(i) N2(i). N1(i) refers to the set of the first neighbors to vertex i,

    and N2(i) refers to the set of the second neighbors to vertex i. Confer to Figure 1. fijrefers to the force that vertex i receives from vertex j. kd(vivj refers to the dissipativeor resistent force that vertex i receives from vertex j. This force acts against the relativevelocity of vertices i and j, to prevent the relative velocity from growing too large. Thisforce contributes to the stability of motion.

    The force fij acts to resist the deformation of the segment between xi and xj , that is,to restore the rest configuration of the segment. The force fij acts in the direction thatdecreases the deformation potential energy Eij of the segment caused by the compressionor stretch or bending of the segment. This energy is a function of the positions xi and xj .The force fij is calculated differently depending on whether the vertex j is a first or secondneighbor to vertex i.

    The force from the first neighborhood

    In the case of first neighborhood of vertex i, the segment between xi and xj is assumed tobe compressed or stretched in the direction of the segment. Let us call the energy caused

    this way as the tension energy Etij .

    Etij = (1/2)ks(|xi xj| Lij)2(2)

    fij = Etij

    xi= ks(|xi xj | Lij)

    (xi xj)

    |xi xj |(3)

    Here Lij is the length of the segment xixj at the rest state.

    The force from the second neighborhood

    In the case of second neighborhood of vertex i, the segment between xi and xj is assumedto bent, as shown at the end of the paper. We assume that the bent segment takes the shape

    of an arc, that is, a part of a circle. Then the bending potential energy of the bent segment

    Ebij is specified as follows:

  • 8/7/2019 constrainedDyn

    4/10

    4 BY MOON-RYUL JUNG

    Ebij = (1/2)kbLijk2ij(4)

    kij = (2/Lij)sinc1(|xi xj |/Lij)(5)

    fij = Ebij

    xi(6)

    = kbkijLijdkij

    d|xij|

    xij|xij|

    (7)

    = kbkijLijd|xij|

    dkij

    xij|xij|

    (8)

    = kbk2ij[cos(kijLij/2) sinc(kijLij/2)]

    1 xij|xij|

    (9)

    matrix notation of motion equation

    The motion equations in (1) can be represented as a single equation as follows:

    Mx = f(x, v)(10)

    Here x = (x11, x12, x13..., xn1, xn2, xn3)T. Similarly for v. f= (f11, f12, f13...,fn1, fn2, fn3)

    T.

    n is the number of vertices in the particle model. (xi1, xi2, xi3) refers to the three coordi-nates of vertex i. We use xi to refer to the position of vertex i, and fi to refer to the forceapplied to vertex i. We have

    fi =

    jN12(i)fij +

    jN12(i)[kd(vi vj)] + mig.

    Mis a diagonal matrix of the form

    m1 0 00 m1 00 0 m1

    . . .

    mn 0 00 mn 00 0 mn

    .

    The differential equation in (10) can be transformed to the following first order system:

    (11)

    xv

    =

    v

    M1f(x, v)

    Question 1: Derive the forward Euler method for solving the ordinary differential equation

    in (11).

    Question 2: Derive the backward (implicit) Euler method for solving the equation. The

    linearization of equation (11) proceeds as follows:

  • 8/7/2019 constrainedDyn

    5/10

    HW7: CONSTRAINED DYNAMICS OF CLOTH MOTION 5

    xivi

    = h

    vi + viM1f(xi + xi, vi + vi)

    (12)

    xi = h(vi + vi)(13)

    vi = hM1(f(xi, vi) + hM1

    f

    xxi +

    f

    vvi

    xi hvi = hvi(14)

    I hM1f

    v h2M1

    f

    x

    vi = hM1

    f(xi, vi) +

    f

    xvi

    Here fx

    and fx

    refer to the values evaluated at the state (xi, vi). We will use symbol A to

    denote the matrix [I hM1 fv h2M1 f

    x], and call the matrix system matrix.

    Question 3: Derive fv

    and fx

    . Discuss whether these matrices are definite. Discuss

    whether matrix A is positive definite. IfA is not positive definite, make A positive definiteby removing some terms from the formula of forces fij .

    The block matrix form of the equation (14) is represented as follows:

    I3n3n hI3n3n A3n3n

    xi

    vi

    =

    hvi

    bi

    (15)

    But the matrix of the system (15) is not symmetric, nor positive definite. So, we cannot

    use a conjugate gradient method suitable to solve the large and spare system, even if the

    system matrix A is symmetric and positive definite. When A is symmetric and positivedefinite, we split the system as follows:

    xi hvi = hvi(16)

    Avi = bi(17)

    Then we apply a conjugate gradient method to the subsystem (17). We can obtain xi bysubstituting vi to the subsystem (16).

    Question 4: Implement both forward Euler and backward Euler Method for cloth simula-

    tion. Assuming that you made A positive definite, use the conjugate gradient method forsolving the linear system involved in the implicit Euler method.

    3. CONSTRAINED DYNAMICS

    Consider the motion equation:

    xv

    =

    v

    M1f(x, v)

    (18)

  • 8/7/2019 constrainedDyn

    6/10

    6 BY MOON-RYUL JUNG

    The motion equations describes the rate in which the trajectory (x(t), v(t)) changes bymeans of the force M1f(x(t), v(t)) applied at the current state (x(t), v(t)) of the sys-

    tem. The motion equations determine a unique trajectory given a specific initial condition.Suppose that we want to add additional conditions for the trajectory to satisfy. But this

    time, the conditions are not specified as differential equations, but as algebraic equations

    for the state variables (x, v), i.e., c(x(t), v(t)) = 0, where

    (19) c(x(t), v(t)) =

    c1(x, v)...

    cm(x, v)

    We assume that the constraints are independent of each other, that there are no constraints

    which can be obtained by linear combination of other constraints.

    Whereas the motion equations describe the mechanism by which the state variables change,

    the additional conditions only say that the state variables should be restricted without spec-ifying exact reasons. These conditions are called constraints, because they further con-

    strain the motion defined by the motion equations. The constraints may specify conditions

    at given times, or for all time. We assume that there are m constraints, with m < 3n,where n is the number of vertices, and 3n is the dimension of the position variable x.

    We assume that typically only neighbor variables are involved in each constraint. In our

    cloth model, each constraint is typically applied to a vertex, or a set of neighbor vertices.

    The constraints we allow directly specifies some components of position correction vectors

    and velocity correction vectors: xkj = vkj , j = 1, m1 and/or vkj = akj , j = 1, m2.Here the indices k1, k2,... refer to the components ofx or v whose values are specified byj-th constraint for position change or velocity change.

    In the process of putting cloth on the body, the contact points between cloth and the body

    impose position change or velocity change constraints. In this case, those constraints are

    not known in advance, but should be discovered in the process of putting cloth on the

    body. During each step, it is checked whether the path of cloth from the current position

    to the next position intersects the body surface. If so, appropriate positional constraints are

    imposed to prevent penetration. But in this paper, we simply assume that constraints are

    given in advance or arbitrary given during simulation.

    Exact formulation of constrained dynamics using Lagrange multipliers

    To devise methods to solve constrained dynamics, we need to formulate it precisely. Now

    the motion equations a trajectory of the system uniquely given an initial condition. So,

    there is no way for the motion equations to produce a trajectory that satisfies the constraints.

    In fact, to satisfy the constraints, we should modify the motion equations themselves byadding forces fc as unknowns to the equation (18). These forces are called constraintforces because they are related to satisfying the constraints. Given motion equations, the

    constrained dynamics is formulated as follows:

    xv

    =

    v

    M1[f(x, v) + fc]

    (20)

    c(x, v) = 0.

  • 8/7/2019 constrainedDyn

    7/10

    HW7: CONSTRAINED DYNAMICS OF CLOTH MOTION 7

    Here the constraint force fc is an unknown m-dimensional vector. But constraints aretypically applied to some vertices, so many components offc are zero. Solving this prob-

    lem comes down to finding fc that, together with the force f(x, v), produces a trajec-tory (x(t), v(t)) satisfying the constraint c(x(t), v(t)) = 0. The constraint force is a 3n-dimensional vector as is force f(x, v) and the constraint c(x, v) is a m-dimensional vector.We assume m < 3n, because m = 3n would mean that the system is fully constrained andthe motion equation is useless. The system (20) is solved by locally linearizing them. Then,

    the number of system state variables and constraint force variables will be greater than the

    number of equations in the linearized system. So, we need to apply some optimization

    criteria to determine the constraint forces fc uniquely.

    Specifying Constraint Forces

    The constraints c(x, v) are in general algebraic equations specifying the values of the vari-ables (x, v) and the relationships among them. We first discuss how to handle the generalform of constraints to solve the constrained system. Then we discuss simpler forms of

    constraints and discuss efficient techniques to handle them.

    Consider the constrained dynamics:

    xv

    =

    v

    M1[f(x, v) + fc]

    (21)

    c(x, v) = 0.(22)

    The constraint force fc is introduced to maintain the constraint c(x, v) = 0, by counteract-ing against the force fwhen it tries to violate the constraint. The constraint force is sup-posed to do nothing more than counteracting. The constraint-violating actions occur in the

    directions in the space of(x, v) such that the movements along those directions change thevalues ofci(x, v), i = 1, m from zero to positive or negative values. That is, the violatingactions occur in the directions normal to the constraint surfaces, i.e. the surfaces defined

    by {(x, v)|ci(x, v) = 0}, i = 1, m. Those directions are given by (ci

    (x,v))T, i = 1, m.

    Here cix

    , i = 1, m are gradient vectors (row vectors) ofcis.

    The constraint force fc that can counteract against the violating actions is given by a linearcombination of those violating actions:

    (23) fc = 1(c1

    (x, v))T+ 2(

    c2(x, v)

    )T+ ... + m(cm

    (x, v))T.

    The coefficients is are called the Lagrange multipliers. Note that the 3n dimensional vec-tor fc has been reduced to an m dimensional vector in (23). This force does not contributeto the movement along the directions tangent to the constraint surfaces. This movement

    is more than what the constraint force is required to do. By substituting the equation (23)

    into equation (21), we obtain the following equations:

  • 8/7/2019 constrainedDyn

    8/10

    8 BY MOON-RYUL JUNG

    xv

    = v

    M1[f(x, v) +cx

    T]

    (24)

    =

    v

    M1[f(x, v) + 1(c1

    (x,v))T+ 2(

    c2(x,v)

    )T+ ... + m(cm(x,v)

    )T]

    ci(x, v) = 0, i = 1, m.(25)

    Here

    c(x,v)

    is the m n Jacobian matrix of vector c with respect to vector x:

    c

    (x, v) = cx

    cv =

    c1x

    c1v

    ...

    cmx cm

    v

    .

    Linearizing Constrained Dynamics

    To solve the equations of constrained dynamics (24 and 24), we linearize them by using an

    implicit Euler method for the dynamics equations:

    I hI A

    xi

    vi

    =

    hvi

    bi

    +cx

    cv

    T(26)

    c

    x

    xi +

    c

    v

    vi = c(xi, vi)(27)

    m1j=1

    akjxikj

    +m2j=1

    bkjvikj

    = ckj

    cx

    cv

    xivi

    =

    c

    x

    xi +

    c

    v

    vi = 0(28)

    The initial state (x0, v0) satisfying the constraint c(x, v) = 0 is given.(29)

    Here cx

    and cv

    are Jacobian matrices ofc with respect to x and v that are evaluated at

    state (xi, vi).

    The differential form of the constraint shown in equation (28) indicates that the legal mo-

    tion (xi, vi) is orthogonal to the gradient vectors ofci,ci

    (x,v). These vectors are normal

    to the constraint surfaces. Solving the constrained dynamics comes down to finding solu-

    tions (xi, vi) to the linear system defined by equations (26) and (28). We assume thatconstraints are specified directly in the differential forms as in equation (28), that is, as a

    linear combination ofxi and vi, rather than as general conditions about xi and vi as inc(x, v) = 0 c(x, v) = 0, although constraints are typically given as linear conditions fromthe beginning. In this paper, we further simplify the constraints so that they specify spe-

    cific values ofxij and vij . So, they do not specify relationship among x

    ij , j = 1, 3n,

    among vij , j = 1, 3n, or among xij , j = 1, 3n and v

    ij , j = 1, 3n. (But, the method

    described below can be applied to the general case of linear constraints.) We need to use

  • 8/7/2019 constrainedDyn

    9/10

    HW7: CONSTRAINED DYNAMICS OF CLOTH MOTION 9

    an iterative method because the system is large and sparse. Typically, the CPU time differ-

    ence between direct method and iterative method is of order n, where n is the number of

    variables.

    Reduced Coordinate or Projection Method

    In the linearized dynamics equation augmented by linearized constraint equations (26) and

    (28) the variables are x,v,i, i = 1, m and the number of variables is 3n + 3n + m. Thenumber of equations is also 3n + 3n + m, so the system can be solved uniquely for thosevariables.

    One method of handling the constraints xkj = vkj and/or vkj = akj is as follows:

    (1) Determine the free subspace and change the variables (x, v) in R23n to thevariables q in the free subspace. The constrained subspace is the set of move-ments that are specified by the constraints, and the free subspace is the set of

    movements not specified by the constraints, and are orthogonal to the constrainedsubspace, and so are free to be determined by the unconstrained motion equations.

    (2) Transform the system (26) onto the free space so that the resulting system is spec-

    ified in terms of the new variables q in the free space. The transformation elim-inates the variables .

    (3) Find the solution vector q in the free subspace, and transform the solution vectorto the original representation (x, v).

    When the constraints specify the values of individual xi and vi, the process of find-ing the solution vector q does not need to consider the constraint equations (28). ??But,otherwise, the constrains should be also transformed, and they should be solved simulta-

    neously with the transformed system equations. *** In this method, we need to updatethe Jacobian matrices fx

    and fv

    in the system matrix A, whenever the projection onto thenew free subspace. In cloth simulation, constraints may be changed quite often, once per

    a few steps. This bookkeeping of the Jacobian matrices is complicated and inefficient. So,

    we avoid this method.

    Find the solution with illegal components and then remove those components

    The linear system defined by equations (26) and (28) can be interpreted as follows:

    Given the initial state (x0, v0), compute the correction vector (x0, v0)to get the new state (x1, v1) such that (x1, v1) = (x0, v

    0) + (x0, v0).Repeat this process for each i = 1, 2,.... The correction vector (x0, v0)should be orthogonal to the constraint gradient vectors ci

    (x,v), i = 1, m.

    In the following, we omit the superscript index i for time step, unless confusing.

    4. FINDING EQUILIBRIUM

    In addition to finding trajectories by the equations (20), we can also use them to finding

    equilibrium states. Equilibrium states are states in which the system does not move. So,

    finding an equilibrium comes down to solving the following equations:

  • 8/7/2019 constrainedDyn

    10/10

    10 BY MOON-RYUL JUNG

    xv 0

    0 = v

    M1[f(x, 0) + fc](30)

    c(x, 0) = 0.

    The equations (42) can be reduced as follows:

    M1[f(x, 0) + fc] = 0(31)

    c(x, 0) = 0.(32)

    The equations (43) and (44) are non-linear algebraic equations for position variable x,which can be solved by the Newton-Raphson method.

    Calling Fortran from C

    struct particleType {

    float mass;float pos[3];

    float vel[3];

    }struct particleType particle[100][100];

    extern C {void dcsint(int *ient, float *h, int *n, float tnode[], float g[],

    float *end1, float *endn, float b[],

    float c[], float d[]);

    }

    int main()

    {// Note that array names g, b, c, and d are already pointers to floats// but we use & to get pointers to ient, h, n, end1, endn

    dcsint(&ient, &h, &n, tnode, g, &end1, &endn, b, c, d);[3] [4]

    }