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.

Description: IMAGE DISPLAY APPARATUS , METHOD AND PROGRAM BASED ON RIGID BODY DYNAMICS 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 Vi e {l , 2...n} (2) XiWi = 0 Vi e {l , 2...nj (4) where 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 α is a set of active variables for which W Ϊ = 0 and the second set β is a set of free variables for which z = 0. The problem is then partitioned as where α and β specify indices in the first and second sets respectively. This is equivalent to the linear algebra problem M z = -q act a a (6) w β = M a z + q 0 β βa a ^ β which must be solved for z while w is calculated by substitution. M aa 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 fi e a s . = (7! . Vi e β The methods go through a sequence of sets until a solution is found, i.e. until s ± ≥ 0 Vi e {l , 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/~ urty/book/LCPboo /inde .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 aa is formed and solved for z using equation (6) . Then s (l > = z a + W β is calculated, where W β = M βa z a (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. 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 f t of magnitude less than or equal to the static friction coefficient μ s times the normal force f n . The force f t due to dynamic friction has a magnitude equal to the dynamic friction coefficient μ s times the normal force, and a direction given by ft v t ≤ 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 γ 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 Figure 1 shows a flow diagram of a prior art implementation of the Murty algorithm, Figure 2 shows a computer running the present invention, Figure 3 shows a flow diagram of the implementation of the present invention, Figure 4 shows the friction pyramid, Figure 5 shows the box-friction model used to approximate to the friction pyramid, Figure 6 is a flow chart of the method including friction, and Figure 7 is a flow chart of the program according to the invention. DETAILED DESCRIPTION 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 i th body has a mass _n_ . , and a position vector p which has 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. Mv = f e +f c +f r (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. "^ e system contains constraint initialisation 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 Φ (p x ,p y ,Pz) is then chosen to be Φ (p) = p z ι 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 J p of the function Φ (p) with respect to position by J = J P Q 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 +l ) th step after a time h are given by Pi + ι = Pi + h v i +1 (10) v i +1 = Vi + h . M ' z . 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 — is set to zero. dp 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 where J p is the Jacobian of the constraint forces based on the position, i.e. J =— . This is related to the J actually dp calculated by J = J P Q. Rather than satisfy this exactly, the parameter γ is introduced by amending the right hand side of equation (5) so that it reads φ 0 + J p (p > - p) = (l -γ) φ 0 (13). When γ = 1 equation (6) becomes equivalent to equation (5) . 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- > J τ ]λ = ^-- ^ - JM- f e + f r ) (14) n n 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 f c is then given by f c = J T λ . (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- ( 16 ) l λ > 0 w +1 > 0 (z_ . l λ ) w +1 = 0 u x - z ∑ > 0 w.i > 0 (u -zX w. x = 0 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 I. 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 (17) This can be solved by partitioning the second set defined above into two sets, γ and i, so that z 3 = 1_ for j e γ and z 3 = U j for j € i . Afterwards, the Murty algorithm is followed with a different definition of the complementarity point, namely, The least index rule is applied to the complementarity point as follows: j = min arg (s_ < 0) If e a and z 3 < 1 D then remove j from a and put it in γ If j e a and z_ > U j then remove j from a and put it in i If j e γ add j to α and remove it from γ If j € add j to α and remove it from The loop is then repeated until there is no element s_ < 0. Figure 3 sets out a flow chart of the Murty algorithm that is used to model the constraints. It is based on that of Figure 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 (Figure 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 (Figure 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 < βi < μλ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 Figure 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 _f t < a constant, whereas for more realistic model the upper bound on f t 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 Figure 7. Firstly, a body data array containing the information about each rigid object, i.e. its position, orientation and mass is initialised. A constraint data array is likewise initialised 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 '1 J T 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 factorised 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 . f e tmp = tmp + v/h rhs = c/h - γ/h 2 - J.tmp Then, rhs, A, A '1 and the lower and upper constraint vectors 1 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 • a (any 3 x 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. • /, is the identity matrix of size / x / . • 0, is the zero matrix of size i x / . • If a and fc are 3 I vectors then a x b = ab ( 1.1 ) where d_ F(p) ≡ V p F(p) ( 1.3) dp 1.2 Parameters of the mechanical system • There are n rigid bodies ("links") numbered 1 ...» . The coordinate system for each body has its origin at its center of mass. • Link / has mass m t and 3 x 3 body-relative inertia tensor l . • There are in constraint equations. • p (In x 1 ) is the system position vector, which has the structure where i = [*, y, , q q qf qf] (1.5) where (v, , z) is the position of the center of mass and (q q 2 ,q ,q A ) is the orientation quaternion (Euler parameters.) These are both relative to the IF. • i' (6n x 1) is the system velocity vector, which has the structure where ■ *. > i, ω ,' ω 3] r (1.7) where (.{-, y, z) is the velocity of the center of mass and (ω ', ω 2 , ω 3 ) is the angular velocity (both relative to the IF). R, is the 3 x 3 unitary rotation matrix corresponding to the Euler parameters for body . q l q l + q q- - q q q Λ Λ 2q 2 q l -2q l q* 2q l q J + 2q 2 q i R = 2q 2 q l + 2q q 4 q l -q 2 q + q l q l - -2q q 2 + 2q ! 4 (1.8) -2q [ qX2q 2 q 4 2q*q + 2q 3 q q q - cf-q 2 - q 2 q^ + q 4 q 4 Force vectors (such as f c , the external force) have the structure /= [/,/_ ■•• /„]' (1.9) where /, = flflf Tf TjTf (1.10) where (f f v ,f z ) is the force applied to center of mass and (T x , T v , T z ) 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 x 3 ). If _. is a point in the IF and a' is a point in the link frame then a = Ra' . Also note that R- 1 = R τ (1.1 1) The ith column vector of R is .., , so that R = II , it-, it - ( 1.12) The u t 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 a - ω x a ( 1.13) Thus - I ω x it ω x ./ . ω x it- ( 1.15) ( 1.16) = ώR ( 1. 17) Note that ώ = -co ' and ώω = 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 where q t are the positions of all particles in the rigid body (w.r.t. the IF) and ( are their masses. Now, L = ∑ d (,, x Ml q,) ( 1. 19) ∑ i x M,<1, + ∑9, x M. , ( 1.20) = o Σ <7, * S, ( 1.21 ) where g, is the force on particle / ' . Now, ' G. ■ ∑»<•1 + J - i where g is the force between q t and q , and G, is the external force on q t . It can be shown that if g :J - -g (as is the case according to Newton) then the total contribution to L from the g is zero, so L = ∑9, x G, ( 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 = tf. x G. + τ, ( 1.23) The quantity 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 V = H(θ' (1.24) where __ = RU , ω = Rω' , and H is the 3 x 3 inertia tensor for this body. Thus R T L = HR τ ω (1.25) L = RHR τ ω (1.26) from the chain rule L = -(RHR τ )ω + RHR τ ώ ( 1.27) dt = (RHR r ω + RHR 7 ω + RHR r ώ) 0 -28) R τ ω = (&R) τ ω (1.29) = R τ ώ τ ω (1.30) = 0 (1.31) so RHR τ ώ = L - RHR τ ω (1.32) = L - ώ(RHR τ )o) ( 1.33) or, schematically. (inertia tensor in IF) x (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: Mv = f e +f c +f r (1-36) where is a block diagonal matrix (with 3 x 3 blocks): and f e is the external force (applied from "outside" the rigid body system), f c is an undetermined constraint force, and is the rotational force: The state variables of the system are /. and v. To integrate the system, the state derivatives must be known. The above equation allows us to determine v , assuming that f c is known). SUBSTITUTE SHEET (H'JLE 23) p is determined by applying a transformation that allows the angular velocity to be converted into Euler parameter derivatives: p = Qv (1.39) where Note that DjD, = / 3 /4 1.5 Integration with implicit constraint projection 1.5.1 Explicit Euler The explicit Euler integration step is new v = v* = v + hM ~ (f e +f c +/,) ( 1.43) As the system evolves we want to compute f c such that the following constraint is satisfied: φ (p) = 0 ( 1.44) Note that φ (/. ) has size m x \ . Make a first order approximation to this: <3φ (Pn) Φ (P) = Φ (/^> ) + -^- 2 -0 > -/ > <,) + " (1-45) where p 0 is the current position, and J is the ... x In Jacobian of the constraint function with respect to position (evaluated at p 0 ) Find the first derivative of φ <3φ dp < Q>) (147) dp dt (148) = J P Q > (149) Wheie J is the Jacobian of the constiamt function with lespect to velocity (J = J p Q ) Find the second dernative of φ _a ψ + δφ_ p ■ (P) = (151) dtdp dt dp dtdt d δφ (152) a pp + J " p ■pp + Jv (153) dp 2 = Jv — c (154) δ 2 φ op is a tensoi quantity because φ is a vector. Note that during simulation, J is the matnx that we actually calculate, not J . The constraint force f c is computed as f ( = 7 (155) wheie / is a vectoi of Lagiange muluplieis This ensuies that the minimal amount of woik is done to enforce the constraints Compute f c such that φ (p ) = 0 Jv = c (156) JM- (f e + J τ λ+f r ) = c (157) JM ~ J τ λ = c-JM~ (f e +f r ) (158) which gives λ , from which f c and v can be computed Note that we can get the same result from solving 1.5.2 Implicit Euler The implicit Euler integration step is p* = p + h Q(p*)v* ( 1.60) v* = v + hM- l (p*)(f e (p*, y*) +f c (p*, v*) +f r (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: φ ( . ) = Jv = o ( 1.62) Substitute the Euler velocity update (equation 1.43) into this, and solve for λ : J(v + /ιM-' ( _ + +/ . )) = 0 ( 1.63 ) (JM' J τ )λ = c - - JM- l (f e +f r ) (1.64) which is similar to equation 1.58 except that the term -Jv/h has replaced c. f c 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 Φ n + . „(/. - />„) = 0 ( 1.65) where φ 0 and J are re-evaluated at the new position. J p is usually not square so there are many possible p that satisfy this equation. We want to find the solution which minimizes . This is done by setting p - Po = J τ δ (1.66) so that Φo + Z^δ = 0 (1.67) P r- p 0 - J p j T )-^ 0 ( 1.69) This corresponds to one iteration of a Newton method to find the root of φ(/. ) = 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 (φ(/. ) = 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- i (f e + J τ λ +f r ) ( 1.70) p* = p + hQv* (1.71) so that P* = p + hQ(v + hM- t (f e + J τ λ +f r )) (1.72) The constraint equation we want to satisfy is (to first order) $ Q + J p (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: •)o + J p (p* -p) = ( l - γ)Φo ( 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 ^ ) + J p hO(v + hM-' {f c + J τ λ +/,.)) = ( l - γ)φ 0 ( 1.75) h (J p QM-'J τ )λ = - ^ 0 + hJ p Q(v + hM- \ (f e +f r )) (1 76) (JM ~ i J τ )λ = (f e +f,) ( 1 77) which is similar to equation 1 64 except for the addition of the teim -γφ 0 //. 2 This equation ensuies that the position constraints are met at the new state, which leduces constiamt violation compared to equation 1 64 It also means that a sepaiate position piojection step ι_, not lequn cd (position pi ejection heie is considei - abl\ less expensive) 1.5.6 Summar . Foi a standaid Euler update, satisfy acceleration constraints by (JM- l J τ )λ = c - JM- l (f e +f r ) (1 78) Foi a standard Euler update, satisfy velocity constraints by Foi a modified Euler update, satisfy position constraints by 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 |λ,| < μλ„ (2 1) where λ„ is the (scalar) normal force, λ, is the 2 x 1 tangential force, and μ is the static ftiction coefficient With dynamic friction the two surfaces are in relative motion and a different equation applies / , = μ — (2 2) where v is the relative surface velocity vector (2 χ l ) 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 (figure 2.1). The pyramid has s sides which are given by the 2 x 1 vectors <:, ...<: ■ _ . The conditions corresponding to equation 2.1 are: V : c ( - μλ„c,) < 0 (2.3) cjλ, - λ n c c l < 0 (2.4) -c r λ, + μλ„ > 0 (2.5) Each side of the friction pyramid has a scalar velocity residual α, . When the contact is sliding in a direction corresponding to side /, α, is positive. When the contact is within the friction pyramid, all the α, are 0. The equation of motion is J ι v + ∑ c , α , = 0 i = 1 Figure 2.1 : The approximated friction cone. where J, extracts from the system velocity vector the 2 x I velocity vector in the contact plane. The full system for in contact points is (as a tableau): (2.6) where J ■ is the joint Jacobian, J ti is the tangential velocity Jacobian for contact / and J ni is the normal velocity Jacobian for contact i. In matrix notation, H = 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: Λ.v = b + w (2.8) Λ- > 0 (2.9) H' ≥ O (2.10) XiW; = 0 (2.1 1 ) The matrix A has size n x . The Murty principal pivoting algorithm to solve this problem goes like this • Set α = { 1, 2, ..., .. } . Here α is the set of indexes of "clamped" variables. • Loop - Solve for x : x a = Λ = L/. δ , .v u = 0. - Find the residual w : w - Ax - b . - If any elements of .v 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 undamped solution A ~ b . At each iteration we ask for the equation Q.x = 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 a to be zero). The projection is done like this: define \V U such that w = W a w a (2.12) x = Λ- ' /7 + . - | W α u α (2.13) QA- l b + QA ~ l W a w a = 0 (ΆS QX = 0) (2.14) w a = -(QA- i W (t )- l QA- i b (2.15) »v α = -(QA- l W a )- l Qx 0 (2.16) w a = 0 (2.17) where Λ- 0 = A ~[ b (2.18) The value of u α is substituted back to get x. Now, in our case some of the variables in .v correspond to normal forces (λ„ ) and some variables correspond to tangential forces (λ, v , λ π . ). If the normal force conditions are violated (λ„ < 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 λ n and λ M 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 Q", Q h and Q 1 of size n x n such that Q"x = 0 is the condition for all normal forces to be zero, Q h x = 0 is the condition for all tangential forces to be clamped at the "high" plane, and Q'x = 0 is the condition for all tangential forces to be clamped at the "low" plane. • Set a,, = a = a, = { } . Here a„ is the set of clamped normal forces, α, and α Λ are the sets of clamped-low and clamped-high tangential indexes. • Loop - Set α α„ r. α, n α /( - Set β 0" Q = Q' (2.19) Q h Solve for = XQX l w a y' Qx 0 (2.20) = 0 (2.21 ) x = x Q + A Λ W α w α (2.22) - If any normal elements of x are less than -ε , find the first one and add its index to α„ . Restart the loop. - If any elements of Q' x are less than -ε , find the first one and add its index to α, . Restart the loop. - If any elements of Q h _ are less than -ε , find the first one and add its index to α Λ . Restart the loop. - If any normal elements of w are less than - , find the first one and remove its index from α,, . 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 ε , 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 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 undamped 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: y E = explicitly integrated variables (3.1 ) }" implicitly integrated variables (3.2) y' = f'(y E , y') (3.4) And we can integrate like this (Euler first order): ) + ι = > + V £ 0 ..v/) (3.5) y. + , = y! + hf'(.vf + > • !+ . ) (3.6) More useful in rigid body dynamics is being implicit in some inputs to a system. Consider the system: y = /(y, x) (3.8) x = g(y) (3.9) Here / 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: >', + . = y, + hf( „ x l + ,) - (3.10) -v, + , = £( V, + 1 ) ( 3- 1 1 ) if we make first order approximations for/ and g: f(y, χ ) f(y„ χ ,)+J F ( χ - χ ,) (3.12) 5(v)~^(.v,) + c ( -y,) (3.13) which gives If the external forces .v 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 J F and J G . Computing J G should be relatively easy. To compute J F , first define the external force f e as /, = Qx (3-15) then *■> = ( 3.16 ) = (Lv + Lv.? )l d < (3.17) e dλ dfjdx = M- l Q-M- l J T (JM- l J T )- JM- i Q (3.18) which means that for the already factored system matrix (JM ~l J 7 )- 1 we must solve for π v extra right hand sides in the matrix JM '] 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: vo d 5Ξ F_:alError { char "s ;, . . . ) ; void keaDeoug ( char *msg, ■ . . ) ; void keaWa ning ( char *msg, . . . ) ; Each of these functions has an interface identical to print f ( ) , 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: • keaFataiΞrror : print the error message to the console and exit. • kea Debu : print the error message to the console, generate debugging information (e.g. dump core on a unix system) and exit. • keaWarnir.g : print the error message to the console, and continue running. The default behavior can be overridden using these functions: typedef voic keaErrorFunctior. ( char *msg , . . . ) ; void keaSet atalErrorHandler ( keaErrorFunctior. * fn ) ; voiα keaS stZaougHandler ( keaΞrrort ' unction * fn ) ; void keaSet ' .. ' arnιngHandler ( ke≤ΞrrorFunction * 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 ( ) /long^ p ( ) functions. 2.2. Math stuff The typedef keaFloat is used everywhere in Kea as the floating point type. The constant keainf lmty 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 vo d keaSet Zero ( mt n, keaFloar *A) ; Set the fust n elements of A to zeio. For large arrays this will normally be faster than a simple for-loop. 2.2.2. Vector and quaternion stuff keaFloat kea ot (keaFloat b[3], -.eaFloat c[3]), Return the inner pioduct of b and c, assuming both are vectors of size 3. void keaCioss (keaFloat b[3], keaFloat c[3], keaFloat a[3]); Set a to the cioss pioduct of b and c. assuming both aie vectoi s ol size 3 voiα _ea?._ eSoace (keaFloat [ 2 , keaFloat a[3], keaFloat b[3]); Make unit length 3x1 vectoi a and b such that togethei with the unit length 3x1 vector n they form an oithonormal basis a and b span the plane that is normal to n, and a x b = n note that if n is not noimahzed then b will not be normalized either void keaQProouct (keaFloat p[4], keaFloat q[4], keaFloat r [ 4 ] ) ; Multiplication of quaternions: set r = p * q. void eaMake. itVector (keaFloat v[3]); Make the given size 3 vector unit length. 2.2.3. Simple matrix stuff void keaMuIt_ply (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 keaMult_olyTl (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 'i 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 1 struct keaBocy { void *usercata; keaFloat mass, I [9]; KeaFloat DCS [ 3] , qrot [ ] , vel [ 6] , keaFloat R r 9] , .other internal stuff... The body's mass parameters are mass and I, a 3x3 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 3x3 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 keaBodylnitialize ( keaBody *body) ; Initialize the body. This must be the first function called on a new body. void keaBody.-.ttach ( keaBody *body, kea orld * orld) ; 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 keaBodyletach ( 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 re- attached at any time. Now here are some functions to set the mass distribution of the body. void keaBodyl.akeSphere ( 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 lx, keaFloat ly, keaFloat I z ) ; 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 keaBoαySetPosition (keaBody *body, keaFloat x, keaFloat y, keaFloat z); void keaBodySetQuatermon (keaBody "tody, keaFloat ql, KeaFloat q2, keaFloat q3, keaFloat q4 ) ; void keaBoaySetLmearVelocity (keaBody -πody, keaFloat dx, KeaFloat αy, keaFloat dz); void keaBoαySetAngularVelocit ( -.eaBoαx τ:dy, keaFloat w.\, .eaFloat v,y, keaFloat vz); Now here aie some functions to add forces to the body. After each time step the body is assumed to ha\e zero force acting on it. These functions accumulate force on the body for the next time step. void keaBoαyAαdForceAbs (keaBody 'body, keaFloat fx, KeaFloat fy, keaFloat fz); void keaBocyAαdForceRel (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 keaBoαyAcdTorqueAbs (keaBody "cody, keaFloat tx, KeaFloat ty, keaFloat tz); void keaBocyAαdTorqueRel (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 keaConstramt structure represents a one, two or three body constraint. The constraint services descπbed 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 keaConstramt structure are internal and should not be accessed directly. The following constraint functions can be called at any time in the simulation. void keaConstramtlnitialize ( keaConstramt *c) ; Initialize the constraint. This must be the first function called on a new constraint. void keaCorstraintAttach (keaConstramt *c, keaWorld *world) ; Attach the constraint to the given world, making it an active part of that world If the constiamt is attached to another woild, it will be detached from that world first If the constiamt is already attached to the world then nothing will be done void keaCo-tt raintDetach ( keaConst ramt *c ) , Detach the constraint from whatever world it is cuirently attached to This does not destroy an \ constraint data it simply pievents the constraint from being a part of the simulation The constiamt can be le-attached at any time old keaCc- ;- raιntSetBo ιes ( e=_Cons tr__nt * c , keaBody "ol , KeaBoα / *b2 , KeaBody * 3 ^ , 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 κeaConstr __" t De ine ( keaConstramt *c, nt num_ce , keaGet lnfoFn *getιnfo, 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 getmfo and startstep are pointers to function that implement the constraint behavior getmro 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 w hich it connects then you may call this function yourself to update that data Aιgument_ to the αetmfo function aie piovided in a stiucture rathei than being passed directly, to allow for futuie expansion without having to rewrite all the constraint code The getinf o 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 keaCo- straint lnfo { keaFloat - 3 ] , int rows k.c , keaFloat ~ c keaFloat ~ _ , keaFloat ~ _ ower, *uoper , kea Float ' c .ipfactor, i r - vpeder vc_α eaGet lnfoFn ( keaConstramt lnfo * ) , The stiucture membeis aie • 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. • rows kip: 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. • siipf actor: 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 keaWorldmitiali ze ( 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 keaWorld≤tepl ( 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 1kg. 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 "over correct". 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 keaConstraintAt- tach ( ) 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 epos [3]; keaFloat normal [3] ; keaFloat penetration; keaFloat max_force; keaFloat a [3] ; keaFloat kl; . . . other internal stuff . . . } ; The fields of keaContact are: • mode: The contact mode is one of the following constants: • 0: Zero friction. • KEA_FRICTION_2 D: Friction in two directions using automatically determined principal directions. • KEA_FRICT ION_I D: Friction in one direction (vector a). • KEA_FRICT I ON_TYRE I : Friction in wheel drive direction (vector a) and first order slip in the lateral (other tangential) direction. The slip factor is the value kl . The following flags can be ORed with mode: • KEA_FRICT ION_BOX: Friction force magnitude along each principal direction is limited to max_force. • epos: 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_f orcε: 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 KΞA_FRICTION_ID and KEA_FRICTION_TYREI modes. It must have unit length. • 11: Parameter kl. This is set in KΞ-._FRICTIO:._TYRΞI mode. The keaContact functions are: void KeaCor.tactlnitialize (keaContact "contact); Initialize a new contact. 3.2. Ball-and-socket The keaBSJomt structure represents a ball and socket joint. void keaBSJo tlnitialize (keaBSJomt * joint); Initialize a new ball and socket joint. keaBSJoιntSet?osιtιon (keaBSJomt *]oιnt, 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 kea.H.inσe structure represents a hinge joint. Note that the initial position of the hinge will be taken as the zero reference for angle determination. void keaHmαelnitialize (keaHinge *]omt) ; Initialize a new hinge joint. void keaHinαeSetPosition (keaHinge "joint, keaFloat x, keaFloat y, keaFloat z); void keaHinσeSetAxis (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 keaHinαeSetNo imits (keaHinge *jomt); void keaHmgeSetLimits (keaHinge * joint, keaFloat low, keaFloat high); Set joint limits, low and high are in radians and are relative to the zero rX rence determined by the initial position of the hinge. void keaHmgeSetNoMotor (keaHinge * joint); void keaHmgeSetLimitedForceMotor (keaHinge * oιnt, keaFloat desιred_velocιty, keaFloat force_lim.it ) ; Sets a motor on the hinge. keaFloat " kea.-.ingeGetAxisAos (keaHinge *joιnt); Returns a pointer to a size 3 vector which gives the current hinge axis in absolute coordinates. KeaFloat ..ea-mgaGetAngle (keaHinge * oιnt); -.eaFloat kea. mgeGetAngieRate (keaHinge *joιnt); Returns the current hinge angle and angular velocity. 3.4. Prismatic The keaPrism structure represents a prismatic joint. void keaPrisrlnitialize (keaPrism *joιnt); Initialize a new prismatic joint. void keaPrisrSetAxis (keaPrism *joιnt, 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 keaPnsmSetNoLimits (keaPrism * joint ); void keaPris Set imits (keaPrism *joιnt, keaFloat low, keaFloat high); Set joint limits, low and mgh are in meters - position zero is when the centers of mass of the two bodies are as close to each other as possible. void keaPnsr.SetNoMotor (keaPrism *joιnt); void keaPrismSetLimitedForceMotor (keaPrism * oιnt, keaFloat desιred_veloctty, keaFloat f orce_lιmιt ) ; Sets a motor on the joint. keaFloat * KeaPnsmGetAxisAbs (keaPrism * joint ); Returns a pointer to a size 3 vector which gives the current sliding axis in absolute coordinates. keaFloat keaPnsmGetPosition (keaPrism * joint ); keaFloat keaPrismGetPositionRate (keaPrism *jo " int); Returns the cuirent sliding position and velocity. Position zero is when the centers of mass of the two bodies aie as close to each other as possible. 3.5. Steering hinge (1) The keaSteermgHmge 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 keaSteermgHingelnitialize (keaSteermgHmge *joιnt); Initialize a new steering hinge joint. void keaSt r ghmgeSet St er mgA is (keaSteermgHmge *joιnt, keaFloat x, keaFloat y, keaFloat z); void ke Ste mghingeSetHingeAxis (keaSteermgHmge *joιnt, keaFloat >., 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 " keaSteenngHingeGetHingeAxisAbs (keaSteermgHmge * joint); keaFloat " -'.eaSteermgHmgeGetSteermgAxisAbs (keaSteermgHmge *joιnt); 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 net be documented here yet. But check out the source file kea_collιce . 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 keaKme-aticTelescopeSegment 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 1 and body 2). void keaKine-naticTelescopeSegmentlnitialize ( keaKmematicTelescopeSeg- ment *k, keaFloat pcsl[3], keaFloat R[9], keaFloat pos2[3], keaFloat pos3[3]); Initialize a <eaKιnematιcTelescopeSegment structure, giving the initial positions of the three bodies, and the rotation matrix of body 1. void keaKmε-aticTelescopeSegmentGet Posit ion ( keaKmematicTelescopeSeg- πrent *k,keaF_oat posl[3 , keaFloat R[9], keaFloat pos2[3], keaFloat cs3[3] j; Given the positions of bodies 1 and 2. and the lotation 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 keaKineraticKeepPlacelmtialize (keaKinematicKeepPlace *k, keaFloat posl[3], keaFloat R [ 9] , keaFloat pos2[3]); Initialize a <eaKιnematιcKeepPlace structure, giving the initial positions of the bodies, and the rotation matrix of body 1. void keaKineraticKeepPlaceGetPosition (keaKinematicKeepPlace *k, keaFloat posl[3], keaF.oat 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): p = v (3.1) where p is the point position, r is its velocity, / 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: + ε λ = - Y£ _______ (3.3) in h 2 h m so the semi-implicit update for p and v is: »', + , = , + -.( " + λ) (3.4) hf Inn in .- c , = »', + — + ; ( 3-5) '» - + ε = vχhf(τ —) + — (3-6) = v « + f TTHiT ) + (TT7^ > + ^/,(i + ,»ε) ) (3 - 7) and P, + = P, + hv l+ , (3.8) Now consider removing the constraint, adding an external spring and damper force, and integrating implicitly: λ = 0 (3.10) /\ + ι = P, + hv, + (3.11) = '', + -(- k p P l + , - . + i) ( 3.13 ) 777 ^ = > . + -(- ^(A + /"', + ,) - _ + ι) ( 3.14 ) h 2 k n + hk .\ hk„ ".*' (ι+ - J H ) = -.-s t ''. &l5 > We can equate coefficients with equation (3.7) to see how to construct an "implicitly integrated spring" w ith a constraint (take / to be zero in equation (3.7)). First equate the coefficient on v, to find ε : 777 ε m (3.17) 1 + mε 777 + h 2 k + hk d z(m + h 2 k + hk d ) = \ + mε (3.18) ε = (3.19) h k p + hk d Then equate the coefficient on p t to find γ : -γ -hk p (3.20) h( \ + mε ) 777 + h-k + hk d h 2 k n ( \ + ε ) - γ = £ (3.21) ) + h 2 k p + hk d _ h (3.22) hk p + k d To summarize, ε = . . ' (3.23) h k p + hk d hk p (3.24) hkp + *< = h (3.25) 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 7 x 77 matnx M and a real /7-dιmensιonal vectoi q, the complementarity problem consists of finding the 7z-dιmensιonal vectoi s and u such that they satisfy the fol- lowins conditions Mz + q = \\ (426) :,≥0 V7 G {1,2, (427) u >0 Vz e {1,2, (428) u,;, _ 0 V7£ {1,2, ,n) (429) This is fundamentally a combinatorial problem and vaiious direct algorithms are available where the search goes through index sets α, β such that αc(l,2, ,«) , βc(l,2, , n) , αnβ = 0,α β _ { 1, 2, ,77} The set α is the set of active variables and ιv, = 0 Vi e α while the set β is the set of free vaπables such that z, = 0 V; e β The problem is then partitioned as where the subscripts α, β, are used to specify all indices that are in the sets α, β lespec- tively This is equivalent to the linear algebra problem which must be solved for c u while Wp is computed by direct substitution The matrix M aa 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 All principal pι\ot methods go through a sequence of sets α ( , β,, 1 = 1,2, until a solution is found ιe,5,≥0V/e (1,2, ,77} 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 α ( °> is good), set / = 0 . 2 form principal submatrix M a(l)a ) and solve Λ/ α( , )α( , ) c α( , ) = -q a ) 3 compute * (< > = c u „, + u- p{1) where .v βW = β(1)α(1) z α(I) 4 if _ , (, ) > 0 V / we are done else find the smallest./ ' such that sj ,> < 0 , if sj' ) = ; then α ( ' + 1 ) = X > λ{j } else α ( ' + ' ) = ^ u {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 figure 1 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: (4.34) λ > 0 v > 0 (4.35) λ'v = 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: is positive definite, where / /V and I , are identity matrices of appropriate sizes. Kostreva demonstrated that one can solve the sequence of complementarity problems defined by a sequence of positive numbers {ε..}°° = , 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 (typically 10 "6 ) 2. Solve LCP(M_°K q) 3. set .<-;+ 1. choose ε ( '> < ε*'- " 4. Solve LCP{M[' q) 5. if ||c<" -z (l - "|| < tυl Solve LCP(M,q) and finish 6. else if ||z (,) - (,_ "II < max goto step 2 7. else error: problem is infeasible We often set ε (θ1 = 10 -6 and ε ( " = 0. This is often sufficient. In Kea, we even go further and set ε<° ) = 10 ~3 and stop right away i.e., we don't bother removing the perturbation. 4.4 Boxed LCPs The boxed LCP problem starts from the definition of the standard LCP and adds two new n- dimensional vectors / and u, lower and upper bounds respectively, such that /, < w, V/ e { 1, 2, ..., 77} and then the problem reads: Mz + q = u' + -vr . (4.38) / >0 V e {1,2, ...,ιή (4.39) v. +( >0 Vi e {1,2, ...,77) (4.40) ( .-l.Xf, = 0 Vie {1,2, ...,n} (4.41) ,-z,≥ V e {1,2, ...,77} (4.42) » .( >0 V. e {1,2, ...,77} (4.43) This is equivalent to a much larger mixed linear complementarity problem defined as: (4.21) V-r H- +1 >0 μ,» ' + ι = 0 v., w >0 = 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 β defined as above into two sets, γ and ι so that Z j = I for / e y and ;__ - κ y for j ε i . Afterwards, we follow the Murty algorithm but we change the definition of the complementarity point s as follows: f min(z. - /., ii j - Zj ) Vy e α s, = (M. a z u - M X - M yι 77, + q.f j Vy e γ (4 23) .-(Λ/, (. α - A/ l . / . - Λ l l » l + <7l ) V e i and then, the least index rule is applied to this new complementarity point as follows: if j e α ( " and z}° < l } then α (, + ' ) = X' {j), γ ( ' + '> - γ ( '> {y } , _ ( ' + " = ι<' ) if j e α'' i and zj' ) > u then α ( ' + ■ > = cχ ( ' ) \{y }, ι ( ' + " = ιW {y }, γ ( ' + " = γ ( ' if j e γ ( ' ) then α ( ' + " = α ( ' ) {y }, γ ( ' + 1 ) = γ ( ' ) \{y }, ι ( ' + 1 ) = t ( ' ) if j ε γ i ' i then α<' + " = α^ u {/}, ι<' + •> = ιW\{ }, γ<' + ' ) = γ<'> 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 isotro- pic 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, /. , 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 μ^ times the magnitude of the normal force f n i.e., ||/, || = JfK+fh ≤ μsf,, (4 - 24) where /,, and /.. 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 r. and its magnitude is the kinetic friction coefficient μ k times the normal force i.e. /, • >' , = /,! » ',! + 2 - - 0 (4 - 26 ^ This model does not specify how to compute /_, or f t 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., π) = ι + f I |/,|| < n/» } (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 d \ , d 2 , ■■■, k and to represent the tangential friction force as: /, = ∑< ,β; ( «8 ) and from this definition, we get an approximation to the friction cone known as the friction polyhedron: c w = {/« + ° < β, < μ, ll »ll } (4 - 29) The construction is shown for the friction pyramid in figure 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, / max . This gives a simple approximation off the friction cone that we refer to as a 'box friction' model. „) = Λ + ∑ β,- o < β , -/ ma χf < 4 - 3 ° ) A box friction approximation to the friction cone is shown in figure 5.

Claims: Claims 1. A computer program recorded on a data carrier for simulating the motion of objects and displaying the results on a display screen, the computer program being operable to control a computer having a display screen, a memory and a processing unit to carry out the steps of storing in the 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. 2. A computer program recorded on a data carrier for simulating the motion of objects and displaying the results on a display screen, the computer program being operable to control a computer having a display screen, a memory and a processing unit to carry out the steps of storing in the 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, 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 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. 3. A computer program according to claim 1 or 2 operable to 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. 4. A computer program according to any preceding claim 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. 5. A computer program according to any preceding claim, wherein the constraint forces are determined by solving the mixed linear complementarity problem using Murty ' s method. 6. A computer program according to claim 5 wherein the means for solving the linear complementarity problem includes solving the boxed LCP problem by the boxed Murty ' s method. 7. A computer program according to claim 5 or 6 wherein the constraints are required to be held to within a tolerance ε where the tolerance ε has a predetermined value that is small . 8. A computer program according to claim 7 where ε has a value between 10 "4 and 10 ~2 . 9. A computer program according to any preceding claim wherein the model includes a model of friction in which the frictional force between a pair of objects is independent of the normal force between the objects. 10. A computer program according to claim 9 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. 11. A computer program according to any preceding claim wherein the bounds on the constraint forces are included by a step of testing whether the constraint forces have a magnitude SUBSTITUTE SHEET (PULE 26) greater than a predetermined value and if so setting them to be that predetermined value. 12. A computer program according to any preceding claim in which the constraints are modelled using the first order expansion of the constraint function Φ : Φ = φ 0 + J p (p ' -p) in the constraint equation. where γ is a relaxation parameter. 13. A computer program according to claim 12 when dependent on claim 6 wherein the parameters γ and ε are chosen to model a compliant coupling between two of the rigid bodies. 14. A computer program according to any one of claims 1 to 13 that is a computer game program. 15. A computer game program according to claim 14 recorded within a cartridge for a computer game machine. 16. A computer game programmed to generate a display by means of a computer program according to any preceding claim. 17. A method for 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 including the steps of storing m the 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. 18. A method for 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 including the steps of storing in the 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 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 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. 19. A method according to claim 17 or 18 including 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. 20. A method according to any of claims 17 to 19 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. 21. A method according to of claims 17 to 20, wherein the constraint forces are determined by solving the mixed linear complementarity problem using a Murty algorithm . 22. A method according to claim 21 wherein the linear complementarity problem is solved by solving the boxed LCP problem by the boxed Murty ' s method. 23. A method according to claim 21 or 22 wherein the constraints are required to be held to within a tolerance ε where the tolerance ε has a predetermined value that is srr_ll. 24. A method according to claim 23 where ε has a value between 10 "4 and 10 "2 . 25. A method according to any of claims 17 to 24 wherein the model includes a model of friction in which the frictional force between a pair of objects is independent of the normal force between the objects. 26. A method according to claim 25 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. 27. A method according to any of claims 17 to 26 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. 28. A method according to any of claims 17 to 27 in which the constraints are modelled using the first order expansion of the constraint function Φ : Φ = φ 0 + J p (p ' -p) in the constraint equation. φ 0 + J p (p ' - p) - (l -γ) φ 0 where γ is a relaxation parameter. 29. A method according to claim 28 when dependent on claim 19 wherein the parameters γ and ε are chosen to model a compliant coupling between two of the rigid bodies. 30. A method of generating a display in a computer game according to any one of claims 17 to 29. 31. 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 : storing in the 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. 32. 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 : storing in the 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 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 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. 33. A computer program recorded on a data carrier for simulating the motion of objects and displaying the results on a display screen, the computer program being operable to control a computer having a display screen, a memory and a processing unit to carry out the steps of storing in the 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 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; 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. 3 . A computer program recorded on a data carrier for simulating the motion of objects and displaying the results on a display screen, the computer program being operable to control a computer having a display screen, a memory and a processing unit to carry out the steps of storing in the memory position and velocity parameters defining an initial state of a model system having a plurality of bodies, the model including a model of friction in which the frictional force between a pair of objects is independent of the normal force between the objects; 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 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; 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. 35. A computer program recorded on a data carrier for simulating the motion of objects and displaying the results on a display screen substantially as herein described with reference to the accompanying drawings . 36. A method for 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 substantially as herein described with reference to the accompanying drawings . 37. Apparatus for simulating the motion of objects and displaying the results on a display screen comprising substantially as herein described with reference to the accompanying drawings .

Inventors: LACOURSIERE CLAUDE, SMITH RUSSELL LEIGH, LACOURSIERE, CLAUDE, SMITH, RUSSELL, LEIGH
Applicants: LACOURSIERE CLAUDE, MATHENGINE PLC, SMITH RUSSELL LEIGH, LACOURSIERE, CLAUDE, SMITH, RUSSELL, LEIGH
Application year: 2001
Main classification: G06F17
IPC codes: G06F17, G06F19, G06T15