# Joints and Motors

A joint establishes some kind of relation between two or more bodies. There are different kinds of joints:

# Distance Joint

A spring or a rigid connector.

```  //joints   import fisica.*;   FWorld world;   void setup() { //sketch size in pixels size(800, 600);   //initialize the physics library Fisica.init(this);   //create a new Fisica world world = new FWorld();   //set the world's properties: world.setEdges(); world.setGravity(0, 0);     FBox b1 = new FBox(70, 20); b1.setPosition(100, 100); world.add(b1);   FBox b2 = new FBox(20, 50); b2.setPosition(300, 100); world.add(b2);   FDistanceJoint spring = new FDistanceJoint(b1, b2); world.add(spring);   //you can change the spring position //spring.setAnchor1(30, 0); //spring.setAnchor2(0, 40);   //and make it springy. It's rigid by default //spring.setFrequency(0.5); //spring.setDamping(0.1);   //By default the balance between bodies is the distance between the bodies. //But it can be arbitrary: //spring.setLength(60);     //it doesn't have to be visible //spring.setDrawable(false); }     void draw() { //update the simulation world.step(); background(255); //redraw the physics world world.draw(); }//end of draw loop```

See the reference for the parent class FJoint for more methods
and FDistanceJoint for distance joint specific ones

# Prismatic Joint

The prismatic joint is more commonly known as a slider joint. The two joined bodies have their rotation held fixed relative to each other, and they can only move along a specified axis.

``` FBox b1 = new FBox(70, 20); b1.setPosition(400, 200); world.add(b1);   FBox b2 = new FBox(20, 50); b2.setPosition(400, 300); world.add(b2);   FPrismaticJoint rotor = new FPrismaticJoint(b1, b2); world.add(rotor);   //a bit bizzarre now, let's reduce some degrees of freedom. //b1.setStatic(true); //b1.setGrabbable(false);   //b1.setDrawable(false); //rotor.setDrawable(false);   // Sets whether the bodies connected by the joint should collide with each other // method for all joints //rotor.setCollideConnected(false);```

# Revolute joint

The revolute joint can be thought of as a hinge, a pin, or an axle. An anchor point is defined on each body, and the bodies will be moved so that these two points are always in the same place, and the relative rotation of the bodies is not restricted.

``` FBox b1 = new FBox(70, 20); b1.setPosition(400, 200); world.add(b1);   FBox b2 = new FBox(20, 50); b2.setPosition(width/2, height/2); world.add(b2);   FRevoluteJoint axis = new FRevoluteJoint(b1, b2); world.add(axis);   //the position of the anchor can be changed //axis.setAnchor(width/2, height/2);   //a bit bizzarre now, let's reduce some degrees of freedom. //b1.setStatic(true); //b1.setGrabbable(false);   //b1.setDrawable(false); //axis.setDrawable(false);   // Sets whether the bodies connected by the joint should collide with each other // method for all joints axis.setCollideConnected(false);```

# MOtor

``` //adding a motor axis.setEnableMotor(true); axis.setMotorSpeed(1000); axis.setMaxMotorTorque(100);```
Posted in