PULLEY JOINT

21
Jun
2012

A pulley is used to create an idealized pulley. The pulley connects two bodies to ground and to each other. As one body goes up, the other goes down. The total length of the pulley rope is conserved according to the initial configuration.

length1 + length2 == constant

You can supply a ratio that simulates a block and tackle. This causes one side of the pulley to extend faster than the other. At the same time the constraint force is smaller on one side than the other. You can use this to create "Mechanical Leverage".

length1 + ratio * length2 == constant

For example, if the ratio is 2, then length1 will vary at twice the rate of length2. Also the force in the rope attached to body1 will have half the constraint force as the rope attached to body2.

Make sure the following codes are at the beginning.
```var    b2Vec2 = Box2D.Common.Math.b2Vec2
,      b2BodyDef = Box2D.Dynamics.b2BodyDef
,      b2Body = Box2D.Dynamics.b2Body
,      b2FixtureDef = Box2D.Dynamics.b2FixtureDef
,      b2World = Box2D.Dynamics.b2World
,      b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape
,      b2CircleShape = Box2D.Collision.Shapes.b2CircleShape
,      b2RevoluteJointDef=Box2D.Dynamics.Joints.b2RevoluteJointDef
,      b2MouseJointDef =  Box2D.Dynamics.Joints.b2MouseJointDef
,      b2PulleyJointDef = Box2D.Dynamics.Joints.b2PulleyJointDef
,      b2DebugDraw = Box2D.Dynamics.b2DebugDraw
,      b2Fixture = Box2D.Dynamics.b2Fixture
,      b2AABB = Box2D.Collision.b2AABB;
```

Line 10 should be present.

### Pulley Joint Definition

```var myjoint = new b2PulleyJointDef();
var worldAnchorOnBody1 = new b2Vec2(6, 7); // Anchor point on body 1 in world axis
var worldAnchorOnBody2 = new b2Vec2(16, 7); // Anchor point on body 2 in world axis
var worldAnchorGround1 = new b2Vec2(6,3); // Anchor point for ground 1 in world axis
var worldAnchorGround2 = new b2Vec2(16,3); // Anchor point for ground 2 in world axis
var ratio = 1; // Define ratio
myjoint.Initialize(box1, box2, worldAnchorGround1, worldAnchorGround2, worldAnchorOnBody1, worldAnchorOnBody2, ratio);
//myjoint.lengthA = 10; // The a reference length for the segment attached to bodyA.
//myjoint.lengthB = 6; // The a reference length for the segment attached to bodyB.
world.CreateJoint(myjoint);
```

NOTE: If you know what lengthA and lengthB in lines 8 & 9 means, please share.

NOTE: To view Source for the given example, right click on canvas element and View frame source.

NOTE: Remember Box2d assumes body is in the correct position when the joint is made.

By administrator at 04:08:23 PM 4 Comment(s)