search

# Class myphysicslab.lab.engine2D.Joint

Provided By `myphysicslab.lab.engine2D.Joint` `myphysicslab.lab.model.AbstractSimObject` `myphysicslab.lab.engine2D.Connector``myphysicslab.lab.model.SimObject``myphysicslab.lab.util.Printable`

A Joint connects two RigidBodys by generating RigidBodyCollisions which are used to find contact forces or collision impulses so that the attachment points on the two RigidBodys are kept aligned together.

The `#addCollision` method is where the collisions are generated; that method is called from `myphysicslab.lab.engine2D.ContactSim#findCollisions`. The RigidBodyCollision generated for a Joint functions as both a collision and a contact.

Joints are immutable: they cannot be changed after they are constructed.

When two RigidBodys are connected by a Joint, the two bodies are set to not collide with each other via `myphysicslab.lab.engine2D.RigidBody#addNonCollide`.

The order of the bodies in the Joint is important because `#align` moves the second body to align with first body (unless the second body is immoveable because it has infinite mass).

The normal vector provided when making a Joint specifies the direction along which the Joint operates. ContactSim calculates forces to keep the acceleration in the normal direction at zero between the two attachment points of the Joint.

A single joint by itself will give a 'sliding track' type of connection. The attachment points must have zero distance between them as measured in the direction of the normal for the Joint, but in the direction perpendicular to the normal the attachment points are free to move. See CartPendulum2 for an example.

A double joint consists of two Joints at the same location (same attachment points) with perpendicular normal directions. A double joint is needed to keep the attachment points aligned together.

Over time slippage of a Joint can occur, especially when there is fast rotation of the bodies. The tightness of a Joint is measured by how close to zero is the distance between the two attachment points. See `#getNormalDistance`.

To attach to a fixed position in space use the `myphysicslab.lab.engine2D.Scrim` object. Or attach to an immoveable (infinite mass) Polygon.

The two attachment points can be widely separated in 'single joints', see CartPendulum2 for an example.

Another name for a joint is a bilateral contact point meaning that it can both push and pull. This is different from ordinary contact points between bodies which can only push against each other.

### Specifying a Joint's Normal Vector

When specifying a normal, we also specify the `myphysicslab.lab.model.CoordType`, which is either world coordinates or body coordinates. There are two cases:

• `CoordType.WORLD` the normal is in world coordinates and is fixed.

• `CoordType.BODY` The normal is calculated in the body coordinates of the second RigidBody of the Joint, and rotates along with that body.

(need to convert from Java) TO BE DONE To make a Joint with a NumericalPath use PathJoint. In that case it is the NumericalPath that determines the normal.

### Aligning Joints

The `#align` method aligns the RigidBodys connected by this Joint. Moves the second body to align with the first body (unless the second body has infinite mass, in which case the first body is aligned to the second). The second body is moved so that its attach point is at same position as the first body's attach point. The angle of the second body is not changed.

NOTE: `align()` only changes the position of the RigidBody, you may need to call `myphysicslab.lab.engine2D.RigidBodySim#initializeFromBody` after this to update the simulation variables. The method `myphysicslab.lab.engine2D.ContactSim#alignConnectors` does the `initializeFromBody` step automatically.

### Implementation Note: Separate Impact Points

Each side of the Joint has its own impact point and `R` vector; these are `impact, impact2, R` and `R2`. We figure the impact point on each body according to where the attachment point is on that body, by doing a `bodyToWorld` translation to find the current location.

Previously we calculated the impact point only for `body1` of the joint and then used that world location to calculate the `R2` for the normal body. It seems that gives worse results, as shown by the 'two-connected-blocks' test where two blocks are connected rigidly by 2 double joints. When the two-connected-blocks is spun quickly, the joints slip significantly if we use the impact point of `body1` to define where the joint is on `body2`.

### new Joint( rigidBody1, attach1_body, rigidBody2, attach2_body, normalType, normal )

Parameters
 rigidBody1 `myphysicslab.lab.engine2D.RigidBody` the first body of the Joint attach1_body `myphysicslab.lab.util.Vector` the attachment point on the first body in body coordinates rigidBody2 `myphysicslab.lab.engine2D.RigidBody` the second body of the Joint attach2_body `myphysicslab.lab.util.Vector` the attachment point on the second body normalType `myphysicslab.lab.model.CoordType` whether the normal is in body (for `rigidBody2`) or world coordinates, from `myphysicslab.lab.model.CoordType` normal `myphysicslab.lab.util.Vector` this Joint's normal vector in body (for `rigidBody2`) or world coordinates