# Patent

## Title
Image display apparatus, method and program based on rigid body dynamics

## Abstract

An image display system and method that use physical models to produce a realistic display of a scene are disclosed. The image display method involves operating a computer having a display screen, a memory and a processing unit for simulating the motion of objects and displaying the results on the display screen. The method includes the steps of storing in the memory position and velocity parameters which define an initial state of a model system having a plurality of bodies, storing in the memory parameters which define at least one constraint function constraining the motion of the bodies in the model system, and calculating in the processor the position and velocity parameters which define the state of the system after a predetermined time step based on rigid body dynamics, including carrying out a semi-implicit integration step subject to the constraints, to determine the velocity after the step, including determining the constraint forces that act to keep the system in compliance with the constraints by ensuring that the first derivative of the constraint function is zero.

## Background
BACKGROUND OF THE INVENTION
The invention relates to an image display system and method, and in particular to an image display system that uses physical dynamic models to produce a realistic display of a scene.
It is becoming increasingly useful to display scenes on computer displays that represent the real world. Such scenes may occur in virtual reality devices, simulators and computer games.
One way of providing such scenes is to film images and to display the recorded images on the display. However, this approach requires that the content of the scene is predetermined and appropriate film sequences created and pre-stored in the computer. Thus, such an approach cannot be used where the scenes are not wholly scripted, which makes the approach unsuitable for simulations and computer games in which the user can carry out actions not predicted by the programmer.
An alternative approach uses a simulation of rigid body dynamics to allow scenes including such objects to be displayed realistically. In order to cope with simulation applications, the model has to be able to cope with a variable number of simulated objects that can be created and destroyed.
Such models should model a plurality of rigid objects that can interact with each other, subject to constraints. For example, if one object is hinged to another object that hinge acts as a constraint; the two objects cannot move independently. The existence of constraints makes the problem much more difficult to solve than a simple application of Newton's laws of motion.
A number of prior approaches have been presented but these have not proven wholly successful. The most suitable for simulation of multiple objects are so-called “extended coordinate methods” in which the constraints are introduced using Lagrange multipliers that correspond to forces that maintain the constraints. However, there are difficulties with these approaches.
Firstly, the known methods use a large number of variables, using nearly doubling the number of variables (because of the Lagrange multipliers) to describe the system, which results in them being eight times more computationally intensive than an equivalent system without constraints. Thus, the prior art methods tend to be highly inefficient.
Secondly, the known methods use differential algebraic equations that are numerically rather stiff. Simple methods for solving such equations are rather unstable.
Thirdly, it is not known how to efficiently incorporate friction into such systems. As will be appreciated, friction is an important property of real physical systems that has to be modelled correctly for a realistic result. This is a difficult problem but a working solution was reported in D. E. Stewart and J. C. Trinkle, “An implicit time-stepping scheme for rigid body dynamics with inelastic collisions and coulomb friction”, International for numerical methods in engineering, volume 39 pages 2673-2691 (1996), and was improved on by Mihai Anitescu and F. A. Potra, “Formulating dynamic multi-rigid-body contact problems with friction as solvable linear complementarity problems”, Non-linear Dynamics, volume 14 pages 231-237 (1997). The approach described allows consistent models in which the velocities can always be computed and are always finite. The disadvantage of the approach is that the model involves solving a particular class of linear complementarity problem which has a structure such that not all algorithms are suitable. Anitescu and Trinkle used the Lemke algorithm but this is inefficient and prone to large errors.
A fourth difficulty with prior art approaches is that the constraints are generated automatically; such constraints need not be not independent of one another which results in the system being degenerate. Geometric analysis software that performs collision detection cannot check whether all the constraints are truly independent of each other, and only during simulation can it be determined that some constraints are redundant. Such degeneracy can cause real problems for the simulations, especially in the case of collision detection which checks for proximity of pairs of objects, whereas the constraint degeneracy only appears at the system level including all the rigid bodies in the system.
Fifthly, known systems do not cope well with stiffness, i.e. rigid spring-like systems and compliant elements. The only tractable solutions ignore contact and friction altogether, which makes them unsuitable for analysis of arbitrary physical systems.
Accordingly, there is a need for an image display system that ameliorates or alleviates some or all of these difficulties.
The known models require the solution of linear complementarity problems, a particular type of constrained equation. In general, a linear complementarity problem can be put in the form:

Mz+q=w  (1)

zi≧0 ∀iε{1, 2 . . . n}  (2)

wi≧0 ∀iε{1, 2 . . . n}  (3)

xiwi=0 ∀iε{1, 2 . . . n}  (4)

where M is an n by n matrix and z and w are real n-dimensional vectors. The problem requires finding the solution of equation (1), i.e. the values of z and w, subject to the constraints (2)-(4).
This is fundamentally a combinatorial problems, and solutions generally search through two index sets, where each index is in one of the sets. The first set a is a set of active variables for which wi=0 and the second set β is a set of free variables for which zi=0. The problem is then partitioned as




  
    
      
        
          
            
              [
              
                
                  
                    
                      M
                      αα
                    
                  
                  
                    
                      M
                      αβ
                    
                  
                
                
                  
                    
                      M
                      βα
                    
                  
                  
                    
                      M
                      ββ
                    
                  
                
              
              ]
            
            ⁡
            
              [
              
                
                  
                    
                      z
                      α
                    
                  
                
                
                  
                    0
                  
                
              
              ]
            
          
          +
          
            [
            
              
                
                  
                    q
                    α
                  
                
              
              
                
                  
                    q
                    β
                  
                
              
            
            ]
          
        
        =
        
          [
          
            
              
                0
              
            
            
              
                
                  w
                  β
                
              
            
          
          ]
        
      
    
    
      
        (
        5
        )
      
    
  




where α and β specify indices in the first and second sets respectively.

This is equivalent to the linear algebra problem

Mααzα=−qα

wβ=Mβαzα+q  (6)

which must be solved for z while w is calculated by substitution. Mαα is known as the principal submatrix.

