Constraints
The library provides two kinds of constraints. Global constraints are applied to all masses, and are generally rendered if graphics is enabled. Examples include ball and plane constraints (i.e. all masses are constrained to lie on one side of a plane or outside of a given ball).
All constraint apply large normal forces to masses violating the constraint, which can lead to instabilities and unwanted behaviour, especially for small delta-t values. If un-physical behavior is observed, try lowering the delta-t value on the masses in question.
Creates a contact plane constraint which forces the mass to lie on the positive side of the plane. The normal vector has the form (a, b, c), and defines a plane ax + by + cz = d, with the normal defining the orientation.
Creates a ball constraint which forces the mass to lie outside of the ball. Defines a ball center dot (position - radius) < radius.
All masses may have local constraints applied, which only affect them and are not rendered. These are detailed in the mass wiki page, and are reproduced here. The mass object has methods
void addConstraint(CONSTRAINT_TYPE type, const Vec & v, double num);
void setDrag(double C);
void fix();
void unfix();
void clearConstraints(CONSTRAINT_TYPE type);
void clearAllConstraints();
The CONSTRAINT_TYPE is an enum which specifies the types of constraints which are allowed to be used. In particular, those include
- CONSTRAINT_PLANE: a constraint which forces the mass to stay in a certain plane specified by a normal vector. The double here functions as a coefficient of friction.
- CONTACT_PLANE: a contact constraint which forces the mass to stay in a half space specified by a normal vector and offset (same as the global Plane, ax + by + cz = d).
- BALL: a contact constraint which forces the mass to stay in the outside of a ball with specified center vector and radius.
- DIRECTION: a constraint which forces the mass to stay in a given line specified by a tangent vector. The double here functions as a coefficient of friction.
This example adds several global constraints to the simulation, and then constraints one of the masses to lie in a given plane.
Mass * m1 = sim.createMass(Vec(0, 0, 1));
sim.createPlane(Vec(0, 0, 1), -1); // plane z = -1
sim.createBall(Vec(0, 0, 2), 4); // ball centered at (0, 0, 2) with radius 4.
m1 -> addConstraint(CONSTRAINT_PLANE, Vec(0, 1, 1), 0); // constraint plane with normal (0, 1, 1) and no friction applied
- Home
- Quickstart
-
About the Titan Library
- Basic Concepts
- Functions
- Data Structures
- CPU - GPU Architecture
- Tutorials