Various implementations are known. They differ in how the two sets are revised. They use a computed complementarity point which is a vector s such that




  
    
      
        
          s
          i
        
        =
        
          {
          
            
              
                
                  z
                  i
                
              
              
                
                  ∀
                  
                    i
                    ∈
                    α
                  
                
              
            
            
              
                
                  w
                  i
                
              
              
                
                  ∀
                  
                    i
                    ∈
                    β
                  
                
              
            
          
        
      
    
    
      
        (
        7
        )
      
    
  




The methods go through a sequence of sets until a solution is found, i.e. until si≧0 ∀iε{1, 2 . . . n}

The Murty principal pivoting algorithm is known from Murty and Yu: “Linear Complementarily, Linear and Non Linear programming” available at
www.personal.engin.umich.edu/ ̃murty/book/LCPbook/index.html,
and also in an earlier edition published by Helderman-Verlag, Heidelberg (1988), the content of which is incorporated into this specification by reference.
The indices are assigned to a set, and i is set to zero. Then, the principal submatrix Mαα is formed and solved for z using equation (6).
Then s(i)=zα+wβ is calculated, where

wβ=Mβαzα  (8)

If s≧0 then the algorithm has found a solution. Otherwise, the smallest index j for which the corresponding element of s is found. If this index is in the first set, the index is moved to the second, otherwise the index is in the second set in which case it is moved to the first set. The loop parameter i is incremented and the loop restarted until a solution is found.

The method is illustrated in the flow chart of FIG. 1.
The method is stateless and can be started from any initial guess for the division of the indices into first and second sets. The matrix will work on any P matrix and in particular on any positive definite matrix.
The method can fail where the matrix is positive semi-definite. Such matrices arise in real physical systems, and can be made positive definite by adding a small amount to each element along the diagonal. Kostreva in “Generalisation of Murty's direct algorithm to linear and convex quadratic programming”, Journal of optimisation theory and applications, Vol. 62 pp 63-76 (1989) demonstrated how to solve such positive semi-definite problems. Basically, the problem is solved for an initial value of ε, ε is then reduced until the solutions converge; if the solutions diverge the problem is unfeasible.
BRIEF SUMMARY OF THE INVENTION
According to the invention, there is provided a method, a computer program recorded on a data carrier (e.g. a magnetic or optical disc, a solid-state memory device such as a PROM, an EPROM or an EEPROM, a cartridge for a gaming console or another device), for controlling a computer (e.g. a general purpose micro, mini or mainframe computer, a gaming console or another device) having a display screen, a memory and a processing unit, the computer program being operable to control the computer to carry out the method, and a computer programmed to carry out the method.
The method according to the invention may include the steps of:

    
    
        storing in a memory position and velocity parameters defining an initial state of a model system having a plurality of bodies,
        storing in the memory parameters defining at least one constraint function constraining the motion of the bodies in the model system, and
        calculating in the processor the position and velocity parameters defining the state of the system after a predetermined time step based on rigid body dynamics, including
        carrying out a semi-implicit integration step subject to the constraints, to determine the velocity after the step, including
        determining the constraint forces that act to keep the system in compliance with the constraints by ensuring that the first derivative of the constraint function is zero.
    
    


In known approaches, the second derivative was held to be zero. However, the method according to the invention provides much faster calculation.
The method may cause the computer to carry out the further step of displaying an image of the objects at their calculated positions on the computer display screen, so that the display shows the objects on the screen using physical laws to simulate their motion.
The means for determining the constraint forces may include solving the linear complementarity problem using the Murty algorithm.
The calculating step may include carrying out the implicit integration by

    
    
        calculating the velocity parameters after the time step from the external forces, the constraint forces and the position and velocity parameters before the time step, and
        calculating the position parameters after the time step from the external forces and constraint forces, the calculated velocity parameters after the time step and the position parameters before the time step; and
    
    


In prior art image display methods implementing rigid body dynamics the accelerations have been taken as parameters. In the method according to the invention, the parameters calculated are position and velocity.
The means for solving the linear complementarity problem may include solving the boxed LCP problem by the modified Murty's method.
In order to implement maximum bounds on the constraint forces the calculation may include the step of testing whether the constraint forces have a magnitude greater than a predetermined value and if so setting them to be that predetermined value. This has not previously been done but leads to a more efficient solution.
Preferably, the model includes a model of friction. Static friction requires that the tangential force ft of magnitude less than or equal to the static friction coefficient μs times the normal force fn. The force ft due to dynamic friction has a magnitude equal to the dynamic friction coefficient μs times the normal force, and a direction given by ft vt≦0.
The dependence of the frictional force on the normal force can be replaced by a novel approximation in which the friction, dynamic or static, is not dependent on the normal force. This force then corresponds to a simple bounded multiplier, i.e. a force that can have up to a predetermined value. Thus the force exactly fits the model used in any event in which the constraint forces Lagrange multipliers have maximum values; friction in the model is equivalent to another bounded constraint force. Thus making this approximation substantially simplifies the inclusion of friction in the model.
Accordingly, the method may include a model of friction in which the frictional force between a pair of objects is independent of the normal force between the objects.
The frictional force between each pair of objects may be modelled as a bounded constraint force in which the constraint force acts in the plane of contact between the pair of objects to prevent sliding of one of the pair of objects over the other of the pair, wherein the constraint force is bounded to be not greater than a predetermined constant value to allow sliding of the objects over one another and thus include dynamic friction in the simulation.
In order to implement bounded constraint forces, the method may include the step of testing whether the constraint forces have a magnitude greater than a predetermined value and if so setting them to be that predetermined value.
The method may include a relaxation parameter y introduced to determine how exactly to satisfy the constraints.
The friction model taken leads to a symmetric positive definite linear complementarity problem, in which the only friction conditions are simple inequalities. This allows the use of the much more efficient Murty algorithm that the less useful Lemke algorithm.
From further aspects, this invention provides a computer program that is a computer game program, which game program may be recorded within a cartridge for a computer game machine; and a computer game programmed to generate a display by means of a computer program according to any preceding claim.



BRIEF DESCRIPTION OF THE DRAWINGS
Specific embodiments of the invention will now be described, purely by way of example, with reference to the accompanying drawings in which
FIG. 1 shows a flow diagram of a prior art implementation of the Murty algorithm,
FIG. 2 shows a computer running the present invention,
FIG. 3 shows a flow diagram of the implementation of the present invention,
FIG. 4 shows the friction pyramid,
FIG. 5 shows the box-friction model used to approximate to the friction pyramid,
FIG. 6 is a flow chart of the method including friction, and
FIG. 7 is a flow chart of the program according to the invention.
FIG. 8 is an illustration of a friction pyramid.



DETAILED DESCRIPTION OF THE INVENTION
The implementation of the invention that will be described includes a computer system 1 having a display 3, a memory 5 and a processor. The computer system has software 9 loaded into the computer memory to allow the computer system to display a simulation of the real physical world on the display 3. The display 3 may be a conventional computer display screen, for example an Liquid Crystal Display (LCD) screen or a Cathode Ray Tube (CRT) screen, or the display 3 may be a less conventional display type such as virtual reality goggles or multiple screens of a coin operated video game, of the type installed in public places.
A physical system which has n rigid bodies is modelled. The ith body has a mass mi, and a position vector p which has s seven coordinates, three to define the position of the rigid body and four being the Euler parameters of the body defining its orientation. Each body also has velocity vector v which has six coordinates, three being the three components of linear velocity and three being the three components of angular velocity, each relative to the inertial frame. Further details about the coordinates and the matrices used to convert between coordinates in the local reference frame and those in an inertial frame are given in sections 1 to 1.4 of Appendix 1.
The key point to note is that equations 1.36 and 1.37 of Appendix 1 define Newton's laws for a dynamical system in a form similar to equation (1), i.e.

M{dot over (v)}=fe+fc+fr  (9)

where M is the block diagonal matrix defined in equation 1.37 of appendix 1.

A rigid body dynamics problem then becomes equivalent to solving equation (7) subject to the dynamic constraints. This is carried out by numerical integration. The difficult part is calculating the constraint force.
The initial state of the system is set up in the computer memory, and includes the above parameters.
Constraints governing the rigid bodies may also be set up. The software 9 may include definitions of such constraints. An example of a constraint is a hinge between two rigid body elements so that the elements cannot move independently, the system contains constraint initialization routines for setting up such constraints. A separate routine is provided for each type of constraint; the routine is called, defining the one, two or three constrained elements and other information required to specify the constraint. For example, if there are two constrained elements in the form of two rigid bodies are joined by a ball and socket joint, the information required is the identity of the constrained elements and the position of the ball and socket joint. The constraint information is stored in the form of the Jacobian of constraint.
A simple example of a constraint would be a rigid floor at height zero in the model. The constraint function Φ(px, py, pz) is then chosen to be Φ(p)=pz, the conventional constraint Φ(p)≧0 then being a definition of the constraint.
The solution method used requires a Jacobian J of the constraint function Φ(p)—this is related to the more conventional Jacobian Jp of the function Φ(p) with respect to position by J=JpQ where Q is defined at equation 1.40 of Appendix 1.
The method used does not require storing the second derivative of the constraint function.
After the initial conditions and constraints are set up, the routine may be called to simply step forward in time by a predetermined time period. Indeed, the use of this simple program structure in which a routine is called with a matrix and outputs a like matrix of the results one time step forward is a significant advantage over prior approaches in which the movement forward in time has not been encapsulated in this way.
The way in which the system moves one step forward is based on simple Euler integration, i.e. calculating the final positions and velocities from the initial positions and velocities and the applied forces. Of course, some of the forces are the constraint forces that ensure that the system remains in accordance with the constraints; the way these are calculated will be described below.
Euler integration can be explicit, in which the integration is based on the values at the start of the step, or implicit in which the values at the end of the step are used. In the method of the invention, a semi-implicit approach is used in which the positions after the step are calculated using the positions at the start of the step and the velocities at the end of the step and the velocities are calculated explicitly. Put mathematically, the position p and velocity v at the (i+1)th step after a time h are given by

pi+1=pi+hvi+1  (10)

vi+1=vi+h·M−1·f  (11)

where M is the block diagonal matrix defined in Appendix 1 and f is the sum of the forces on the system, including the constraint forces to maintain the constraint. Note that the equations for the position variables are implicit and the equation for velocity explicit. Thus, the above equations need to be solved subject to the constraint equations.
Of course, in order to carry out the above calculation it is necessary to calculate f. The force f is made up of the external force plus the effects of the external torques plus the constraint force that keeps the system in accordance with the constraints. Thus, the constraint forces on the system must be calculated. Appendix 1 at 1.51 demonstrates how to do this for an explicit Euler scheme to calculate subject to the constraint Φ(p)=0. In the conventional scheme, the constraints are calculated by setting the second derivative of Φ to zero.
In the method according to the embodiment, however, this is not done and the first derivative




  
    ∂
    Φ
  
  
    ∂
    p
  




is set to zero.

The detail is set out in sections 1.5 to 1.6 of Appendix 1. The approach of using the velocity constraints rather than the second derivative of the constraint function has both advantages and disadvantage. The key disadvantage is that although this approach guarantees that the velocity constraints are satisfied it does not guarantee that the position constraints are.
The constraint equation may be given by

φo+Jp(p′−p)=0  (12)

where Jp is the Jacobian of the constraint forces based on the position, i.e.




  
    J
    p
  
  =
  
    
      
        ∂
        Φ
      
      
        ∂
        p
      
    
    .
  




This is related to the J actually calculated by J=JpQ.

Rather than satisfy this exactly, the parameter γ is introduced by amending the right hand side of equation (12) so that it reads

φo+Jp(P′−p)=(1−γ)φo  (13).

When γ=1 equation (13) becomes equivalent to equation (12). A value of 0.2 has been found suitable.
A solution for the forces is given at 1.5.5. of Appendix 1.
The result is:




  
    
      
        
          
            (
            
              
                J
                .
                
                  M
                  
                    -
                    1
                  
                
              
              ⁢
              
                J
                T
              
            
            )
          
          ⁢
          λ
        
        =
        
          
            
              
                -
                γ
              
              ⁢
              
                
              
              ⁢
              
                φ
                0
              
            
            
              h
              2
            
          
          -
          
            Jv
            h
          
          -
          
            
              JM
              
                -
                1
              
            
            ⁡
            
              (
              
                
                  f
                  c
                
                +
                
                  f
                  r
                
              
              )
            
          
        
      
    
    
      
        (
        14
        )
      
    
  




This is an equation in the form Ax+b=w and it can be solved by the algorithm presented below to find the vector γ.
The constraint force fc is then given by

fc=JTλ.  (15)

The constraint forces may then be fed into the integration step to compute the position of each object after the timestep.
It should be noted that the method uses bounded constraints. In other words, each element of the force is not allowed to become arbitrarily large as in previous methods but is bounded. This is simply implemented by testing to see if the elements of the force are larger than the bound and if so reducing the element to the bound.
The problem posed is not directly amenable to simple solution by the Murty algorithm. Rather, it has the slightly different structure of a boxed linear complementarity problem, as follows:

Az+q=w+−w. 

zi−1i≧0

w+i≧0

(zi−1i)w+i=0

(ui−zi≧0

w−i≧0

(ui−zi)w−i=0  (16)

The w+ and w− terms come from the integration step; they correspond to forces/accelerations from upper and lower boundaries respectively, the positions of the boundaries being given by u and 1. The z term corresponds to the differential of the velocity.
The result gives the constraint force which can be plugged into the integration.
The above formalism is equivalent to a mixed complementarity problem defined as




  
    
      
        
          
            
              [
              
                
                  
                    A
                  
                  
                    
                      -
                      I
                    
                  
                  
                    I
                  
                
                
                  
                    I
                  
                  
                    0
                  
                  
                    0
                  
                
                
                  
                    
                      -
                      I
                    
                  
                  
                    0
                  
                  
                    0
                  
                
              
              ]
            
            ⁡
            
              [
              
                
                  
                    
                      
                        
                          z
                        
                      
                      
                        
                          
                            w
                            +
                          
                        
                      
                    
                  
                
                
                  
                    
                      w
                      -
                    
                  
                
              
              ]
            
          
          +
          
            [
            
              
                
                  
                    
                      
                        q
                      
                    
                    
                      
                        
                          -
                          l
                        
                      
                    
                  
                
              
              
                
                  u
                
              
            
            ]
          
        
        =
        
          
            [
            
              
                
                  
                    
                      
                        0
                      
                    
                    
                      
                        μ
                      
                    
                  
                
              
              
                
                  v
                
              
            
            ]
          
          .
        
      
    
    
      
        (
        17
        )
      
    
  




This can be solved by partitioning the second set defined above into two sets, γ and ι, so that zj=1j for jεy and Zj=Uj for jει. Afterwards, the Murty algorithm is followed with a different definition of the complementarity point, namely,




  
    
      
        
          s
          j
        
        =
        
          {
          
            
              
                
                  min
                  ⁡
                  
                    (
                    
                      
                        
                          z
                          j
                        
                        -
                        
                          l
                          j
                        
                      
                      ,
                      
                        
                          u
                          j
                        
                        -
                        
                          z
                          j
                        
                      
                    
                    )
                  
                
              
              
                
                  ∀
                  
                    j
                    ∈
                    α
                  
                
              
            
            
              
                
                  (
                  
                    
                      
                        A
                        
                          γ
                          ⁢
                          
                            
                          
                          ⁢
                          α
                        
                      
                      ⁢
                      
                        z
                        α
                      
                    
                    -
                    
                      
                        A
                        γγ
                      
                      ⁢
                      
                        l
                        γ
                      
                    
                    -
                    
                      
                        A
                        γι
                      
                      ⁢
                      
                        u
                        l
                      
                    
                    +
                    
                      q
                      y
                    
                  
                  )
                
              
              
                
                  ∀
                  
                    j
                    ∈
                    γ
                  
                
              
            
            
              
                
                  -
                  
                    (
                    
                      
                        
                          A
                          
                            ι
                            ⁢
                            
                              
                            
                            ⁢
                            α
                          
                        
                        ⁢
                        
                          z
                          α
                        
                      
                      -
                      
                        
                          A
                          ιγ
                        
                        ⁢
                        
                          l
                          γ
                        
                      
                      -
                      
                        
                          A
                          ιι
                        
                        ⁢
                        
                          u
                          ι
                        
                      
                      +
                      
                        q
                        ι
                      
                    
                    )
                  
                
              
              
                
                  ∀
                  
                    j
                    ∈
                    ι
                  
                
              
            
          
        
      
    
    
      
        (
        18
        )
      
    
  




The least index rule is applied to the complementarity point as follows:

j=min arg(sj<0)

If jεα and zj<1j then remove j from α and put it in γ

If jεα and zj>uj then remove j from α and put it in ι

If jεγ add j to α and remove it from γ

If jε1 add j to α and remove it from ι

The loop is then repeated until there is no element Sj<0.

FIG. 3 sets out a flow chart of the Murty algorithm that is used to model the constraints. It is based on that of FIG. 1, with amendments to cope with the bounded parameters which are may be used to model friction.
This solution will be referred to as the Boxed LCP solution, which has been developed independently by the inventors.
The above solution may be refined by replacing the zeroes with a tolerance parameter −ε. This is similar to the Kostreva method, except here the parameter is not reduced but simply kept at a constant value say 10−3.
The parameters γ and ε may be chosen to model a compliant coupling between two of the rigid bodies. In this way springs and compliant bodies may be included in the model without any complexity.
Appendix 4 sets out how the parameters ε and γ already present in the model can be used to model stiff springs. Such parameters are very useful for modelling car suspensions, and the like. Thus, the use of the model provides the unexpected benefit of being usable not merely to ensure fitting of the constraints but can also be used to model stiff springs without any additional parameters or programming.
A key advantage provided by the approach selected is that it allows the inclusion of friction.
The friction constraint can thus be considered to be given by a cone which; if the contact force between two bodies is given by a force vector the values of the dynamic friction when the bodies slide is given by a cone in the three dimensional space of the force (FIG. 4). In the invention this cone is approximated by a four sided box, in other words friction is approximated by a model in which the transverse frictional force is not dependent on the normal force (FIG. 5).
The method thus works as follows:
Step 1: For each contact point, apply a non-penetration constraint and a static friction constraint.
Step 2: Estimate a normal force λi for each point
Step 3: At each point of contact, limit the Lagrange multipliers that enforce zero relative velocity to have a maximum value proportional to the normal force: i.e.

−μλi≦βij≦μλi 

Step 4: solve with the boxed Murty algorithm

Step 5: refine estimate of normal forces and repeat if required.

A flow chart of this procedure is presented in FIG. 6.
Surprisingly, such a crude model still gives good realistic results. The real advantage is that the model does not involve a combination of the Lagrange multipliers (constraint forces) as a constraint—the constraints are of the simple form ft≦a constant, whereas for more realistic model the upper bound on ft would depend on the normal force. This allows the use of a simpler algorithm as set out above. Indeed, the bounded constraint force has exactly the same bounded force as used for all of the constraints on the objects; accordingly adding friction does not add significantly to the difficulty of solving the problem.
Thus, the described embodiment allows much faster processing of the simulation.
A list of the routines used in the program implementing the embodiment, including the many routines to set up individual types of constraint, is provided in Appendix 2.
The program implementing the above is schematically shown in FIG. 7.
Firstly, a body data array containing the information about each rigid object, i.e. its position, orientation and mass is initialized. A constraint data array is likewise initialized containing parameters defining the constraints.
In the next step, the constraint data array is interrogated to create a list of Jacobians.
Then, a matrix A is calculated given by A=JM−1JT where M is the mass matrix as defined in Appendix 1 and J is the Jacobian. This step is done so that A is an upper triangle matrix (and symmetric).
The upper triangle elements of A are then copied to the lower, and the diagonal modified. Rotational force may be added to the bodies at this stage. The A matrix is then complete.
Next, A is factorized to find A−1 by Cholesky deposition.
An intermediate result rhs is then calculated as follows: Calculation of rhs, for each body:

tmp=0

tmp=M−1·fe 

tmp=tmp+v/h 

rhs=c/h−γ/h2−J·tmp

Then, rhs, A, A−1 and the lower and upper constraint vectors l and u are sent to a routine which calculates λ, the Lagrange multipliers, by solving equation (16) by these parameters by the boxed LCD method as described above.
Next, the resultant forces are calculated from λ and J, and the results passed to the semi-implicit integrator.
This outputs the velocity, force, position and orientation, in the form of the transformation matrix and orientation quaternion of each body.
Finally, a screen image is calculated displaying the objects in their new locations and this is displayed on the video display unit.
The method described works much faster than previously known methods. Accordingly, it becomes possible to more accurately simulate real time scenes, and provide an improved simulation that more rapidly and accurately simulates the real physical world.
APPENDIX 1
1 Rigid Body Dynamics
1.1 Definitions
Acronyms


    
    
        COM: Center of mass.
        IF: Inertial frame of reference for the whole system.

Notation α (any 3×1 vector) is relative to the IF.

        a′ is relative to the coordinate system of some rigid body. a and a′ are related by a unitary (rotational) transformation.
        Ii is the identity matrix of size i×i.
        0i is the zero matrix of size i×i.
        If a and b are 3×1 vectors then

a×b=âb  (1.1)

where

    
    






  
    
      
        
          a
          ^
        
        =
        
          
            
              [
              
                
                  
                    0
                  
                  
                    
                      -
                      
                        a
                        3
                      
                    
                  
                  
                    
                      a
                      2
                    
                  
                
                
                  
                    
                      a
                      3
                    
                  
                  
                    0
                  
                  
                    
                      -
                      
                        a
                        1
                      
                    
                  
                
                
                  
                    
                      -
                      
                        a
                        2
                      
                    
                  
                  
                    
                      a
                      1
                    
                  
                  
                    0
                  
                
              
              ]
            
            ⇒
            
              
                a
                ^
              
              ⁢
              a
            
          
          =
          0
        
      
    
    
      
        (
        1.2
        )
      
    
  
  
    
      
        
          
            
              d
              
                
              
            
            
              d
              p
            
          
          ⁢
          
            
          
          ⁢
          F
          ⁢
          
            
          
          ⁢
          
            (
            p
            )
          
        
        ≡
        
          
            
              ∇
              p
            
            ⁢
            
              
            
            ⁢
            F
          
          ⁢
          
            
          
          ⁢
          
            (
            p
            )
          
        
      
    
    
      
        (
        1.3
        )
      
    
  




1.2 Parameters of the Mechanical System


    
    
        There are n rigid bodies (“links”) numbered 1 . . . n. The coordinate system for each body has its origin at its center of mass.
        Link i has mass mi and 3×3 body-relative inertia tensor Hi.
        There are m constraint equations.
        p (7n×1) is the system position vector, which has the structure

p=[p1p2 . . . pn]T 

where

pi=[xiyiziqi1qi2qi3qi3]T  (1.5)

where (x,y,z) is the position of the center of mass and (q1, q2, q3, q4) is the orientation quaternion (Euter parameters). These are both relative to the IF.

        v (6n×1) is the system velocity vector, which has the structure

v=[v1v2 . . . vn]T  (1.6)

where

vi=[{dot over (x)}i{dot over (y)}iżi{dot over (ω)}i1{dot over (ω)}i2{dot over (ω)}i3]T  (1.7)

where ({dot over (x)}, {dot over (y)}, ż) is the velocity of the center of mass and (ω1 ω2 ω3) is the angular velocity (both relative to the IF).

Ri is the 3×3 unitary rotation matrix corresponding to the Euler parameters for body i.

    
    






  
    
      
        R
        =
        
          [
          
            
              
                
                  
                    
                      q
                      1
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      1
                    
                  
                  +
                  
                    
                      q
                      2
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      2
                    
                  
                  -
                  
                    
                      q
                      3
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      3
                    
                  
                  -
                  
                    
                      q
                      4
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      4
                    
                  
                
              
              
                
                  
                    2
                    ⁢
                    
                      q
                      2
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      3
                    
                  
                  -
                  
                    2
                    ⁢
                    
                      q
                      1
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      4
                    
                  
                
              
              
                
                  
                    2
                    ⁢
                    
                      q
                      1
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      3
                    
                  
                  +
                  
                    2
                    ⁢
                    
                      q
                      2
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      4
                    
                  
                
              
            
            
              
                
                  
                    2
                    ⁢
                    
                      q
                      2
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      3
                    
                  
                  +
                  
                    2
                    ⁢
                    
                      q
                      1
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      4
                    
                  
                
              
              
                
                  
                    
                      q
                      1
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      1
                    
                  
                  -
                  
                    
                      q
                      2
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      2
                    
                  
                  +
                  
                    
                      q
                      3
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      3
                    
                  
                  -
                  
                    
                      q
                      4
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      4
                    
                  
                
              
              
                
                  
                    
                      -
                      2
                    
                    ⁢
                    
                      q
                      1
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      2
                    
                  
                  +
                  
                    2
                    ⁢
                    
                      q
                      3
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      4
                    
                  
                
              
            
            
              
                
                  
                    
                      -
                      2
                    
                    ⁢
                    
                      q
                      1
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      3
                    
                  
                  +
                  
                    2
                    ⁢
                    
                      q
                      2
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      4
                    
                  
                
              
              
                
                  
                    2
                    ⁢
                    
                      q
                      1
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      2
                    
                  
                  +
                  
                    2
                    ⁢
                    
                      q
                      3
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      4
                    
                  
                
              
              
                
                  
                    
                      q
                      1
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      1
                    
                  
                  -
                  
                    
                      q
                      2
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      2
                    
                  
                  -
                  
                    
                      q
                      3
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      3
                    
                  
                  -
                  
                    
                      q
                      4
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      q
                      4
                    
                  
                
              
            
          
          ]
        
      
    
    
      
        (
        1.8
        )
      
    
  




Force vectors (such as fe, the external force) have the structure

f=[f1f2 . . . fn]T  (1.9)

where

f1=[fixfiyfizTixTiyTiz]T  (1.10)

where (fx, fy, fz) is the force applied to center of mass and (Tx, Ty, Tz) is the applied torque (both relative to the IF).

1.3 Equations of Motion for One Rigid Body
1.3.1 Coordinate Transformation
R is the unitary transformation matrix for link i (3×3). If a is a point in the IF and a′ is a point in the link frame then a=Ra′. Also note that

R−1=RT  (1.11)

The ith column vector of R is ui, so that





  
    
      
        R
        =
        
          [
          
            
              
                
                  
                    u
                    
                      .
                      .
                    
                  
                  .
                
                .
              
              i
            
            ⁢
            
              
                
                  
                    u
                    
                      .
                      .
                    
                  
                  .
                
                .
              
              2
            
            ⁢
            
              
                
                  
                    u
                    
                      .
                      .
                    
                  
                  .
                
                .
              
              3
            
          
          ]
        
      
    
    
      
        (
        1.12
        )
      
    
  




The ui vectors are axis unit vectors for the body.

1.3.2 Rotating Frame

If a is an IF point in the body relative to the center of mass then

{dot over (a)}=ω×a  (1.13)

Thus

{dot over (R)}=[{dot over (u)}1{dot over (u)}2{dot over (u)}3]  (1.14)

=[ω×uiω×u2ω×u3]  (1.15)

=[{circumflex over (ω)}u1{circumflex over (ω)}u2ω×u3]  (1.16)

={circumflex over (ω)}R  (1.17)

Note that {circumflex over (ω)}={circumflex over (ω)}T and {circle around (ω)}ω=0.

1.3.3 Angular Momentum

To start with we will consider just the rotational part of motion, and ignore the linear part (which is a lot easier to deal with). The definition of angular momentum L for a rigid body is





  
    
      
        L
        ≡
        
          
            ∑
            i
            
              
            
          
          ⁢
          
            
          
          ⁢
          
            
              q
              i
            
            ×
            
              M
              i
            
            ⁢
            
              
                q
                .
              
              i
            
          
        
      
    
    
      
        (
        1.18
        )
      
    
  




where qi are the positions of all particles in the rigid body (w. r. t. the IF) and Mi are their masses. Now,





  
    
      
        
          L
          .
        
        =
        
          
            ∑
            i
            
              
            
          
          ⁢
          
            
          
          ⁢
          
            
              
                d
                
                  
                
              
              
                d
                t
              
            
            ⁢
            
              
            
            ⁢
            
              (
              
                
                  q
                  i
                
                ×
                
                  M
                  i
                
                ⁢
                
                  
                
                ⁢
                
                  
                    q
                    .
                  
                  i
                
              
              )
            
          
        
      
    
    
      
        (
        1.19
        )
      
    
  








  
    
      
        =
        
          
            
              ∑
              i
              
                
              
            
            ⁢
            
              
                
                  q
                  .
                
                i
              
              ×
              
                M
                i
              
              ⁢
              
                
              
              ⁢
              
                
                  q
                  .
                
                i
              
            
          
          +
          
            
              ∑
              i
              
                
              
            
            ⁢
            
              
            
            ⁢
            
              
                q
                i
              
              ×
              
                M
                i
              
              ⁢
              
                
              
              ⁢
              
                
                  q
                   ̈
                
                i
              
            
          
        
      
    
    
      
        (
        1.20
        )
      
    
  
  
    
      
        =
        
          
            ∑
            i
            
              
            
          
          ⁢
          
            
          
          ⁢
          
            
              q
              i
            
            ×
            
              g
              i
            
          
        
      
    
    
      
        (
        1.21
        )
      
    
  




where gi is the force on particle i. Now,





  
    g
    i
  
  ≡
  
    
      
        ∑
        
          j
          ≠
          i
        
        
          
        
      
      ⁢
      
        
      
      ⁢
      
        g
        ij
      
    
    +
    
      G
      i
    
  




where gij is the force between qi and qj, and Gi is the external force on qi. It can be shown that if gij=−gji (as is the case according to Newton) then the total contribution to L from the gij is zero, so





  
    
      
        
          L
          .
        
        ≡
        
          
            ∑
            i
            
              
            
          
          ⁢
          
            
          
          ⁢
          
            
              q
              i
            
            ×
            
              G
              i
            
          
        
      
    
    
      
        (
        1.22
        )
      
    
  




Where the sum over i only includes those particle positions at which an external force is acting. Introducing the effect of torque is easy—all “pure” torques applied to the rigid body effectively works through the center of mass, so





  
    
      
        
          L
          .
        
        =
        
          
            
              ∑
              i
              
                
              
            
            ⁢
            
              
            
            ⁢
            
              
                q
                i
              
              ×
              
                G
                i
              
            
          
          +
          
            
              ∑
              i
              
                
              
            
            ⁢
            
              
            
            ⁢
            
              τ
              i
            
          
        
      
    
    
      
        (
        1.23
        )
      
    
  




The quantity {dot over (L)} is effectively the external rotational force applied to the body, which is usually a combination of joint constraint forces and forces external to the rigid body system.

1.3.4 The Link Between ω and L

It can be shown that

L′=Hω′  (1.24)

where L=RL′, ω=Rω′, and H is the 3×3 inertia tensor for this body. Thus

RTL=HRTω  (1.25)

L=RHRTω  (1.26)

from the chain rule





  
    
      
        
          L
          .
        
        =
        
          
            
              
                d
                
                  
                
              
              
                d
                t
              
            
            ⁢
            
              
            
            ⁢
            
              (
              
                RHR
                T
              
              )
            
            ⁢
            
              
            
            ⁢
            ω
          
          +
          
            
              RHR
              T
            
            ⁢
            
              
            
            ⁢
            ω
          
        
      
    
    
      
        (
        1.27
        )
      
    
  




=({dot over (R)}HRTω+RH{dot over (R)}Tω+RHRT{dot over (ω)})  (1.28)

{dot over (R)}Tω=({circumflex over (ω)}R)Tω  (1.29)

=RT{circumflex over (ω)}Tω  (1.30)

=0  (1.31)

so

RHRT{dot over (ω)}={dot over (L)}−{dot over (R)}HRTω  (1.32)

={dot over (L)}−{circumflex over (ω)}(RHRT)ω  (1.33)

={dot over (L)}−ω×((RHRT)ω)  (1.34)

or, schematically,

(inertia tensor in IF)×(angular acceleration)=(external force)+(coriolis force)  (1.35)

which is simply a statement of Newton's law.

1.4 Equations of Motion for a Rigid Body System
For n rigid bodies we simple combine the equations of motion into one matrix equation:

M{dot over (v)}=fe+fc+fr  (1.36)

where M is a block diagonal matrix (with 3×3 blocks):





  
    
      
        M
        =
        
          [
          
            
              
                
                  
                    m
                    1
                  
                  ⁢
                  
                    
                  
                  ⁢
                  
                    I
                    3
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
            
            
              
                
                  
                
              
              
                
                  
                    R
                    1
                  
                  ⁢
                  
                    
                  
                  ⁢
                  
                    H
                    1
                  
                  ⁢
                  
                    
                  
                  ⁢
                  
                    R
                    1
                    T
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
            
            
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                    m
                    2
                  
                  ⁢
                  
                    
                  
                  ⁢
                  
                    I
                    3
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
            
            
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                    R
                    2
                  
                  ⁢
                  
                    
                  
                  ⁢
                  
                    H
                    2
                  
                  ⁢
                  
                    
                  
                  ⁢
                  
                    R
                    2
                    T
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
            
            
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                ...
              
              
                
                  
                
              
              
                
                  
                
              
            
            
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                    m
                    n
                  
                  ⁢
                  
                    
                  
                  ⁢
                  
                    I
                    3
                  
                
              
              
                
                  
                
              
            
            
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                    R
                    n
                  
                  ⁢
                  
                    
                  
                  ⁢
                  
                    H
                    n
                  
                  ⁢
                  
                    
                  
                  ⁢
                  
                    R
                    n
                    T
                  
                
              
            
          
          ]
        
      
    
    
      
        (
        1.37
        )
      
    
  




and fe is the external force (applied from “outside” the rigid body system), fc is an undetermined constraint force, and fr is the rotational force:





  
    
      
        
          f
          r
        
        =
        
          [
          
            
              
                
                  
                    -
                    
                      ω
                      1
                    
                  
                  ×
                  
                    (
                    
                      
                        (
                        
                          
                            R
                            1
                          
                          ⁢
                          
                            
                          
                          ⁢
                          
                            H
                            1
                          
                          ⁢
                          
                            
                          
                          ⁢
                          
                            R
                            1
                            T
                          
                        
                        )
                      
                      ⁢
                      
                        
                      
                      ⁢
                      
                        ω
                        1
                      
                    
                    )
                  
                
              
            
            
              
                ⋮
              
            
            
              
                
                  
                    -
                    
                      ω
                      n
                    
                  
                  ×
                  
                    (
                    
                      
                        (
                        
                          
                            R
                            n
                          
                          ⁢
                          
                            
                          
                          ⁢
                          
                            H
                            n
                          
                          ⁢
                          
                            
                          
                          ⁢
                          
                            R
                            n
                            T
                          
                        
                        )
                      
                      ⁢
                      
                        
                      
                      ⁢
                      
                        ω
                        n
                      
                    
                    )
                  
                
              
            
          
          ]
        
      
    
    
      
        (
        1.38
        )
      
    
  




The state variables of the system are p and v. To integrate the system, the state derivatives must be known. The above equation allows us to determine {dot over (v)}, assuming that fc is known). {dot over (p)} is determined by applying a transformation that allows the angular velocity to be converted into Euler parameter derivatives

{dot over (p)}=Qv  (1.39)





  
    
      
        Q
        =
        
          [
          
            
              
                
                  I
                  3
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
            
            
              
                
                  
                
              
              
                
                  D
                  1
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
            
            
              
                
                  
                
              
              
                
                  
                
              
              
                
                  I
                  3
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
            
            
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  D
                  2
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
            
            
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                ...
              
              
                
                  
                
              
              
                
                  
                
              
            
            
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  I
                  3
                
              
              
                
                  
                
              
            
            
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  
                
              
              
                
                  D
                  n
                
              
            
          
          ]
        
      
    
    
      
        (
        1.40
        )
      
    
  




where





  
    
      
        
          D
          i
        
        =
        
          0.5
          ⁡
          
            [
            
              
                
                  
                    
                      -
                      
                        q
                        i
                        2
                      
                    
                    -
                    
                      q
                      i
                      3
                    
                    -
                    
                      q
                      i
                      4
                    
                  
                
              
              
                
                  
                    
                      +
                      
                        q
                        i
                        1
                      
                    
                    +
                    
                      q
                      i
                      4
                    
                    -
                    
                      q
                      i
                      3
                    
                  
                
              
              
                
                  
                    
                      -
                      
                        q
                        i
                        4
                      
                    
                    -
                    
                      q
                      i
                      1
                    
                    -
                    
                      q
                      i
                      2
                    
                  
                
              
              
                
                  
                    
                      +
                      
                        q
                        i
                        3
                      
                    
                    -
                    
                      q
                      i
                      2
                    
                    +
                    
                      q
                      i
                      1
                    
                  
                
              
            
            ]
          
        
      
    
    
      
        (
        1.41
        )
      
    
  




Note that DiTDi=I3/4.

1.5 Integration with Implicit Constraint Projection
1.5.1 Explicit Euler
The explicit Euler integration step is

new p=p*=p+hQv  (1.42)

new v=v*=v+hM−1(fe+fc+fr)  (1.43)

As the system evolves we want to compute fc such that the following constraint is satisfied:

φ(p)=0  (1.44)

Note that φ(p) has size m×1. Make a first order approximation to this:





  
    
      
        
          φ
          ⁢
          
            
          
          ⁢
          
            (
            p
            )
          
        
        =
        
          
            φ
            ⁢
            
              
            
            ⁢
            
              (
              
                p
                0
              
              )
            
          
          +
          
            
              
                
                  ∂
                  φ
                
                ⁢
                
                  
                
                ⁢
                
                  (
                  
                    p
                    0
                  
                  )
                
              
              
                ∂
                p
              
            
            ⁢
            
              
            
            ⁢
            
              (
              
                p
                -
                
                  p
                  0
                
              
              )
            
          
          ⁢
          
            
              +
              .
            
            -
          
          ⁢
          ...
        
      
    
    
      
        (
        1.45
        )
      
    
  
  
    
      
        ≈
        
          
            φ
            0
          
          +
          
            
              J
              p
            
            ⁢
            
              
            
            ⁢
            
              (
              
                p
                -
                
                  p
                  0
                
              
              )
            
          
        
      
    
    
      
        (
        1.46
        )
      
    
  




where po is the current position, and Jp is the m×7n Jacobian of the constraint function with respect to position (evaluated at p0). Find the first derivative of φ:





  
    
      
        
          φ
          ⁢
          
            
          
          ⁢
          
            (
            p
            )
          
        
        =
        
          
            
              ∂
              φ
            
            
              ∂
              p
            
          
          ·
          
            
              ∂
              p
            
            
              ∂
              t
            
          
        
      
    
    
      
        (
        1.47
        )
      
    
  
  
    
      
        =
        
          
            J
            p
          
          ⁢
          
            
          
          ⁢
          
            p
            .
          
        
      
    
    
      
        (
        1.48
        )
      
    
  
  
    
      
        =
        JpQv
      
    
    
      
        (
        1.49
        )
      
    
  
  
    
      
        =
        Jv
      
    
    
      
        (
        1.50
        )
      
    
  




Where J is the Jacobian of the constraint function with respect to velocity (J=JpQ). Find the second derivative of φ:





  
    
      
        
          φ
          ⁢
          
            
          
          ⁢
          
            (
            p
            )
          
        
        =
        
          
            
              
                ∂
                
                  
                
              
              
                ∂
                t
              
            
            ⁢
            
              
            
            ⁢
            
              
                
                  ∂
                  φ
                
                
                  ∂
                  p
                
              
              ·
              
                
                  ∂
                  p
                
                
                  ∂
                  t
                
              
            
          
          +
          
            
              
                
                  ∂
                  φ
                
                
                  ∂
                  p
                
              
              ·
              
                
                  ∂
                  
                    
                  
                
                
                  ∂
                  t
                
              
            
            ⁢
            
              
            
            ⁢
            
              
                ∂
                p
              
              
                ∂
                t
              
            
          
        
      
    
    
      
        (
        1.51
        )
      
    
  
  
    
      
        =
        
          
            
              
                ∂
                
                  
                
              
              
                ∂
                p
              
            
            ⁢
            
              
            
            ⁢
            
              
                ∂
                φ
              
              
                ∂
                p
              
            
            ⁢
            
              
            
            ⁢
            
              p
              .
            
            ⁢
            
              p
              .
            
          
          +
          
            
              J
              p
            
            ⁢
            
              p
               ̈
            
          
        
      
    
    
      
        (
        1.52
        )
      
    
  
  
    
      
        =
        
          
            
              
                ∂
                
                  
                     
                    2
                  
                  ⁢
                  φ
                
              
              
                ∂
                
                  p
                  2
                
              
            
            ⁢
            
              
            
            ⁢
            
              p
              .
            
            ⁢
            
              
            
            ⁢
            
              p
              .
            
          
          +
          
            J
            ⁢
            
              
            
            ⁢
            
              v
              .
            
          
        
      
    
    
      
        (
        1.53
        )
      
    
  
  
    
      
        =
        
          
            J
            ⁢
            
              
            
            ⁢
            
              v
              .
            
          
          -
          c
        
      
    
    
      
        (
        1.54
        )
      
    
  








  
    ∂
    
      
         
        2
      
      ⁢
      φ
    
  
  
    ∂
    
      p
      2
    
  




is a tensor quantity because φ is a vector.

Note that during simulation, J is the matrix that we actually calculate, not Jp. The constraint force fc is computed as

fc=JTλ  (1.55)

where λ is a vector of Lagrange multipliers. This ensures that the minimal amount of work is done to enforce the constraints. Compute fc such that φ(p);

J{dot over (v)}=c  (1.56)

JM−1(fc+JTλ+fr)=c  (1.57)

JM−1JTλ=c−JM−1(fe+fr)  (1.58)

which gives λ, from which fc and {dot over (v)} can be computed. Note that we can get the same result from solving





  
    
      
        
          
            [
            
              
                
                  
                    MJ
                    T
                  
                
              
              
                
                  
                    J
                    ⁢
                    
                      
                    
                    ⁢
                    0
                  
                
              
            
            ]
          
          ⁡
          
            [
            
              
                
                  
                    v
                    .
                  
                
              
              
                
                  λ
                
              
            
            ]
          
        
        =
        
          [
          
            
              
                
                  
                    f
                    e
                  
                  +
                  
                    f
                    r
                  
                
              
            
            
              
                c
              
            
          
          ]
        
      
    
    
      
        (
        1.59
        )
      
    
  




1.5.2 Implicit Euler

The implicit Euler integration step is

p*=p+hQ(p*)v*  (1.60)

v*=v+hM−1(p*)(fe(p*,v*)+(fc(p*,v*)+fr(p*,v*))  (1.61)

where the dependence of the right hand sides on the new state is made obvious. Performing this fully implicit update is rather difficult, even when using low order Rosenbrock methods, for reasons explained later.

1.5.3 Velocity Projection Method

Instead of trying to satisfy the acceleration constraint (φ=0) lets try to satisfy the velocity constraint (φ=0). From equation 1.50:

φ(p)=Jv=0  (1.62)

Substitute the Euler velocity update (equation 1.43) into this, and solve for λ;

J(v+hM−1(fe+fc+fr))=0  (1.62)





  
    
      
        
          
            (
            
              
                JM
                
                  -
                  1
                
              
              ⁢
              
                
              
              ⁢
              
                J
                T
              
            
            )
          
          ⁢
          
            
          
          ⁢
          λ
        
        =
        
          c
          -
          
            
              Jv
              h
            
            ⁢
            
              
            
            ⁢
            
              JM
              
                -
                1
              
            
            ⁢
            
              
            
            ⁢
            
              (
              
                
                  f
                  e
                
                +
                
                  f
                  r
                
              
              )
            
          
        
      
    
    
      
        (
        1.63
        )
      
    
  




which is similar to equation 1.58 except that the term −Jv/h has replaced c. fc and the new state are computed as before. This equation ensures that the velocity constraints are met at the new state, which reduces constraint violation compared to equation 1.58. It also means we do not have to have a separate impulse application step—collision constraints for example will automatically result in a zero penetration velocity.

A further advantage is that the value c does not have to be computed for each constraint. Although this thing is relatively inexpensive to compute, it is annoying to derive.

1.5.4 Position Projection as a Separate Step

Extra work must be done in the velocity projection method to ensure that the constraints don't come apart, because although the velocity constraints are guaranteed to be satisfied at the new state, the position constraints may not be. One option is Baumgarte stabilization. Another is direct position projection. We start with

φ0+JP(p−p0)=0  (1.65)

where φ0 and Jp are re-evaluated at the new position. Jp is usually not square so there are many possible p that satisfy this equation. We want to find the solution which minimizes |p−p0|. This is done by setting

P−P0=JpTδ  (1.66)

so that

φ0+JpJpTδ=0  (1.67)

δ=−(JpJpT−1φ0)  (1.68)

p←p0−(JpJpT−1φ0)  (1.69)

This corresponds to one iteration of a Newton method to find the root of φ(p)=(0). Multiple iterations can be performed to get perfect projection, but this will usually not be necessary.

1.5.5 Position Projection Method

We can take this process one step further by trying to satisfy the position constraint (φ(p)=(0) at the new timestep. To do this we must first express the Euler position update in terms of the new velocity rather than the current one, otherwise the new position will be independent of λ.

v*=v+hM−1(fe+JTλ+fr)  (1.70)

p*=p+hQv*  (1.71)

so that

p*=p+hQ(v+hM−1(fe+JTλ+fr)  (1.72)

The constraint equation we want to satisfy is (to first order)

φo+Jp(p*−p)=0  (1.73)

But actually to gain more flexibility we will introduce a parameter γ which controls how much we want to satisfy this constraint, so:

φ0+Jp(p*−p)=(1−γ)φ0  (1.74)

so if γ=0 we are assumed to already have the correct position and no position projection will be done (γ=1) will give us normal position projection). So

φ0+JphQ(v+hM−1(fe+JTλ+fr))=(1−γ)φ0  (1.75)

h2(JpQM−1JT)λ=−γφ0+hJpQ(v+hM−1(fe+fr))  (1.76)





  
    
      
        
          
            (
            
              
                JM
                
                  -
                  1
                
              
              ⁢
              
                
              
              ⁢
              
                J
                T
              
            
            )
          
          ⁢
          
            
          
          ⁢
          λ
        
        =
        
          
            -
            
              
                γ
                ⁢
                
                  
                
                ⁢
                
                  φ
                  0
                
              
              
                h
                2
              
            
          
          -
          
            Jv
            h
          
          -
          
            
          
          ⁢
          
            
              JM
              
                -
                1
              
            
            ⁢
            
              
            
            ⁢
            
              (
              
                
                  f
                  e
                
                +
                
                  f
                  r
                
              
              )
            
          
        
      
    
    
      
        (
        1.77
        )
      
    
  




which is similar to equation 1.64 except for the addition of the term −γφ0/h2. This equation ensures that the position constraints are met at the new state, which reduces constraint violation compared to equation 1.64. It also means that a separate position projection step is not required (position projection here is considerably less expensive).

1.5.6 Summary

For a standard Euler update, satisfy acceleration constraints by

(JM−1JT)λ=c−JM−1(fe+fr)  (1.78)

For a standard Euler update, satisfy velocity constraints by





  
    
      
        
          
            (
            
              
                JM
                
                  -
                  1
                
              
              ⁢
              
                
              
              ⁢
              
                J
                T
              
            
            )
          
          ⁢
          
            
          
          ⁢
          λ
        
        =
        
          
            -
            
              Jv
              h
            
          
          -
          
            
          
          ⁢
          
            
              JM
              
                -
                1
              
            
            ⁢
            
              
            
            ⁢
            
              (
              
                
                  f
                  e
                
                +
                
                  f
                  r
                
              
              )
            
          
        
      
    
    
      
        (
        1.79
        )
      
    
  




For a modified Euler update, satisfy position constraints by





  
    
      
        
          
            (
            
              
                JM
                
                  -
                  1
                
              
              ⁢
              
                
              
              ⁢
              
                J
                T
              
            
            )
          
          ⁢
          
            
          
          ⁢
          λ
        
        =
        
          
            -
            
              
                γ
                ⁢
                
                  
                
                ⁢
                
                  φ
                  0
                
              
              
                h
                2
              
            
          
          -
          
            Jv
            h
          
          -
          
            
          
          ⁢
          
            
              JM
              
                -
                1
              
            
            ⁢
            
              
            
            ⁢
            
              (
              
                
                  f
                  e
                
                +
                
                  f
                  r
                
              
              )
            
          
        
      
    
    
      
        (
        1.80
        )
      
    
  




2.0 Contact with Friction
The Coulomb friction model relates the normal and tangential force at each contact point between two bodies. The distinction is made between static and dynamic friction. With static friction there is no relative movement (sliding) between points that are in contact, and the following equation is satisfied:

|λt|≦μλn  (2.1)

where λn is the (scalar) normal force, λ1, is the 2×I tangential force, and μ is the static friction coefficient. With dynamic friction the two surfaces are in relative motion and a different equation applies:





  
    
      
        
          λ
          1
        
        =
        
          
            μ
            d
          
          ⁢
          
            
          
          ⁢
          
            λ
            n
          
          ⁢
          
            
          
          ⁢
          
            v
            n
          
        
      
    
    
      
        (
        2.2
        )
      
    
  




where v is the relative surface velocity vector (2×1) and μd is the dynamic friction coefficient. Equation 2.1 defines a friction cone, the boundary between static and dynamic friction.

With acceleration based friction models such as those used by Baraff the distinction between static and sliding friction is made explicitly, and care must be taken to ensure that switching between the two modes happens correctly. Baraff's acceleration based friction model generates an LCP problem that can sometimes be inconsistent, and even when it is consistent it is not guaranteed to be solvable by his Cottle-Dantzig based LCP method.

2.1 Velocity Based Model

The velocity based formulation of Anitescu and Potra resolves some of these problems. First, to allow a linear complementarity solution the friction cone is approximated by a friction pyramid (FIG. 8). The pyramid has s sides which are given by the 2×1 vectors c1 . . . cs. The conditions corresponding to equation 2.1 are:

∀i: ciT(λ1−μλnci)≦0  (2.3)

ciTλ1−μλnciTci≦0  (2.4)

−ciTλ1+μλn≧0  (2.5)

Each side of the friction pyramid has a scalar velocity residual α1. When the contact is sliding in a direction corresponding to side i, αi is positive. When the contact is within the friction pyramid, all the αi are 0. The equation of motion is





  
    
      
        J
        t
      
      ⁢
      v
    
    +
    
      
        ∑
        
          i
          =
          1
        
        s
      
      ⁢
      
        
          c
          i
        
        ⁢
        
          α
          i
        
      
    
  
  =
  0




where J1 extracts from the system velocity vector the 2×1 velocity vector in the contact plane. The full system for m contact points is (as a tableau):





  
    
      
        
          
            
              
                v
                ⁢
                
                  
                
                ⁢
                
                  λ
                  j
                
              
            
            
              
                
                  λ
                  
                    t
                    ⁢
                    
                      
                    
                    ⁢
                    1
                  
                
                ⁢
                
                  
                
                ⁢
                ...
                ⁢
                
                  
                
                ⁢
                
                  λ
                  tm
                
              
            
            
              
                
                  λ
                  
                    
                      t
                      ⁢
                      
                        
                      
                      ⁢
                      1
                    
                    ⁢
                    
                      
                    
                  
                
                ⁢
                ...
                ⁢
                
                  
                
                ⁢
                
                  λ
                  tm
                
              
            
            
              
                
                  α
                  
                    11
                    ⁢
                    
                      
                    
                  
                
                ⁢
                ...
                ⁢
                
                  
                
                ⁢
                
                  α
                  
                    1
                    ⁢
                    s
                  
                
              
            
            
              
                
                  α
                  
                    m
                    ⁢
                    
                      
                    
                    ⁢
                    1
                  
                
                ⁢
                
                  
                
                ⁢
                ...
                ⁢
                
                  
                
                ⁢
                
                  α
                  ms
                
              
            
          
          
            
              
                M
                -
                
                  
                    J
                    j
                    T
                  
                  ⁢
                  
                    J
                    j
                  
                
              
            
            
              
                
                  
                    -
                    
                      J
                      
                        
                          t
                          ⁢
                          
                            
                          
                          ⁢
                          1
                        
                        ⁢
                        
                          
                        
                      
                      T
                    
                  
                  ⁢
                  ...
                
                -
                
                  J
                  tm
                  T
                
              
            
            
              
                
                  
                    -
                    
                      J
                      
                        n
                        ⁢
                        
                          
                        
                        ⁢
                        1
                      
                      T
                    
                  
                  ⁢
                  
                    
                  
                  ⁢
                  ...
                
                -
                
                  J
                  nm
                  T
                
              
            
            
              
                
              
            
            
              
                
              
            
          
          
            
              
                
                  J
                  
                    t
                    ⁢
                    
                      
                    
                    ⁢
                    1
                  
                
                ⁢
                
                  
                
                ⁢
                ...
                ⁢
                
                  
                
                ⁢
                
                  J
                  tm
                
              
            
            
              
                
              
            
            
              
                
              
            
            
              
                
                  c
                  1
                
                ⁢
                
                  
                
                ⁢
                ...
                ⁢
                
                  
                
                ⁢
                
                  c
                  s
                
              
            
            
              
                
                  c
                  
                    1
                    ⁢
                    
                      
                    
                  
                
                ⁢
                ...
                ⁢
                
                  
                
                ⁢
                
                  c
                  s
                
              
            
          
          
            
              
                
                  J
                  
                    
                      n
                      ⁢
                      
                        
                      
                      ⁢
                      1
                    
                    ⁢
                    
                      
                    
                  
                
                ⁢
                ...
                ⁢
                
                  
                
                ⁢
                
                  J
                  nm
                
              
            
            
              
                
              
            
            
              
                
              
            
            
              
                
              
            
            
              
                
              
            
          
          
            
              
                
              
            
            
              
                
                  
                    -
                    
                      c
                      1
                      
                        T
                        ⁢
                        
                          
                        
                      
                    
                  
                  ⁢
                  ...
                
                -
                
                  c
                  s
                  T
                
              
            
            
              
                μ
                ⁢
                
                  
                
                ⁢
                ...
                ⁢
                
                  
                
                ⁢
                μ
              
            
            
              
                
              
            
            
              
                
              
            
          
          
            
              
                
              
            
            
              
                
                  
                    -
                    
                      c
                      1
                      T
                    
                  
                  ⁢
                  
                    
                  
                  ⁢
                  ...
                
                -
                
                  c
                  s
                  T
                
              
            
            
              
                μ
                ⁢
                
                  
                
                ⁢
                ...
                ⁢
                
                  
                
                ⁢
                μ
              
            
            
              
                
              
            
            
              
                
              
            
          
        
        ⁢
        
          
            
              =
            
          
          
            
              
                =
                
                  
                    
                      f
                      e
                    
                    +
                    
                      f
                      r
                    
                  
                  =
                  0
                
              
            
          
          
            
              
                =
                
                  
                    0
                    ⁢
                    
                      
                    
                    ⁢
                    ...
                  
                  =
                  0
                
              
            
          
          
            
              
                ≥
                
                  0
                  ⁢
                  
                    
                  
                  ⁢
                  ...
                
                >
                0
              
            
          
          
            
              
                ≥
                
                  0
                  ⁢
                  
                    
                  
                  ⁢
                  ...
                
                >
                0
              
            
          
          
            
              
                ≥
                
                  0
                  ⁢
                  
                    
                  
                  ⁢
                  ...
                
                >
                0
              
            
          
        
      
    
    
      
        (
        2.6
        )
      
    
  




where Jj is the joint Jacobian, Ju is the tangential velocity Jacobian for contact i and Jni is the normal velocity Jacobian for contact i. In matrix notation,





  
    
      
        
          H
          ⁡
          
            [
            
              
                
                  v
                
              
              
                
                  λ
                
              
              
                
                  α
                
              
            
            ]
          
        
        =
        q
      
    
    
      
        (
        2.7
        )
      
    
  




Note that the friction model is anisotropic, and that there is no separate value of μ for static and dynamic friction.

2.1.1 How to Implement this

Directly implementing an LCP solver for the above model is wasteful, as the matrix that needs to be factorized is larger than necessary (there are 3+s rows for every contact point). A method that uses only 3 rows per contact point will be described below. Consider the statement of standard LCP:

Ax=b+w  (2.8)

x≧0  (2.9)

w≧0  (2.10)

xiwi=0  (2.11)

The matrix A has size n×n. The Murty principal pivoting algorithm to solve this problem goes like this

    
    
        Set α={1, 2, . . . , n}. Here α is the set of indexes of “clamped” variables.
        Loop
        
            Solve for x: xa,
        
        
    
    






  
    =
    
      AA
      ⁢
      
        
      
      ⁢
      
        
          -
          1
        
        
          
            a
            _
          
          ⁢
          
            
          
          ⁢
          
            a
            _
          
        
      
      ⁢
      
        
      
      ⁢
      
        b
        
          a
          _
        
      
    
  
  ,
  
    
      x
      
        a
        _
      
    
    =
    0
  




    
    
        
        
            Find the residual w: w=Ax−b.
            If any elements of x are less than −ε, find the first one and add its index to α. Restart the loop.
            If any elements of w are less than −ε, find the first one and remove its index from α. Restart the loop.
            If we get to this point, we have a valid solution (x, w).

This procedure is guaranteed to terminate if A is a P matrix. The value ε is a small tolerance, typically 10−6. A variant of this procedure that is more computationally efficient in practical situations finds the value of x at each iteration by projecting from the totally unclamped solution A−1b. At each iteration we ask for the equation Qx=0 to be true, where Q is a matrix with a row for every index in α, with a single 1 in the position corresponding to the index (this is equivalent to asking for all the xα, to be zero).

The projection is done like this:

define Wα such that w=Wαwα  (2.12)

x=A−1b+A−1Wαwα  (2.13)

QA−1b+QA−1Wαwα=0 (as Qx=0)  (2.14)

wα=−(QA−1Wα)−1QA−1b  (2.15)

wα=−(QA−1Wα)−1Qx0  (2.16)

wā=0  (2.17)

where

x0=A−1b  (2.18)

The value of wα is substituted back to get x.

Now, in our case some of the variables in r correspond to normal forces (λn) and some variables correspond to tangential forces (λtx, λty). If the normal force conditions are violated (λn≦0) then the normal force can be projected back to zero as above. If the tangential force conditions are violated, the tangential forces must be projected back to the planes that make up the sides of the friction cone. This can be done by simply altering Q so that the appropriate plane equations appear on the rows of Q corresponding to the projected tangential variables.

This is easiest to achieve when we have a four sided friction pyramid. because then λtx and λty are effectively decoupled from each other. Also this means that a tangential variable will be projected to at most one plane at a time (if we had a many-sided friction volume then many planes could be involved in a projection and the situation becomes more complicated).

Here is the modified Murty algorithm:

        
        
        Make the matrices Qn, Qh and Q1 of size n×n such that Qnx=0 is the condition for all normal forces to be zero, Qhx=0 is the condition for all tangential forces to be clamped at the “high” plane, and Q1x=0 is the condition for all tangential forces to be clamped at the “low” plane.
        Set αn=αh=α1={ }. Here αn is the set of clamped normal forces, α1 and αh are the sets of clamped-low and clamped-high tangential indexes.
        Loop
        
            Set α=αn∩α1∩αh,
            Set Q:
        
        
    
    






  
    
      
        Q
        =
        
          [
          
            
              
                
                  Q
                  
                    
                      α
                      n
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      α
                      n
                    
                  
                  n
                
              
            
            
              
                
                  Q
                  
                    
                      α
                      1
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      α
                      1
                    
                  
                  1
                
              
            
            
              
                
                  Q
                  
                    
                      α
                      h
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      α
                      h
                    
                  
                  h
                
              
            
          
          ]
        
      
    
    
      
        (
        2.19
        )
      
    
  




    
    
        Solve for x:

wα=−(QA−1Wα)−1Qx0  (2.20)

wα=0  (2.21)

x=x0+A−1Wαwα  (2.22)
        
            If any normal elements of x are less than −ε, find the first one and add its index to αn. Restart the loop.
            If any elements of Q1x are less than −ε, find the first one and add its index to α1. Restart the loop.
            If any elements of Qhx are less than −ε, find the first one and add its index to αh. Restart the loop.
            If any normal elements of w are less than −ε, find the first one and remove its index from αn. Restart the loop.
            If any clamped-low tangential elements of w are less than −ε, find the first one and remove its index from αι. Restart the loop.
            If any clamped-high tangential elements of w are greater than C, find the first one and remove its index from αh. Restart the loop.
            If we get to this point, we have a valid solution (x, w).

This algorithm simulates what happens when the full problem in the previous section's tableau is solved with the standard Murty algorithm. This problem is guaranteed to have at least one solution, but unfortunately this algorithm is not guaranteed to find it. As μ gets larger the algorithm will start to cycle though the same index sets. In practice this rarely happens with physically realistic values of μ.

There are two possible ways to fix this problem. The first is to try and add heuristics to the projection process to restrict the possible combinations of clamped and unclamped states (see the matlab code for some examples). This has not been successful so far. The second is to detect when we come back on a previously encountered index set and then alter the rules for index swapping to prevent us following the same path. This could possibly be done preemptively at the level of individual friction pyramids before the global index set has repeated. This has not been tried yet, it is difficult in matlab.

There are several simple things that improve the speed of this algorithm. The first is finding a good starting index set, by applying the switching condition to every single index in one go. In fact this procedure may be followed for several iterations to improve performance, although it must be eventually abandoned for the one-at-a-time approach to ensure convergence. Also re-using index sets from the previous simulation iteration is useful. We need to investigate heuristics for choosing the switching index. For example, should we switch on the most or least violating index?

2.1.2 Tyres

Tyres have special friction requirements. When the tyre is under longitudinal force, the friction cone is actually scaled along one axis into a sort of friction ellipse. This can be simulated by altering the friction pyramid so that it is a kind of friction “diamond”, and ensuring that the tangential x and y axes are aligned with the wheel. Tyres also have the characteristics of slip and pneumatic trail, which I have not investigated yet.

        
        
    
    


3.0 More Implicit Integration
It is possible to perform implicit integration on only some state variables in a system. For example, we can divide up the variables like this:

yE=explicitly integrated variables  (3.1)

yI=implicitly integrated variables  (3.2)

yE=fE(yE,yI)  (3.3)

yI=fI(yE,yI)  (3.4)

And we can integrate like this (Euler first order):

yi+1E=yiE+hfE(yiE,yi1)  (3.5)

yi+11=yi1+hf1(yi+1E,yi+11)  (3.6)





  
    
      
        ≈
        
          
            y
            i
            1
          
          +
          
            
              
                h
                ⁡
                
                  [
                  
                    
                      1
                      -
                      
                        h
                        ⁢
                        
                          
                        
                        ⁢
                        
                          
                            ∂
                            
                              
                            
                          
                          
                            ∂
                            
                               
                              y
                            
                          
                        
                        ⁢
                        
                          
                        
                        ⁢
                        
                          f
                          1
                        
                        ⁢
                        
                          
                        
                        ⁢
                        
                          (
                          y
                          )
                        
                      
                    
                    ⁢
                    
                      |
                      
                        (
                        
                          
                            y
                            i
                            E
                          
                          ,
                          
                            y
                            i
                            l
                          
                        
                        )
                      
                    
                    -
                  
                  ]
                
              
              
                -
                1
              
            
            ⁢
            
              f
              1
            
            ⁢
            
              
            
            ⁢
            
              (
              
                
                  y
                  i
                  E
                
                ,
                
                  y
                  i
                  1
                
              
              )
            
          
        
      
    
    
      
        (
        3.7
        )
      
    
  




More useful in rigid body dynamics is being implicit in some inputs to a system. Consider the system:

{dot over (y)}=f(y,x)  (3.8)

x=g(y)  (3.9)

Here f is the rigid body system, y is its state variables, and x is the “external” forces presented to it. We can do implicit Euler integration only in the variables x as follows:

yi+1=yi+hf(yi,xi+1)  (3.10)

xi+1=g(yi+1)  (3.11)

if we make first order approximations for f and g:

f(y,x)≈f(yi,xi)+JF(x−xi)  (3.12)

g(y)≈g(yi)+JG(y−yi)  (3.13)

which gives





  
    
      
        
          y
          
            i
            +
            1
          
        
        =
        
          
            y
            i
          
          +
          
            
              
                (
                
                  
                    1
                    h
                  
                  -
                  
                    
                      J
                      F
                    
                    ⁢
                    
                      
                    
                    ⁢
                    
                      J
                      G
                    
                  
                
                )
              
              
                -
                1
              
            
            ⁢
            
              
            
            ⁢
            f
            ⁢
            
              
            
            ⁢
            
              (
              
                
                  y
                  i
                
                ,
                
                  x
                  i
                
              
              )
            
          
        
      
    
    
      
        (
        3.14
        )
      
    
  




If the external forces x are stiff, e.g. if they come from stiff springs, then this formulation will add extra stability to the system without the overhead of making the rigid body dynamics fully implicit.

To implement this scheme we need to compute JF and JG. Computing JG should be relatively easy. To compute JF first define the external force fc as

fc=Qx  (3.15)

then





  
    
      
        
          
            
              d
              
                
              
            
            
              d
              x
            
          
          ⁢
          
            
          
          ⁢
          f
          ⁢
          
            
          
          ⁢
          
            (
            .
            )
          
        
        =
        
          
            
              d
              
                
              
            
            
              d
              x
            
          
          ⁢
          
            
          
          ⁢
          
            v
            .
          
        
      
    
    
      
        (
        3.16
        )
      
    
  
  
    
      
        =
        
          
            (
            
              
                
                  
                    ∂
                    
                      
                    
                  
                  
                    ∂
                    
                      f
                      c
                    
                  
                
                ⁢
                
                  
                
                ⁢
                
                  v
                  .
                
              
              +
              
                
                  
                    ∂
                    
                      
                    
                  
                  
                    ∂
                    λ
                  
                
                ⁢
                
                  
                
                ⁢
                
                  
                    v
                    .
                  
                  ·
                  
                    
                      ∂
                      λ
                    
                    
                      ∂
                      
                        f
                        c
                      
                    
                  
                
              
            
            )
          
          ⁢
          
            
              ∂
              
                f
                c
              
            
            
              ∂
              x
            
          
        
      
    
    
      
        (
        3.17
        )
      
    
  
  
    
      
        =
        
          
            
              M
              
                -
                1
              
            
            ⁢
            
              
            
            ⁢
            Q
          
          -
          
            
              M
              
                -
                1
              
            
            ⁢
            
              
            
            ⁢
            
              J
              T
            
            ⁢
            
              
            
            ⁢
            
              
                (
                
                  
                    JM
                    
                      -
                      1
                    
                  
                  ⁢
                  
                    
                  
                  ⁢
                  
                    J
                    T
                  
                
                )
              
              
                -
                1
              
            
            ⁢
            
              
            
            ⁢
            
              JM
              
                -
                1
              
            
            ⁢
            
              
            
            ⁢
            Q
          
        
      
    
    
      
        (
        3.18
        )
      
    
  




which means that for the already factored system matrix (JM−1JT)−1 we must solve for nx extra right hand sides in the matrix JM−1 Q and then do a few other cheaper operations. Thus we should be selective about which external forces get the implicit treatment (stiff forces are the obvious candidates).

3.1 Modular Systems

The construction of modular systems and the application of the chain rule to propagate jacobian information for the purposes of implicit integration are well known in the art. An example is provided in the MATLAB reference manual.

APPENDIX 2
Contents
1. Conventions
2. Kea core


    
    
        2.1. Error Handling
        2.2. Math stuff
        
            2.2.1. Miscellaneous
            2.2.2. Vector and quaternion stuff
            2.2.3. Simple Matrix Stuff
        
        
        2.3. Rigid body dynamics core
        
            2.3.1. Rigid Body Structure
            2.3.2. Rigid Body Functions
            2.3.3. Abstract Constraint Functions
            2.3.4. Worlds

3. Constraints

        
        
        3.1. Contact
        3.2. Ball-and-socket
        3.3. Hinge
        3.4. Prismatic
        3.5. Steering hinge (1)

4. Collision

5. Utilities

        5.1. Kinematics
        
            5.1.1. Telescope Segment
            5.1.2. Keep Place

6. Other

        
        
        6.1. Constraints
        6.2. Dynamics scheduler
        6.3. More Functions
        6.4. Controller layer

1. Conventions

All matrices are stored in column-major order, i.e. stored by columns.

2. Kea Core

    
    


2.1. Error Handling
The following three functions are used internally within Kea to generate error and warning messages:


    
    
        void keaFatalError (char @msg, . . . );
        void keaDebug (char *msg, . . . );
        void keaWarning (char *msg, . . . );

Each of these functions has an interface identical to printf ( ), they take an error message string and a variable number of arguments. These functions can also be called by the user.

The default behavior of these functions is as follows:

        keaFatalError: print the error message to the console and exit.
        keaDebug: print the error message to the console, generate debugging information (e.g. dump core on a unix system) and exit.
        keaWarning: print the error message to the console, and continue running.

The default behavior can be overridden using these functions:

        typedef void keaErrorFunction (char *msg, . . . );
        void keaSetFatalErrorHandler (keaErrorFunction *fn);
        void keaSetDebugHandler (keaErrorFunction *fn);
        void keaSetWarningHandler (keaErrorFunction *fn);

It is useful to override the default behavior on systems without a text console (for example the PlayStation 2) or in shipping software. Note that the fatal error and debug calls are expected never to return, however they may perform exception handling using the C set-jmp ( )/longjmp ( )functions.

2.2. Math Stuff

The typedef keaFloat is used everywhere in Kea as the floating point type. The constant keaInfinity is defined to correspond to the system infinity value, or if that does not exist the largest representable floating point value.

2.2.1. Miscellaneous

void keaSetZero (int n, keaFloat *A);

        Set the first n elements of A to zero. For large arrays this will normally be faster than a simple for-loop.

2.2.2. Vector and Quaternion Stuff

keaFloat keaDot (keaFloat b [3], keaFloat c [3]);

        Return the inner product of b and c, assuming both are vectors of size 3.

void keaCross (keaFloat b [3], keyFloat c [3], keaFloat a [3]);

        Set a to the cross product of b and c. assuming both are vectors of size 3.

void keaPlaneSpace (keaFloat n[3], keaFloat a[3], keaFloat b [3]);

        Make unit length 3×1 vectors a and b such that together with the unit length 3×1 vector n they form an orthonormal basis. a and b span the plane that is normal to n, and a×b n. note that if n is not normalized then b will not be normalized either.

void keaQProduct (keaFloat p [4], keaFloat q [4], keaFloat r [4]);

        Multiplication of quaternions: set r=p*q.

void keaMakeUnitVector (keaFloat v [3]);

        Make the given size 3 vector unit length.

2.2.3. Simple Matrix Stuff

void keaMultiply (int p, int q, int r, keaFloat *B, keaFloat *C, keaFloat *A);

        Set A=B*C, where A is p*r, B is p*q, C is q*r.

void keaMultiplyT1 (int p, int c, int r, keaFloat *B, keaFloat *C, keaFloat *A);

        Set A=BT*C, where A is p*r, B is q*p, C is q*r.

2.3. Rigid Body Dynamics Core

2.3.1. Rigid Body Structure

The keaBody structure represents a rigid body in Kea. The coordinates of a rigid body (x, y, z) are always with respect to the body's center of mass.

There are a number of internal variables that are made public for ease of access. You should not modify these directly!

struct keaBody (

        void *userdata;
        keaFloat mass, I [9];
        keaFloat pos [3], qrot [4], vel [6];
        keaFloat R[9];
        . . . other internal stuff . . .

)

The body's mass parameters are mass and I, a 3×3 symmetric inertia tensor matrix. The body's state variables are

        pos, the center of mass (COM) position (x, y, z).
        qrot, the four quaternion rotation numbers.
        vel, the COM velocity (vx, vy, vz). and the angular velocity (wx, wy, wz).

R is the body 3×3 rotation matrix. It is a direct function of the qrot vector, and it is updated whenever qrot changes.

userdata is a variable that the user is free to change, this is never used by Kea.

2.3.2. Rigid Body Functions

All rigid body functions can be called at any time between simulation timesteps. void keaBodyInitialize (keaBody *body);

        Initialize the body. This must be the first function called on a new body.

void keaBodyAttach (keaBody *body, keaWorld *world);

        Attach the body to the world, making it an active part of that world. A body must be attached to a world before it can have constraints attached to it. If the body is already attached to another world it will be detached from that world first. If the body is already attached to the world then nothing will be done.

void keaBodyDetach (keaBody *body);

        Detach the body from whatever world it is currently attached to. Any constraints that are connected to this body are disconnected first. This does not destroy any body data, it simply prevents the body from being a part of the simulation. The body can be reattached at any time.

Now here are some functions to set the mass distribution of the body.

void keaBodyMakeSphere (keaBody *body, keaFloat mass, keaFloat radius);

        Set the mass parameters of this body to a sphere of the given mass and radius.

void keaBodyMakeBox (keaBody *body, keaFloat mass, keaFloat 1x, keaFloat 1y, keaFloat 1z);

        Set the mass parameters of this body to a box of the given mass and side lengths.

Now here are some functions to set the position, rotation, and velocity of the body. If you set values that are inconsistent with the current constraints then the simulation will attempt to correct this in subsequent time steps.

void keaBodvSetPosition (keaBody *body, keaFloat x, keaFloat y, keaFloat z);

void keaBodySetQuaternion (keaBody *body, keaFloat q1, keaFloat q2, keaFloat q3, keaFloat q4);

void keaBodySetLinearVelocity (keaBody *body, keaFloat dx, keaFloat dy, keaFloat dz);

void keaBodySetAngularVelocity (keaBody *body, keaFloat wx, keaFloat wy, keaFloat wz);

Now here are some functions to add forces to the body. After each time step the body is assumed to have zero force acting on it. These functions accumulate force on the body for the next time step.

void keaBodyAndForceAbs (keaBody *body, keaFloat fx, keaFloat fy, keaFloat fz);

void keaBodyAddForceRel (keaBody *body, keaFloat fx, keaFloat fy, keaFloat fz);

        Add a force, in the absolute (inertial) frame or the relative (body) frame, to the body's center of mass.

void keaBodyAddTorqueAbs

        (keaBody *body, keaFloat tx, keaFloat ty, keaFloat tz);

void keaBodyAddTorqueRel

        (keaBody *body, keaFloat tx, keaFloat ty, keaFloat tz);
        Add a torque, in the absolute (inertial) frame or the relative (body) frame, to the body's center of mass.

2.3.3. Abstract Constraint Functions

The keaConstraint structure represents a one, two or three body constraint. The constraint services described below are used by all the system joint types, and allow new constraint types to be created by the user. Note that all variables in the keaConstraint structure are internal and should not be accessed directly.

The following constraint functions can be called at any time in the simulation.

void keaConstraintInitialize (keaConstraint *c);

        Initialize the constraint. This must be the first function called on a new constraint.

void keaConstraintAttach (keaConstraint *c, keaWorld *world);

        Attach the constraint to the given world, making it an active part of that world. If the constraint is attached to another world, it will be detached from that world first. If the constraint is already attached to the world then nothing will be done.

void keaConstraintDetach (keaConstraint *c);

        Detach the constraint from whatever world it is currently attached to. This does not destroy any constraint data, it simply prevents the constraint from being a part of the simulation. The constraint can be re-attached at any time.

void keaConstraintSetBodies (keaConstraint *c, keaBody *b1, keaBody *b2, keaBody *b3);

        This set the bodies that the constraint attaches. The constraint must have been attached to a world, and the bodies must be in the same world.

keaConstraintDefine (keaConstraint *c, int num_ce, keaGetInfoFn *getinfo, keaStartStepFn

        *startstep);
        Sets the behavior of the constraint. This is only called to define new constraint types. num_ce is the number of constraint equations. getinfo and startstep are pointers to functions that implement the constraint behavior. getinfo gets information about this constraint for the current state of the constrained bodies. startstep is called automatically at the start of each timestep, it can set some auxiliary state-based data (such as joint angles) which the user can read. If you change the state of the constraint or the bodies which it connects then you may call this function yourself to update that data. Arguments to the getinfo function are provided in a structure rather than being passed directly, to allow for future expansion without having to rewrite all the constraint code. The getinfo function is free to ignore any of the arguments in this structure, except for the essential ‘J’. Each matrix/vector here has num_ce rows to fill in.

struct keaConstraintInfo (

        keaFloat *J[3];
        int rowskip;
        keaFloat *c;
        keaFloat *xi;
        keaFloat *lower, *upper;
        keaFloat *slipfactor;

);

typedef void keaGetInfoFn (keaConstraintInfo *);

The structure members are:

        J: Up to 3 pointers to Jacobian matrices that must be filled in. These matrices are stored by rows for convenience in constraint formation, in contrast to the usual Kea storage convention.
        rowskip: How much to jump by to go between J matrix rows.
        c: Vector in the constraint equation J*v=c.
        xi: Constraint error vector.
        lower, upper: Lagrange multiplier limits.
        slipfactor: First order constraint slipping vector.

2.3.4. Worlds

The keaWorld structure represents a simulated world in Kea. All members of this structure are internal and should not be accessed directly.

void keaWorldInitialize (keaWorld *world);

        Initialize a new world. After initialization, bodies and constraints can be attached to it.

void keaWorldDestroy (keaWorld *world);

        Destroy the given world. This simply detaches all bodies and constraints from the world, emptying it.

void keaWorldAddGravity (keaWorld *world, keaFloat gravity);

        Add a downwards (−z) gravity force to all bodies in the world. gravity is given in m/s2.

void keaWorldStep1 (keaWorld *world, keaFloat stepsize);

        Evolve the world forward in time by stepsize seconds. This uses an algorithm which will be fast, except for systems containing large articulated rigid body structures.

void keaWorldSetEpsilon (keaWorld *world, keaFloat x);

void keaWorldSetGamma (keaWorld *world, keaFloat x);

        These functions set world parameters. Increasing epsilon helps to combat numerical instability problems caused by degenerate systems. Increasing it will make the simulation more “non-physical” but may smooth over simulation glitches. The default value is 0.0001, increasing this to 0.1-1 will result in observable non-physical effects for worlds where that masses are on the order of 1 kg.
        Gamma is the projection constant which controls constraint stabilization. If the rigid body configuration has diverged from its constrained configuration, the next time step it will be brought a fraction ‘gamma’ of the way back to its correct configuration. Setting gamma to zero will result in articulated structures gradually coming apart. Setting gamma to one and higher will result in instabilities as the simulation tries to “overcorrect”. The default value is 0.2, and that is probably good enough for most simulations.

3. Constraints

To make a constraint, call its initialization functions, and then call the keaConstraintAttach ( ) and keaConstraintSetBodies ( ) functions.

3.1. Contact

The keaContact constraint is a collision contact between body 1 and body 2, or a collision contact between body 1 and the static environment. The keaContact structure has a number of public variables that must be set before the world step function is called:

struct keaContact (

        int mode;
        keaFloat cpos [3];
        keaFloat normal [3];
        keaFloat penetration;
        keaFloat maxforce;
        keaFloat a [3];
        keaFloat k1;
        . . . other internal stuff.

)

The fields of keaContact are:

        mode: The contact mode is one of the following constants:
        
            o: Zero friction.
            KEA_FRICTION-2D: Friction in two directions using automatically determined principal directions.
            KEA_FRICTION—1D: Friction in one direction (vector a).
            KEA_FRICTION_TYRE1: Friction in wheel drive direction (vector a) and first order slip in the lateral (other tangential) direction. The slip factor is the value k1. The following flags can be ORed with mode:
            KEA_FRICTION_BOX: Friction force magnitude along each principal direction is limited to maxforce.
        
        
        cpos: The contact position, in absolute coordinates. This must always be set.
        normal: The vector that is normal to the contact sliding plane, relative to body 1. This must have unit length. This must point ‘in’ to body 1, that is body 1 motion is allowed along the direction of +normal and body 2 motion is allowed along the direction of −normal. This must always be set.
        penetration: The penetration distances of the contact along the normal direction. This must always be set.
        max_force: The maximum frictional force that can be applied. This is set when the box friction flag is set.
        a: Parameter vector a. This is set in KEA_FRICTION—1D and KEA_FRICTION_TYRE1 modes. It must have unit length.
        k1: Parameter k1. This is set in KEA_FRICTION_TYRE1 mode.

The keaContact functions are:

void keaContactInitialize (keaContact *contact);

        Initialize a new contact.

3.2. Ball-and-Socket

The keaBSJoint structure represents a ball and socket joint.

void keaBSJointhnitialize (keaBSJoint *joint);

        Initialize a new ball and socket joint.

keaBSJointSetPosition (keaBSJoint *joint, keaFloat x, keaFloat y, keaFloat z);

        Set the joint position (in absolute coordinates). The constraint bodies must have been set first. and the positions of the joined bodies must have been set.

3.3. Hinge

The keaHinge structure represents a hinge joint. Note that the initial position of the hinge will be taken as the zero reference for angle determination.

void keaHingeInitialize (keaHinge *joint);

        Initialize a new hinge joint.

void keaHingeSetPosition

        (keaHinge *joint, keaFloat x, keaFloat y, keaFloat z);

void keaHingeSetAxis

        (keaHinge *joint, keaFloat x, keaFloat y, keaFloat z);
        Set the position of the hinge joint and its axis (in absolute coordinates). The joint bodies must have been set first, and the positions of the joined bodies must have been set.

void keaHingeSetNoLimits (keaHinge *joint);

void keaHingeSetLimits (keaHinge *joint, keaFloat low, keaFloat high);

        Set joint limits. low and high are in radians and are relative to the zero reference determined by the initial position of the hinge.

void keaHingeSetNoMotor (keaHinge *joint);

void keaHingeSetLimitedForceMotor (keaHinge *joint, keaFloat desired_velocity, keaFloat force limit);

        Sets a motor on the hinge.

keaFloat keaHingeGetAxisAbs (keaHinge *joint);

        Returns a pointer to a size 3 vector which gives the current hinge axis in absolute coordinates. keaFloat keaHingeGetAngle (keaHinge *joint);

keaFloat keaHingeGetAngleRate (keaHinge *joint);

        Returns the current hinge angle and angular velocity.

3.4. Prismatic

The keaPrism structure represents a prismatic joint.

void keaprismInitialize (keaprism *joint);

        Initialize a new prismatic joint.

void keaPrismSetAxis (keaprism *joint, keaFloat x, keaFloat y, keaFloat z);

        Set the sliding axis for the prismatic joint (in absolute coordinates). The joint bodies must have been set first, and the positions of the joined bodies must have been set.

void keaPrismSetNoLimits (keaprism *joint);

void keaPrismSetLimits (keaprism *joint, keaFloat low, keaFloat high);

        Set joint limits. low and high are in meters-position zero is when the centers of mass of the two bodies are as close to each other as possible.

void keaPrismSetNoMotor (keaprism *joint);

void keaPrismSetLimitedForceMotor (keaPrism *joint, keaFloat desired_velocity, keaFloat force limit);

        Sets a motor on the joint.

keaFloat *kea PrismGetAxisAbs (keaprism *joint);

        Returns a pointer to a size 3 vector which gives the current sliding axis in absolute coordinates.

keaFloat keaPrismGetPosition (keaprism *joint);

keaFloat keaPrismGetPositionRate (keaprism *joint);

        Returns the current sliding position and velocity. Position zero is when the centers of mass of the two bodies are as close to each other as possible.

3.5. Steering Hinge (1)

The keaSteeringHinge structure represents a steering hinge joint, which is a hinge that can be steered along a steering axis. This joint is useful on the front wheels of cars. Body 1 is the chassis and body 2 is the wheel. The connection point for the wheel body is its center of mass.

void keaSteeringHingeInitialize (keaSteeringHinge *joint);

        Initialize a new steering hinge joint.

void keaSteeringHingeSetSteeringAxis

        (keaSteeringHinge *joint, keaFloat x, keaFloat y, keaFloat z)

void keaSteeringHingeSetHingeAxis

        (keaSteeringHinge *joint, keaFloat x, keaFloat y, keaFloat z);
        These functions set the joint geometry, the steering axis and the hinge axis. The joint bodies must have been set first, and the positions of the joined bodies must have been set.

keaFloat *keaSteeringHingeGetHingeAxisAbs (keaSteeringHinge *joint);

keaFloat *keaSteeringHingeGetSteeringAxisAbs (keaSteeringHinge *joint);

        Returns pointers to size 3 vectors which give the current hinge and steering axes in absolute coordinates.

4. Collision

The Kea collision API is in a state of flux and will not be documented here yet. But check out the source file kea_collide. h if you want to know what the current story is.

5. Utilities

5.1. Kinematics

These functions allow for easy kinematic (rather than dynamic) placement of objects. They are specific to particular kinematic situations that the author has come across in the past, so not all common cases are covered here!

5.1.1. Telescope Segment

The keaKinematicTelescopeSegment structure and associated functions allow kinematic placement of an intermediate telescope segment (body 3) given the positions of the segments at the ends of the telescope (body I and body 2).

void keaKineTaticTelescopeSegmentInitialize (keaKinematicTelescopeSegment *k,

        keaFloat pos1 [3], keaFloat R [9], keaFloat pos2 [3], keaFloat pos3 [3]);
        Initialize a keaKinematicTelescopeSegment structure, giving the initial positions of the three bodies, and the rotation matrix of body 1.

void keaKinematicTelescopeSegmentGetPosition (keaKinematicTelescopeSegment *k, keaFloat pos1 [3], keaFloat R [9], keaFloa pos2 [3], keaFloat pos3 [3]);

        Given the positions of bodies 1 and the rotation matrix of body 1, return the position of body 3.

5.1.2. Keep Place

The keaKinematicKeepPlace structure and associated functions allow kinematic placement of a body (number 2) always in the same place relative to another body (number 1).

void keaKinematicKeepDlaceInitialize (keaKinematicKeepPlace *k, keaFloat pos1 [3], keaFloat R [9], keaFloat pos2 [3]);

        Initialize a keaKinematicKeepPlace structure, giving the initial positions of the bodies, and the rotation matrix of body 1.

void keaKinematicKeepPlaceGetPosition (keaKinematicKeepPlace *k, keaFloat pos1 [3], keaFloat R [9], keaFloat pos2 [3]);

        Given the position and rotation matrix of body 1, return the position of body 2.

6. Other

Some parts of the Kea API are not covered here, mostly those parts that haven't even been designed yet! Here are notes about what is missing.

6.1. Constraints

More constraint types are needed, especially the linear-1, angular-1 stuff from the SDK.

This will be trivial to add.

Document the functions that help implement user defined constraints, e.g. getting the bodies a constraint attaches.

For the contact constraint, we are currently missing:

        velocity dependent slip.
        the friction cone one-step-late approximation.
        keep the physical stuff in separate structure, i.e. separate the physical quantities from the geometrical ones.

Take a look at how well the keaConstraint functions operate on the joint types—is there an annoying type casting issue?

6.2. Dynamics Scheduler

This things hasn't even been designed yet. It could sit outside the Kea core, in which case we must check how to detach groups of RBs and constraints from the world without destroying the relationships between then, so they can be attached again later.

6.3. More Functions

Need more functions to compute rotations, e.g. to set body orientation. Use functions from glowworm. Open source.

Need more functions to add force to bodies, e.g. at a non-COM position.

Again, use the functions from glowworm. Open source.

6.4. Controller Layer

An open source dataflow based control layer, that allows us to easily implement ‘gadgets’ such as springs, PD controllers etc. Issues: data transfer (wiring), encapsulation of basic Kea structures, driving of the simulation. This should be quite easy.

    
    


APPENDIX 3
Stiff Spring Simulation
From Notes by Russell Smith
This describes how to implement a stiff spring in Kea using constraints. The key is to allow first order slip along the spring direction. Consider a one dimensional single particle system (mass m):

{dot over (p)}=v  (3.1)





  
    
      
        
          v
          .
        
        =
        
          
            l
            m
          
          ⁢
          
            (
            
              f
              +
              
                
                  J
                  T
                
                ⁢
                λ
              
            
            )
          
        
      
    
    
      
        (
        3.2
        )
      
    
  




where p is the point position, v is its velocity, f is the external force and λ is the constraint force (all scalars). We will enforce the constraint p=0 by setting J to 1. Thus from equation 1.80 in appendix 1, λ is computed as:





  
    
      
        
          
            (
            
              
                l
                m
              
              +
              ɛ
            
            )
          
          ⁢
          λ
        
        =
        
          
            -
            
              
                γ
                ⁢
                
                  
                
                ⁢
                p
              
              
                h
                2
              
            
          
          -
          
            v
            h
          
          -
          
            f
            m
          
        
      
    
    
      
        (
        3.3
        )
      
    
  




so the semi-implicit update for p and v is:





  
    
      
        
          v
          
            i
            +
            1
          
        
        =
        
          
            v
            i
          
          +
          
            
              h
              m
            
            ⁢
            
              (
              
                f
                +
                λ
              
              )
            
          
        
      
    
    
      
        (
        3.4
        )
      
    
  
  
    
      
        =
        
          
            v
            i
          
          +
          
            hf
            m
          
          +
          
            
              
                -
                
                  
                    γ
                    ⁢
                    
                      
                    
                    ⁢
                    p
                  
                  hm
                
              
              -
              
                v
                m
              
              -
              
                hf
                
                  m
                  2
                
              
            
            
              
                1
                m
              
              +
              ɛ
            
          
        
      
    
    
      
        (
        3.5
        )
      
    
  
  
    
      
        =
        
          
            v
            i
          
          +
          
            hf
            ⁡
            
              (
              
                ɛ
                
                  1
                  +
                  
                    m
                    ⁢
                    
                      
                    
                    ⁢
                    ɛ
                  
                
              
              )
            
          
          +
          
            
              
                -
                
                  
                    γ
                    ⁢
                    
                      
                    
                    ⁢
                    p
                  
                  h
                
              
              -
              v
            
            
              1
              +
              
                m
                ⁢
                
                  
                
                ⁢
                ɛ
              
            
          
        
      
    
    
      
        (
        3.6
        )
      
    
  
  
    
      
        =
        
          
            v
            i
          
          +
          
            f
            ⁡
            
              (
              
                
                  h
                  ⁢
                  
                    
                  
                  ⁢
                  ɛ
                
                
                  1
                  +
                  
                    m
                    ⁢
                    
                      
                    
                    ⁢
                    ɛ
                  
                
              
              )
            
          
          +
          
            v
            ⁡
            
              (
              
                
                  m
                  ⁢
                  
                    
                  
                  ⁢
                  ɛ
                
                
                  1
                  +
                  
                    m
                    ⁢
                    
                      
                    
                    ⁢
                    ɛ
                  
                
              
              )
            
          
          +
          
            p
            ⁡
            
              (
              
                
                  -
                  γ
                
                
                  h
                  ⁡
                  
                    (
                    
                      1
                      +
                      
                        m
                        ⁢
                        
                          
                        
                        ⁢
                        ɛ
                      
                    
                    )
                  
                
              
              )
            
          
        
      
    
    
      
        (
        3.7
        )
      
    
  




and

pi+1=pi+hvi+1  (3.8)

Now consider removing the constraint, adding an external spring and damper force, and integrating implicitly:





  
    
      
        
          f
          i
        
        =
        
          
            
              -
              
                k
                p
              
            
            ⁢
            
              p
              i
            
          
          -
          
            
              k
              d
            
            ⁢
            
              v
              i
            
          
        
      
    
    
      
        (
        3.9
        )
      
    
  
  
    
      
        λ
        =
        0
      
    
    
      
        (
        3.10
        )
      
    
  
  
    
      
        
          p
          
            i
            +
            1
          
        
        =
        
          
            p
            i
          
          +
          
            hv
            
              i
              +
              1
            
          
        
      
    
    
      
        (
        3.11
        )
      
    
  
  
    
      
        
          v
          
            i
            +
            1
          
        
        =
        
          
            v
            i
          
          +
          
            
              h
              m
            
            ⁢
            
              f
              
                i
                +
                1
              
            
          
        
      
    
    
      
        (
        3.12
        )
      
    
  
  
    
      
        =
        
          
            v
            i
          
          +
          
            
              h
              m
            
            ⁢
            
              (
              
                
                  
                    -
                    
                      k
                      p
                    
                  
                  ⁢
                  
                    p
                    
                      i
                      +
                      1
                    
                  
                
                -
                
                  
                    k
                    d
                  
                  ⁢
                  
                    v
                    
                      i
                      +
                      1
                    
                  
                
              
              )
            
          
        
      
    
    
      
        (
        3.13
        )
      
    
  
  
    
      
        =
        
          
            v
            i
          
          +
          
            
              h
              m
            
            ⁢
            
              (
              
                
                  -
                  
                    
                      k
                      p
                    
                    ⁡
                    
                      (
                      
                        
                          p
                          i
                        
                        +
                        
                          hv
                          
                            i
                            +
                            1
                          
                        
                      
                      )
                    
                  
                
                -
                
                  
                    k
                    d
                  
                  ⁢
                  
                    v
                    
                      i
                      +
                      1
                    
                  
                
              
              )
            
          
        
      
    
    
      
        (
        3.14
        )
      
    
  
  
    
      
        
          
            v
            
              i
              +
              1
            
          
          ⁡
          
            (
            
              1
              +
              
                
                  
                    
                      h
                      2
                    
                    ⁢
                    
                      k
                      p
                    
                  
                  +
                  
                    hk
                    d
                  
                
                m
              
            
            )
          
        
        =
        
          
            v
            i
          
          -
          
            
              
                hk
                p
              
              m
            
            ⁢
            
              p
              i
            
          
        
      
    
    
      
        (
        3.15
        )
      
    
  
  
    
      
        
          V
          
            i
            +
            1
          
        
        =
        
          
            
              v
              1
            
            ⁡
            
              (
              
                m
                
                  m
                  +
                  
                    
                      h
                      2
                    
                    ⁢
                    
                      k
                      p
                    
                  
                  +
                  
                    hk
                    d
                  
                
              
              )
            
          
          +
          
            
              p
              i
            
            ⁡
            
              (
              
                
                  -
                  
                    hk
                    p
                  
                
                
                  m
                  +
                  
                    
                      h
                      2
                    
                    ⁢
                    
                      k
                      p
                    
                  
                  +
                  
                    hk
                    d
                  
                
              
              )
            
          
        
      
    
    
      
        (
        3.16
        )
      
    
  




We can equate coefficients with equation (3.7) to see how to construct an “implicitly integrated spring” with a constraint (take f to be zero in equation (3.7)). First equate the coefficient on vj to find ε:





  
    
      
        
          
            m
            ⁢
            
              
            
            ⁢
            ɛ
          
          
            1
            +
            
              m
              ⁢
              
                
              
              ⁢
              ɛ
            
          
        
        =
        
          m
          
            m
            +
            
              
                h
                
                  2
                  ⁢
                  
                    
                  
                
              
              ⁢
              
                k
                p
              
            
            +
            
              hk
              d
            
          
        
      
    
    
      
        (
        3.17
        )
      
    
  
  
    
      
        
          ɛ
          ⁡
          
            (
            
              m
              +
              
                
                  h
                  2
                
                ⁢
                
                  k
                  p
                
              
              +
              
                hk
                d
              
            
            )
          
        
        =
        
          1
          +
          
            m
            ⁢
            
              
            
            ⁢
            ɛ
          
        
      
    
    
      
        (
        3.18
        )
      
    
  
  
    
      
        ɛ
        =
        
          1
          
            
              
                h
                2
              
              ⁢
              
                k
                p
              
            
            +
            
              hk
              d
            
          
        
      
    
    
      
        (
        3.19
        )
      
    
  




Then equate the coefficient on pi to find γ:





  
    
      
        
          
            -
            γ
          
          
            h
            ⁡
            
              (
              
                1
                +
                
                  m
                  ⁢
                  
                    
                  
                  ⁢
                  ɛ
                
              
              )
            
          
        
        =
        
          
            
              -
              
                hk
                p
              
            
            
              m
              +
              
                
                  h
                  2
                
                ⁢
                
                  k
                  p
                
              
              +
              
                hk
                d
              
            
          
          ⁢
          `
        
      
    
    
      
        (
        3.20
        )
      
    
  
  
    
      
        γ
        =
        
          
            
              h
              2
            
            ⁢
            
              
                k
                p
              
              ⁡
              
                (
                
                  1
                  +
                  
                    m
                    ⁢
                    
                      
                    
                    ⁢
                    ɛ
                  
                
                )
              
            
          
          
            m
            +
            
              
                h
                2
              
              ⁢
              
                k
                p
              
            
            +
            
              hk
              d
            
          
        
      
    
    
      
        (
        3.21
        )
      
    
  
  
    
      
        =
        
          
            hk
            p
          
          
            
              hk
              p
            
            +
            
              k
              d
            
          
        
      
    
    
      
        (
        3.22
        )
      
    
  




The parameters ε and γ are both dependent on the time step, but they are not dependent on the mass, so this constraint functions as a true spring. When ε is 0 this corresponds to a spring or damper constant of infinity, which results in an unmovable spring (complete constraint satisfaction).

APPENDIX 4
4.1 Linear Complementarity Problems
Given a real square n×n matrix M and a real n-dimensional vector q, the complementarity problem consists of finding the n-dimensional vectors z and w such that they satisfy the following conditions:

Mz+q=w  (4.26)

zi≧0 ∀iε(1, 2, . . . , n)  (4.27)

wi≧0∀iε(1, 2, . . . , n)  (4.28)

wizi≧0 ∀iε(1, 2, . . . , n)  (4.29)

This is fundamentally a combinatorial problem and various direct algorithms are available where the search goes through index sets α, β such that α⊂{1, 2, . . . , n}, β⊂{1, 2, . . . , n), α∩β=Ø, α∪β={1, 2, . . . , n}. The set α is the set of active variables and wi=0 ∀iεα while the set β is the set of free variables such that zi=0 ∀iεβ. The problem is then partitioned as:





  
    
      
        
          
            
              [
              
                
                  
                    
                      
                        M
                        αα
                      
                      ⁢
                      
                        M
                        αβ
                      
                    
                  
                
                
                  
                    
                      
                        M
                        βα
                      
                      ⁢
                      
                        M
                        ββ
                      
                    
                  
                
              
              ]
            
            ⁡
            
              [
              
                
                  
                    
                      z
                      α
                    
                  
                
                
                  
                    0
                  
                
              
              ]
            
          
          +
          
            [
            
              
                
                  
                    q
                    α
                  
                
              
              
                
                  
                    q
                    β
                  
                
              
            
            ]
          
        
        =
        
          [
          
            
              
                0
              
            
            
              
                
                  w
                  β
                
              
            
          
          ]
        
      
    
    
      
        (
        4.30
        )
      
    
  




where the subscripts α, β, are used to specify all indices that are in the sets α, β respectively. This is equivalent to the linear algebra problem:

Mααzα=−q  (4.31)

wβ=Mβαzα+qβ  (4.32)

which must be solved for zα while B is computed by direct substitution. The matrix Mαα is known as a principal submatrix of the matrix M. Various principal pivoting algorithms perform the same basic computation but take different strategies to revise the sets α and β from the computed complementarity point which is a vector s such that:





  
    
      
        si
        =
        
          {
          
            
              
                
                  z
                  i
                
              
              
                
                  ∀
                  
                    i
                    ⁢
                    
                      
                    
                    ⁢
                    ε
                    ⁢
                    
                      
                    
                    ⁢
                    α
                  
                
              
            
            
              
                
                  w
                  i
                
              
              
                
                  ∀
                  
                    i
                    ⁢
                    
                      
                    
                    ⁢
                    εβ
                  
                
              
            
          
        
      
    
    
      
        (
        4.33
        )
      
    
  




All principal pivot methods go through a sequence of sets αi, βi, i=1, 2, . . . until a solution is found i.e., si≧0 ∀iε{1, 2, . . . , n}.

4.2 The Murty Algorithm

One important such algorithm is the Murty Principal Pivot Method which is as follows:

1. Initialize (basically, any guess for α(0) is good), set i=0.
2. form principal submatrix Mα(i)α(i) and solve Mα(i)α(i)zα(i)=qα(i) 
3. compute s(i)=zα(i)+wβ(i) where wβ(i)=Mβ(i)α(i)zα(i) 
4. if sj(i)≧0 ∀ j we are done

    
    
        else
        
            find the smallest j such that sj(i)<0,
            if sj(i)=zj then α(i+1)=α(i)\{j}
            else α(i+1)=α(i)∪{j}
            i←i+1
            goto step 2

This algorithm is special in that it is stateless and can be started from any initial guess for α0. This method will work on any P matrix and in particular, any positive definite matrix.

The flowchart for this algorithm is given in FIG. I below.

4.3 The Kostreva Perturbation Method

In the case where the matrix M is positive semi-definite, the Murty principal pivot method can fail. This can arise in a multi-body simulation in the case where the constraints are degenerate, or if we work from the optimization matrix which leads to the form:

        
        
    
    






  
    
      
        
          
            
              [
              
                
                  
                    
                      N
                      -
                      
                        J
                        T
                      
                    
                  
                
                
                  
                    
                      J
                      ⁢
                      
                        
                      
                      ⁢
                      0
                    
                  
                
              
              ]
            
            ⁡
            
              [
              
                
                  
                    v
                  
                
                
                  
                    λ
                  
                
              
              ]
            
          
          +
          
            [
            
              
                
                  
                    -
                    F
                  
                
              
              
                
                  c
                
              
            
            ]
          
        
        =
        
          [
          
            
              
                0
              
            
            
              
                v
              
            
          
          ]
        
      
    
    
      
        (
        4.34
        )
      
    
  




λ≧0 v≧0  (4.35)

λ1v=0  (4.36)

for a multibody problem with inequality constraints. This matrix is positive semi-definite if the mass submatrix N is positive definite (which is always the case for physical systems). However, given any number ε>0, the matrix obtained from the original one by adding ε on the diagonal is always positive definite, i.e., the matrix:





  
    
      
        
          M
          ɛ
        
        =
        
          [
          
            
              
                
                  N
                  +
                  
                    ɛ
                    ⁢
                    
                      
                    
                    ⁢
                    
                      l
                      N
                    
                  
                
              
              
                
                  -
                  
                    J
                    T
                  
                
              
            
            
              
                J
              
              
                
                  ɛ
                  ⁢
                  
                    
                  
                  ⁢
                  
                    l
                    J
                  
                
              
            
          
          ]
        
      
    
    
      
        (
        4.37
        )
      
    
  




is positive definite, where 1N and iJ are identity matrices of appropriate sizes. Kostreva demonstrated that one can solve the sequence of complementarity problems defined by a sequence of positive numbers {n}n=1∞ such that ε→0 as n→∞ and find an answer to the positive semi-definite problem or find that it is infeasible (i.e., there is no answer). The algorithm is as follows;

1. Choose ε(0)>0 (typically 10−6)
2. Solve LCP(Mε(0), q)
3. set i←i+1. choose ε(i)<ε(i−1) 
4. Solve LCP(Mε(i), q)
5. if ∥z(i)−z(i−1)∥< to 1 Solve LCP(M,q) and finish
6. else if ∥z(i)−z(i−1)∥<max goto step 2
7. else error: problem is infeasible
We often set ε(0)=10−6 and ε(1)=0. This is often sufficient. In Kea, we even go further and set ε(0)=10−3 and stop and away i.e., we don't bother don't perturbation.
4.4 Boxed LCPs
The boxed LCP problem starts from the definition of the standard LCP and adds two new n-dimensional vectors 1 and u, lower and upper bounds respectively, such that 1i<ui ∀Iε{1, 2, . . . , n} and then the problem reads:

Mz+q=w+−w  (4.38)

zi−li≧0 ∀iε{1, 2, . . . , n}  (4.39)

w+i≧0 ∀iε{1, 2, . . . , n}  (4.40)

(zi−li)w+i=0 ∀iε{1, 2, . . . , n}  (4.41)

ui−zi≧0 ∀iε{1, 2, . . . , n}  (4.42)

w−i≧0 ∀iε{1, 2, . . . , n}  (4.43)

(ui−zi)w+i=0 ∀iε{1, 2, . . . , n}  (4.44)

This is equivalent to a much larger mixed linear complementarity problem defined as:





  
    
      
        
          
            
              [
              
                
                  
                    M
                  
                  
                    
                      -
                      ll
                    
                  
                
                
                  
                    l
                  
                  
                    
                      0
                      ⁢
                      
                        
                      
                      ⁢
                      0
                    
                  
                
              
              ]
            
            ⁡
            
              [
              
                
                  
                    z
                  
                
                
                  
                    
                      w
                      +
                    
                  
                
                
                  
                    
                      w
                      -
                    
                  
                
              
              ]
            
          
          +
          
            [
            
              
                
                  q
                
              
              
                
                  
                    -
                    l
                  
                
              
              
                
                  u
                
              
            
            ]
          
        
        =
        
          [
          
            
              
                0
              
            
            
              
                μ
              
            
            
              
                v
              
            
          
          ]
        
      
    
    
      
        (
        4.21
        )
      
    
  




μi,w+i≧0 μiw+i0 vi,w−i≧0 viw−i=0  (4.22)

This is precisely the sort of problem that the Kostreva procedure is designed to solve. However, because of the structure of the problem, there are simplifications that can be achieved on this. The idea is to partition the set 3 defined as above into two sets, γ and t so that zj=1j for jεy and Zj=uj for jεt. Afterwards, we follow the Murty algorithm but we change the definition of the complementarity point s as follows:




  
    
      
        
          s
          j
        
        =
        
          {
          
            
              
                
                  min
                  ⁡
                  
                    (
                    
                      
                        
                          z
                          j
                        
                        -
                        
                          1
                          j
                        
                      
                      ,
                      
                        
                          u
                          j
                        
                        -
                        
                          z
                          j
                        
                      
                    
                    )
                  
                
              
              
                
                  ∀
                  
                    j
                    ⁢
                    
                      
                    
                    ⁢
                    εα
                  
                
              
            
            
              
                
                  
                    (
                    
                      
                        
                          
                            M
                            γα
                          
                          ⁢
                          
                            z
                            α
                          
                        
                        -
                        
                          
                            M
                            γγ
                          
                          ⁢
                          
                            I
                            γ
                          
                        
                        -
                        
                          M
                          γ1
                        
                      
                      ,
                      
                        
                          u
                          1
                        
                        +
                        
                          q
                          γ
                        
                      
                    
                    )
                  
                  j
                
              
              
                
                  ∀
                  
                    j
                    ⁢
                    
                      
                    
                    ⁢
                    εγ
                  
                
              
            
            
              
                
                  -
                  
                    
                      (
                      
                        
                          
                            M
                            
                              1
                              ⁢
                              α
                            
                          
                          ⁢
                          
                            z
                            α
                          
                        
                        -
                        
                          
                            M
                            
                              1
                              ⁢
                              γ
                            
                          
                          ⁢
                          
                            l
                            γ
                          
                        
                        -
                        
                          
                            M
                            α
                          
                          ⁢
                          
                            u
                            1
                          
                        
                        +
                        
                          q
                          1
                        
                      
                      )
                    
                    j
                  
                
              
              
                
                  ∀
                  
                    j
                    ⁢
                    
                      
                    
                    ⁢
                    ε
                    ⁢
                    
                      
                    
                    ⁢
                    ι
                  
                
              
            
          
        
      
    
    
      
        (
        4.23
        )
      
    
  




and then, the least index rule is applied to this new complementarity point as follows:

j=min arg(sj<0)

if jεα(i) and zj(i)<1j then α(i+1)=α(i)\{j}γ(i+1)=γ(i)∪{j}, ι(i+1)=ι(i) 

if jεα(i) and zj(i))>μj then α(i+1)=α(i)/{j}, ι(i+1)=ι(i) ∪{j}, γ(i+1)=γi 

if jεγ(i) then α(i+1)=α(i)∪{j}, γ(i+1)=γ(i)\{j}, ι(i+1)=ι(i) 

if jεγ(i) then α(i+1)=α(i)∪{j}, t(i+1)=t(i)/{j}, γ(i+1)=γ(i) 

This modification of the standard Murty algorithm has not been traced in the literature by the authors yet.

4.5 Box Friction

The Coulomb friction model specifies the tangential forces at a point of contact in terms of the normal force at that point. The model specifies non-ideal constraint forces i.e., forces arising from constraints that do work on the system. This is in sharp contrast to typical ideal constraints which do no work on the system. Coulomb friction implements a maximum dissipation principle i.e., when the velocity at the point of contact is non-zero, the tangential force will be aligned against the velocity in a way that maximizes the work done; for isotropic friction, this means that the force of friction is directly opposed to the velocity of the contact point in the contact plane. One should note that Coulomb friction is a constitutive law i.e., an empirical model which is meant to summarize experimental evidence, in contrast with a fundamental law which can be derived from first principles. As such, “Coulomb's Law” is not so strict: the modeler has license to alter this model to ease computation provided the overall behaviour is still close to what is seen in an experiment.

The Coulomb friction model for a single point describes two states for the contact namely, sticking or sliding. In stick mode or static friction mode, the tangential force vector f1, which lies in a plane tangential to the normal force of contact, the force that prevents two objects from interpenetrating, must have smaller magnitude than the friction coefficient μs times the magnitude of the normal force fn i.e.,

∥ft∥=√{square root over (ft12+ft22)}≦μsfn  (4.24)

where ft1 and ft2 are components of the tangential force along two perpendicular directions in the tangential plane. In dynamic or sliding friction, the friction force must oppose the sliding velocity vector v1 and its magnitude is the kinetic friction coefficient μk times the normal force i.e.

∥ft∥=μkfn  (4.25)

ft·vt=ft1vt1+ft2vt2≦0  (4.26)

This model does not specify how to compute fn or ft at all but only states relationships between those quantities. These conditions specify that the tangential force should lie in the convex cone defined by the normal force, i.e.,

C(fn)={fn+ft| ∥ft∥<μsfn}  (4.27)

The first approximation we perform on this is to replace the friction cone by a friction pyramid, a simple case of polygonal cone approximation found in the literature. The idea is to introduce k linearly dependent basis vectors for the contact plane denoted d1, d2, . . . , and to represent the tangential friction force as:





  
    
      
        
          f
          t
        
        =
        
          
            ∑
            i
          
          ⁢
          
            
              d
              i
            
            ⁢
            
              β
              i
            
          
        
      
    
    
      
        (
        4.28
        )
      
    
  




and from this definition, we get an approximation to the friction cone known as the friction polyhedron:





  
    
      
        
          C
          
            (
            fn
            )
          
        
        =
        
          {
          
            
              
                f
                n
              
              +
              
                
                  ∑
                  i
                
                ⁢
                
                  
                    d
                    i
                  
                  ⁢
                  
                    β
                    i
                  
                
              
            
            ❘
            
              0
              <
              
                β
                i
              
              <
              
                
                  μ
                  s
                
                ⁢
                
                  
                  
                    f
                    n
                  
                  
                
              
            
          
          }
        
      
    
    
      
        (
        4.29
        )
      
    
  




The construction is shown for the friction pyramid in FIG. 4 using four basis vectors with equal angular spacing.

The final approximation is to neglect the dependence of the tangential friction forces on the normal force by specifying an independent maximum value for the coefficients, fmax. This gives a simple approximation off the friction cone that we refer to as a ‘box friction’ model.





  
    
      
        
          B
          
            (
            fn
            )
          
        
        =
        
          {
          
            
              
                f
                n
              
              +
              
                
                  ∑
                  i
                
                ⁢
                
                  
                    d
                    i
                  
                  ⁢
                  β
                
              
            
            |
            
              0
              <
              
                β
                i
              
              <
              
                f
                max
              
            
          
          }
        
      
    
    
      
        (
        4.30
        )
      
    
  




A box friction approximation to the friction cone is shown in FIG. 5.

## Claims

1. A computer-implemented method, using a computer having at least a processing unit and a memory, for determining motion of simulated objects each of which is represented by a data structure indicating characteristics of the simulated object, wherein each of at least some of the simulated objects have visual characteristics and simulated physical characteristics and wherein the motion of the simulated objects is to be in compliance with a physics model and is to be represented on a display device such that a viewer perceives the motion of the simulated objects in compliance with the physics model, the method comprising:
storing, in the memory, position parameters and velocity parameters, the position and velocity parameters defining an initial state of the physics model and the simulated objects;
storing, in the memory, constraint parameters defining at least one constraint function constraining the motion of the simulated objects according to the physics model, wherein the constraint parameters include at least one position constraint constraining the motion of the plurality of rigid bodies;
calculating, using the processor, the position and velocity parameters defining the state of the simulated objects after a predetermined time step based on rigid body dynamics, including:
a) carrying out a semi-implicit integration step subject to the constraints constraining the motion of the simulated objects, to determine the velocity after the step; and
b) determining constraint forces that act to keep the simulated objects in compliance with the constraints by ensuring that the first derivative of the constraint function is zero;

generating, using the processor, at the end of the predetermined time step, a screen image of a series of screen images for display on the display device, the screen image displaying a view of the simulated objects such that the viewer can perceive the motion of the simulated objects in compliance with the physics model, the screen image being based on the calculated position and velocity parameters defining the state of the simulated objects at the end of the predetermined time step; and
displaying the screen image on the display device;
wherein the physics model includes a model of friction in which the frictional force between a pair of objects is independent of a normal force between the objects for both elastic and inelastic collisions.

2. The method of claim 1, further comprising before the step of calculating in the processor the position and velocity parameters, a step of:
storing in the memory parameters defining a bounded constraint force to simulate the effects of friction in which the constraint force acts in the plane of contact between a pair of objects to prevent sliding of one of the pair of objects over the other of the pair, wherein the constraint force is bounded to be not greater than a predetermined constant value to allow sliding of the objects over one another and thus include dynamic friction in the simulation.

3. A method according to claim 1 wherein the calculating step includes carrying out the implicit integration by:
calculating the velocity parameters after the time step from the external forces, the constraint forces and the position and velocity parameters before the time step, and
calculating the position parameters after the time step from the external forces and constraint forces, the calculated velocity parameters after the time step and the position parameters before the time step.

4. A method according to claim 1 wherein the frictional force between a pair of objects is modelled as a bounded constraint force in which the constraint force acts in the plane of contact between the pair of objects to prevent sliding of one of the pair of objects over the other of the pair, wherein the constraint force is bounded to be not greater than a predetermined constant value to allow sliding of the objects over one another and thus include dynamic friction in the simulation.

5. A method according to claim 1 wherein the bounds on the constraint forces are included by a step of testing whether the constraint forces have a magnitude greater than a predetermined value and if so setting them to be that predetermined value.

6. A method of generating a display in a computer game according to claim 1.

7. A method according to claim 1, wherein the constraint forces are determined by solving the mixed linear complementarity problem using a Murty algorithm.

8. A method according to claim 5 wherein the linear complementarity problem is solved by solving the boxed LCP problem by the boxed Murty's method.

9. A method according to claim 7 wherein the constraints are required to be held to within a predetermined tolerance ε.

10. A method according to claim 9 where ε has a value between 10−4 and 10−2.

11. A method according to claim 1, in which the constraints are modelled using the first order expansion of the constraint function Φ, such that Φ=φo+Jp(p′−p)=(1−γ)φo, where γ is a relaxation parameter, φo is a constraint, Jp is the Jacobian of the constraint forces based on position, p′ is a position parameter after the predetermined timestep, and p is a position parameter before the predetermined timestep.

12. A method according to claim 11 wherein γ and a predetermined tolerance ε on the constraints are chosen to model a compliant coupling between two of the rigid bodies.

13. A computer readable medium storing a plurality of program code for controlling a data processor of a computer system, that when executed, cause the data processor to perform one or more tasks for simulating the motion of objects and displaying the results on a display screen, the computer system including a memory having memory locations for position parameters and for velocity parameters, the position and velocity parameters defining an initial state of a model system having a plurality of bodies, the plurality program code comprising:
program code for storing, in the memory, constraint parameters defining at least one constraint function constraining the motion of the bodies in the model system, wherein the constraint parameters include at least one position constraint constraining the motion of the plurality of rigid bodies;
program code for calculating the position and velocity parameters defining the state of the system after a predetermined time step based on rigid body dynamics, including:
a) program code for performing a semi-implicit integration step subject to the constraints constraining the motion of the simulated objects to determine the velocity after the step; and
b) program code for determining constraint forces that act to keep the system in compliance with the constraints by ensuring that the first derivative of the constraint function is zero; and

program code for generating, at the end of the predetermined time step, a screen image of a series of screen images for display on the display screen, the screen image displaying a view of the simulated objects such that the viewer can perceive the motion of the simulated objects in compliance with the physics model, the screen image being based on the calculated position and velocity parameters defining the state of the simulated objects at the end of the predetermined time step; and
program code for displaying the screen image on the display screen,
wherein the model system includes a model of friction in which the frictional force between a pair of objects is independent of a normal force between the objects for both elastic and inelastic collisions.

14. The computer readable medium of claim 13, wherein the data carrier is a cartridge for a computer game machine.

15. The computer readable medium of claim 13, wherein the semi-implicit integration step comprises:
program code for calculating the velocity parameters after the time step from external forces, the constraint forces and the position and velocity parameters before the time step, and
program code for calculating the position parameters after the time step from the external forces and constraint forces, the calculated velocity parameters after the time step and the position parameters before the time step each according to the constraints.

16. Apparatus for simulating the motion of objects and displaying the results on a display screen comprising:
a display screen,
a memory,
a processing unit,
and a computer program stored in the memory for causing the apparatus to carry out the steps of:
a) storing in the memory position and velocity parameters defining an initial state of a model system having a plurality of bodies,
b) storing in the memory parameters defining at least one constraint function constraining the motion of the bodies in the model system, wherein the at least one constraint function defines at least one position constraint constraining the motion of the plurality of rigid bodies,
c) storing in the memory parameters defining a bounded constraint force to simulate the effects of friction in which the constraint force acts in the plane of contact between a pair of objects to prevent sliding of one of the pair of objects over the other of the pair, wherein the constraint force is bounded to be not greater than a predetermined constant value to allow sliding of the objects over one another and thus include dynamic friction in the simulation, and wherein the bounded constraint force is independent of a normal force between the objects for both elastic and inelastic collisions;
d) calculating in the processor the position and velocity parameters defining the state of the system after a predetermined time step based on rigid body dynamics, including
i) carrying out a semi-implicit integration step subject to the constraints, to determine the velocity after the step; and
ii) determining the constraint forces that act to keep the system in compliance with the constraints by ensuring that the first derivative of the constraint function is zero; and

e) generating, at the end of the predetermined time step, a screen image of a series of screen images for display on the display screen, the screen image displaying a view of the simulated objects such that the viewer can perceive the motion of the simulated objects in compliance with the physics model, the screen image being based on the calculated position and velocity parameters defining the state of the simulated objects at the end of the predetermined time step, and
f) displaying, on the display screen, the screen image.

17. A computer-implemented method, using a computer, for simulating movement of a plurality of rigid bodies according to a physics model by calculating motion of the plurality of the rigid bodies the method comprising:
storing, into storage accessible to the computer, position parameters defining initial positions of a plurality of rigid bodies;
defining at least one position constraint constraining the motion of the plurality of rigid bodies, the at least one position constraint defining constraints on positions of the plurality of rigid bodies represented by the position parameters read from the storage;
providing the at least one position constraint to the computer;
determining a bounded constraint force, using the computer, wherein the bounded constraint force represents a frictional force between a pair of objects of the plurality of rigid bodies, the frictional force acting in a plane of contact between the pair of objects and wherein at least one reaction force is bounded to be not greater than a predetermined value relative to the frictional force, and wherein the bounded constraint force is independent of a normal force between the objects for both elastic and inelastic collisions;
calculating, using the computer, new position parameters for the plurality of rigid bodies using the computer, the new position parameters defining new positions of the plurality of rigid bodies after a predetermined time step, wherein the new position parameters depend on at least one reaction force that acts to keep the plurality of rigid bodies in compliance with the at least one position constraint, such that the new position parameters satisfy the at least one position constraint directly without an iterative error process; and
generating, using the processor, at the end of the predetermined time step, a screen image of a series of screen images for display on a display device, the screen image displaying a view of the simulated objects such that the viewer can perceive the motion of the simulated objects in compliance with the physics model, the screen image being based on the calculated position and velocity parameters defining the state of the simulated objects at the end of the predetermined time step; and
displaying the screen image on the display device.

18. The method according to claim 17, further comprising constraining at least one reaction force to not exceed a predetermined value by setting the at least one reaction force equal to the predetermined value if it would exceed the predetermined value.

19. The method according to claim 17, further comprising displaying an image of the plurality of rigid bodies at their calculated positions on a display.

20. The method according to claim 17, further comprising:
storing, into the storage, velocity parameters defining initial velocities of the plurality of rigid bodies;
defining at least one combined constraint constraining the motion of the plurality of rigid bodies, the at least one combined constraint defining constraints on velocities and positions of the plurality of rigid bodies represented by the velocity parameters and position parameters read from the storage;
providing the at least one combined constraint to the computer, and
wherein calculating the new position parameters depends on at least one reaction force that acts to keep the plurality of rigid bodies in compliance with the at least one position constraint and the at least one combined constraint.

21. The method according to claim 20, further comprising storing, into the storage, force parameters defining at least one initial force acting on the plurality of rigid bodies, and wherein the at least one constraint further includes constraints on the positions of the plurality of rigid bodies that depend upon the stored position parameters, the velocity parameters and the force parameters read from the storage.

22. The method according to claim 20, further comprising calculating new velocity parameters for the plurality of rigid bodies defining new velocities of the plurality of rigid bodies after the predetermined time step.

23. A computer system comprising a processor and instruction memory, the instruction memory comprising instructions that, when executed, calculate simulated movement of a plurality of rigid bodies according to a physics model from stored representations of the plurality of rigid bodies, the computer system comprising:
a data memory configured to store position parameters defining initial positions of the plurality of rigid bodies;
a constraint definer that, when executed, defines at least one position constraint constraining motion of the plurality of rigid bodies, the at least one position constraint defining constraints on positions of the plurality of rigid bodies represented by the stored position parameters read from the storage;
a friction modeler operable to determine a bounded constraint force, wherein the bounded constraint force represents a frictional force between a pair of objects of the plurality of rigid bodies, the frictional force acting in a plane of contact between the pair of objects, wherein at least one reaction force is bounded to be not greater than a predetermined value relative to the frictional force, and wherein the bounded constraint force is independent of a normal force between the objects for both elastic and inelastic collisions; and
a position parameter calculator that, when executed, calculates new position parameters for the plurality of rigid bodies defining new positions of the plurality of rigid bodies after a predetermined time step, wherein the new position parameters depend on at least one reaction force that acts to keep the plurality of rigid bodies in compliance with the at least one position constraint, such that the new position parameters satisfy the at least one position constraint directly without an iterative error process;
a image generator that when executed at the end of the predetermined time step, generates a screen image of a series of screen images for display on a display device, the screen image displaying a view of the simulated objects such that the viewer can perceive the motion of the simulated objects in compliance with the physics model, the screen image being based at least in part on the position parameters for the plurality of rigid bodies at the end of the predetermined time step;
wherein the processor is configured, when executed, to perform processing operations that implement the constraint definer and the position parameter calculator in accordance with computer executable instructions stored in the instruction memory.

24. Computer system according to claim 23, the computer executable instructions stored in the instruction memory further comprising instructions for determining a bounded constraint force, wherein the bounded constraint force represents a frictional force between a pair of objects of the plurality of rigid bodies, the frictional force acting in a plane of contact between the pair of objects and wherein at least one reaction force is bounded to be not greater than a predetermined value relative to the frictional force.

25. Computer system according to claim 23, the computer executable instructions stored in the instruction memory further comprising instructions for constraining at least one reaction force to not exceed a predetermined value by setting the at least one reaction force equal to the predetermined value if it would exceed the predetermined value.

26. Computer system according to claim 23, the computer executable instructions stored in the instruction memory further comprising instructions to generate a display of an image of the plurality of rigid bodies at their calculated positions on a display.

27. Computer system according to claim 23, wherein the data memory is further configured to store velocity parameters defining initial velocities of the plurality of rigid bodies, and wherein the constraint definer configured with the at least one constraint including at least one combined constraint constraining velocities and positions of the plurality of rigid bodies represented by the velocity parameters and position parameters stored in the data memory.

28. Computer system according to claim 27, wherein the data memory is further configured to store force parameters defining at least one initial force acting on the plurality of rigid bodies, and wherein the at least one constraint further includes constraints on the positions of the plurality of rigid bodies that depend upon the stored position parameters, the velocity parameters and the force parameters read from the data memory.

29. Computer system according to claim 27, further comprising a velocity parameter calculator configured to calculate new velocity parameters for the plurality of rigid bodies after the predetermined time step.

30. Computer system according to claim 23, further comprising a reaction force calculator configured to calculate at least one reaction force.

31. Computer system according to claim 30, wherein the reaction force calculator is configured, when executed, to calculate the at least one reaction force to not exceed a predetermined value by setting the at least one reaction force equal to the predetermined value if it would exceed the predetermined value.

32. Computer system according to claim 23, the computer executable instructions stored in the instruction memory further comprising instructions for defining at least one combined constraint constraining the motion of the plurality of rigid bodies, the at least one combined constraint defining constraints on velocities and positions of the plurality of rigid bodies represented by the velocity parameters and position parameters read from the storage, and for calculating new position parameters for the plurality of rigid bodies defining new positions of the plurality of rigid bodies after a predetermined time step, wherein the new position parameters depend on at least one reaction force that acts to keep the plurality of rigid bodies in compliance with the at least one position constraint and the at least one combined constraint.

33. Computer system according to claim 32, the computer executable instructions stored in the instruction memory further comprising instructions for storing force parameters defining at least one initial force acting on the plurality of rigid bodies and for implementing constraints on the positions of the plurality of rigid bodies that depend upon the stored position parameters, the velocity parameters and the force parameters read from the data memory.

34. Computer system according to claim 32, the computer executable instructions stored in the instruction memory further comprising instructions for calculating new velocity parameters for the plurality of rigid bodies defining new velocities of the plurality of rigid bodies after the predetermined time step.

35. Processing apparatus for calculating simulated movement of a plurality of rigid bodies according to a physics model, the processing apparatus comprising:
means for storing position parameters defining initial positions of a plurality of rigid bodies;
means for defining at least one position constraint constraining the motion of the plurality of rigid bodies, the at least one position constraint defining constraints on positions of the plurality of rigid bodies represented by the position parameters read from the means for storing;
means for determining a bounded constraint force, wherein the bounded constraint force represents a frictional force between a pair of objects of the plurality of rigid bodies, the frictional force acting in a plane of contact between the pair of objects, wherein at least one reaction force is bounded to be not greater than a predetermined value relative to the frictional force, and wherein the bounded constraint force is independent of a normal force between the objects for both elastic and inelastic collisions;
means for calculating new position parameters for the plurality of rigid bodies defining new positions of the plurality of rigid bodies after a predetermined time step, wherein the new position parameters depend on at least one reaction force that acts to keep the plurality of rigid bodies in compliance with the at least one position constraint, such that the new position parameters satisfy the at least one position constraint directly without an iterative error process; and
means for generating, at the end of the predetermined time step, a screen image of a series of screen images for display on a display device, the screen image displaying a view of the simulated objects such that the viewer can perceive the motion of the simulated objects in compliance with the physics model, the screen image being based on the calculated position and velocity parameters defining the state of the simulated objects at the end of the predetermined time step; and
means for displaying the screen image on the display device.

36. A data carrier tangibly embodying a program of machine readable instructions executable by a digital processing apparatus having stored thereon instructions that, when executed, calculate simulated movement of a plurality of rigid bodies according to a physics model, the program comprising:
program code for storing, into storage accessible to the computer, position parameters defining initial positions of a plurality of rigid bodies;
program code for defining at least one position constraint constraining the motion of the plurality of rigid bodies, the at least one position constraint defining constraints on positions of the plurality of rigid bodies represented by the position parameters read from the storage;
program code for determining a bounded constraint force, wherein the bounded constraint force represents a frictional force between a pair of objects of the plurality of rigid bodies, the frictional force acting in a plane of contact between the pair of objects, wherein at least one reaction force is bounded to be not greater than a predetermined value relative to the frictional force, and wherein the bounded constraint force between the pair of objects is independent of a normal force between the objects for both elastic and inelastic collisions;
program code for calculating new position parameters for the plurality of rigid bodies defining new positions of the plurality of rigid bodies after a predetermined time step, wherein the new position parameters depend on at least one reaction force that acts to keep the plurality of rigid bodies in compliance with the at least one position constraint, such that the new position parameters satisfy the at least one position constraint directly without an iterative error process; and
program code for generating, at the end of the predetermined time step, a screen image of a series of screen images for display on a display device, the screen image displaying a view of the simulated objects such that the viewer can perceive the motion of the simulated objects in compliance with the physics model, the screen image being based on the calculated position and velocity parameters defining the state of the simulated objects at the end of the predetermined time step; and
program code for displaying the screen image on the display device.

37. The data carrier tangibly embodying a program of machine readable instructions according to claim 36, further comprising program code for constraining at least one reaction force to not exceed a predetermined value by setting the at least one reaction force equal to the predetermined value if it would exceed the predetermined value.

38. The data carrier tangibly embodying a program of machine readable instructions according to claim 36, further comprising program code for displaying an image of the plurality of rigid bodies at their calculated positions on a display.

39. The data carrier tangibly embodying a program of machine readable instructions according to claim 36, further comprising:
program code for storing, into the storage, velocity parameters defining initial velocities of the plurality of rigid bodies;
program code for defining at least one combined constraint constraining the motion of the plurality of rigid bodies, the at least one combined constraint defining constraints on velocities and positions of the plurality of rigid bodies represented by the velocity parameters and position parameters read from the storage; and
program code for calculating new position parameters for the plurality of rigid bodies defining new positions of the plurality of rigid bodies after a predetermined time step, wherein the new position parameters depend on at least one reaction force that acts to keep the plurality of rigid bodies in compliance with the at least one position constraint and the at least one combined constraint.

40. The data carrier tangibly embodying a program of machine readable instructions according to claim 39, further comprising program code for storing, into the storage, force parameters defining at least one initial force acting on the plurality of rigid bodies, and the at least one constraint further includes constraints on the positions of the plurality of rigid bodies that depend upon the stored position parameters, the velocity parameters and the force parameters read from the storage.

41. The data carrier tangibly embodying a program of machine readable instructions according to claim 39, further comprising program code for calculating new velocity parameters for the plurality of rigid bodies defining new velocities of the plurality of rigid bodies after the predetermined time step.