## Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

## Physics

## TOC »

## Documentation

A high-level wrapper for Chipmunk2D.

## Author

Richard van Roy

## Requirements

### Vectors

#### Creation

`create-vect``x``y`procedureCreates a new vector.

#### Properties

`vect-x``vect`procedure

`vect-y``vect`procedure

#### Methods

`vect-=?``vect-a``vect-b`procedureCheck if two vectors are equal.

`vect-add``vect-a``vect-b`procedureAdds two vectors.

`vect-sub``vect-a``vect-b`procedureSubstracts two vectors

`vect-neg``vect`procedureNegate a vector.

`vect-mult``vect``scalar`procedureScalar multiplication

`vect-dot``vect-a``vect-b`procedureVector dot product.

`vect-cross``vect-a``vect-b`procedure2D vector cross product analog. The cross product of 2D vectors results in a 3D vector with only a z component. This function returns the value along the z-axis.

`vect-perp``vect`procedureReturns a perpendicular vector. (90 degree rotation)

`vect-rperp``vect`procedureReturns a perpendicular vector. (-90 degree rotation)

`vect-project``vect-a``vect-b`procedureReturns the vector projection of

*vect-a*onto*vect-b*.

`vect-rotate``vect-a``vect-b`procedureUses complex multiplication to rotate

*vect-a*by*vect-b*. Scaling will occur if*vect-a*is not a unit vector.

`vect-unrotate``vect-a``vect-b`procedureInverse of

*(vect-rotate)*.

`vect-length``vect`procedureReturns the length of v.

`vect-length-squared``vect`procedureReturns the squared length of v. Faster than

*(vect-length)*when you only need to compare lengths.

`vect-lerp``vect-a``vect-b``t`procedureLinearly interpolate between

*vect-a*and*vect-b*.

`vect-lerpconst``vect-a``vect-b``t`procedureLinearly interpolate between

*vect-a*towards*vect-b*by distance d.

`vect-slerp``vect-a``vect-b``t`procedureSpherical linearly interpolate between

*vect-a*and*vect-b*.

`vect-slerpconst``vect-a``vect-b``angle`procedureSpherical linearly interpolate between

*vect-a*towards*vect-b*by no more than angle*angle*in radians.

`vect-normalize``vect`procedureReturns a normalized copy of v. As a special case, it returns

*(vect-zero)*when called on*(vect-zero)*.

`vect-clamp``vect``length`procedureClamp v to length

*length*.

`vect-dist``vect-a``vect-b`procedureReturns the distance between

*vect-a*and*vect-b*.

`vect-dist-squared``vect-a``vect-b`procedureReturns the squared distance between

*vect-a*and*vect-b*. Faster than*(cpvdist)*when you only need to compare distances.

`vect-near?``vect-a``vect-b``distance`procedureReturns true if the distance between

*vect-a*and*vect-b*is less than*distance*.

#### Conversions

`angle->vect``angle`procedureReturns the unit length vector for the given

*angle*(in radians).

`vect->angle``vect`procedureReturns the angular direction

*vect*is pointing in (in radians).

### Axis Aligned Bounding Boxes

#### Creation

`create-bb``left-bottom``right-top`procedureCreates a new Axis Aligned Bounding Box

#### Properties

`bb-left-bottom``bb`procedure

`bb-right-top``bb`procedure

#### Methods

`bb-intersects?``bb-a``bb-b`procedureReturns true if the bounding boxes intersect.

`bb-contains-bb?``bb``other`procedureReturns true if

*bb*completely contains*other*.

`bb-contains-vect?``bb``vect`procedureReturns true if bb contains

*vect*.

`bb-merge``bb-a``bb-b`procedureReturn the minimal bounding box that contains both

*bb-a*and*bb-b*.

`bb-expand``bb``vect`procedureReturn the minimal bounding box that contains both bb and

*vect*.

`bb-center``bb`procedureReturn the center of bb.

`bb-area``bb`procedureReturn the area of bb.

`bb-merged-area``bb-a``bb-b`procedureMerges

*bb-a*and*bb-b*then returns the area of the merged bounding box.

`bb-seqment-query``bb``vect-a``vect-b`procedureReturns the fraction along the segment query the bounding box is hit. Returns

**infinity**if it doesn’t hit.

`bb-intersects-seqment``bb``vect-a``vect-b`procedureReturns true if the segment defined by endpoints

*vect-a*and*vect-b*intersect*bb*.

`bb-clamp-vect``bb``vect`procedureReturns a copy of

*vect*clamped to the bounding box.

`bb-wrap-vect``bb``vect`procedureReturns a copy of

*vect*wrapped to the bounding box.

### Bodies

#### Creation

`create-body``mass``inertia`procedureReturns a new body.

*mass*and*inertia*are the mass and moment of inertia for the body. Guessing the mass for a body is usually fine, but guessing a moment of inertia can lead to a very poor simulation.

`create-static-body`procedureCreate additional static bodies with infinite mass and moment of inertia.

#### Properties

`body-mass``body`procedure`set!`(`body-mass``body`)`value`setterMass of the body.

`body-moment``body`procedure`set!`(`body-moment``body`)`value`setterMoment of inertia (MoI or sometimes just moment) of the body. The moment is like the rotational mass of a body. See below for function to help calculate the moment.

`body-position``body`procedure`set!`(`body-position``body`)`value`setterPosition of the center of gravity of the body. When changing the position you may also want to call

*(space-reindex-shapes-for-body)*to update the collision detection information for the attached shapes if plan to make any queries against the space.

`body-velocity``body`procedure`set!`(`body-velocity``body`)`value`setterLinear velocity of the center of gravity of the body.

`body-force``body`procedure`set!`(`body-force``body`)`value`setterForce applied to the center of gravity of the body.

`body-angle``body`procedure`set!`(`body-angle``body`)`value`setterRotation of the body in radians. When changing the rotation you may also want to call

*(space-reindex-shapes-for-body)*to update the collision detection information for the attached shapes if plan to make any queries against the space.

`body-angle-velocity``body`procedure`set!`(`body-angle-velocity``body`)`value`setterThe angular velocity of the body in radians per second.

`body-torque``body`procedure`set!`(`body-torque``body`)`value`setterThe torque applied to the body.

`body-rotation``body`procedureThe rotation vector for the body. Can be used with

*(vect-rotate)*or*(vect-unrotate)*to perform fast rotations.

`body-velocity-limit``body`procedure`set!`(`body-velocity-limit``body`)`value`setterVelocity limit of the body. Defaults to

**infinity**unless you set it specifically. Can be used to limit falling speeds, etc.

`body-angularvelocity-limit``body`procedure`set!`(`body-angular-velocity-limit``body`)`value`setterAngular velocity limit of the body in radians per second. Defaults to

**infinity**unless you set it specifically.

`body-space``body`procedureGet the

*space*that*body*has been added to.

`body-userdata``body`procedure`set!`(`body-userdata``body`)`value`setterUserdata can be set to any object and is not used internally.

#### Sleeping Functions

`body-sleeping?``body`procedureReturns

**#t**if*body*is sleeping.

`body-activate``body`procedureReset the idle timer on a body. If it was sleeping, wake it and any other bodies it was touching.

`body-sleep``body`procedureForces a body to fall asleep immediately even if it’s in midair. Cannot be called from a callback.

`body-activate-static``body``#!optional``filter-shape`procedureSimilar in function to

*(body-activate)*. Activates all bodies touching*body*. If*filter-shape*is set, then only bodies touching through it will be awoken.

`body-sleep-with-group``body``#!optional``group`procedureWhen objects in Chipmunk sleep, they sleep as a group of all objects that are touching or jointed together. When an object is woken up, all of the objects in it’s group are woken up. this function allows you group sleeping objects together. It acts identically to

*(body-sleep)*if you don't pass a*group*by starting a new group. If you pass a sleeping body for*group*,*body*will be awoken when*group*is awoken. You can use this to initialize levels and start stacks of objects in a pre-sleeping state.

#### Iterators

`body-each-shape``body``proc`procedureThis functions calls

*proc*on every shape inside this body.*proc*should have the following form:(lambda (shape) ...)

`body-each-constraint``body``proc`procedureThis functions calls

*proc*on every constraint inside this body.*proc*should have the following form:(lambda (constraint) ...)

`body-each-arbiter``body``proc`procedureThis functions calls

*proc*on every arbiter inside this body.*proc*should have the following form:(lambda (arbiter) ...)

#### Moment of Inertia and Area Helper Functions

Use the following functions to approximate the moment of inertia for your body, adding the results together if you want to use more than one.

`moment-for-circle``mass``radius-a``radius-b``offset`procedureCalculate the moment of inertia for a hollow circle,

*radius-a*and*radius-b*are the inner and outer diameters in no particular order. (A solid circle has an inner diameter of 0)

`moment-for-seqment``mass``vect-a``vect-b`procedureCalculate the moment of inertia for a line segment. The endpoints

*vect-a*and*vect-b*are relative to the body.

`moment-for-polygon``vertices``offset`procedureCalculate the moment of inertia for a solid polygon shape assuming it’s center of gravity is at it’s centroid. The offset is added to each vertex.

`moment-for-box``width``height`procedureCalculate the moment of inertia for a solid box centered on the body.

`area-for-circle``radius-a``radius-b`procedureArea of a hollow circle.

`area-for-segment``vect-a``vect-b``radius`procedureArea of a beveled segment. (Will always be zero if

*radius*is zero)

`area-for-polygon``vertices`procedureSigned area of a polygon shape. Returns a negative number for polygons with a backwards winding.

#### Coordinate Conversion Functions

Many things are defined in coordinates local to a body meaning that the (0,0) is at the center of gravity of the body and the axis rotate along with the body.

`body-local->world``body``vect`procedureConvert from body local coordinates to world space coordinates.

`body-world->local``body``vect`procedureConvert from world space coordinates to body local coordinates.

#### Applying Forces and Torques

People are sometimes confused by the difference between a force and an impulse. An impulse is basically a very large force applied over a very short period of time, like a ball hitting a wall or cannon firing. Chipmunk treats impulses as if they occur instantaneously by simply adding directly to the velocity of an object. Both impulses and forces are affected the mass of an object. Double the mass of the object and halve the effect.

`body-reset-forces``body`procedureZero both the forces and torques currently applied to the body.

`body-apply-force``body``f``r`procedureAdd the force

*f*to*body*at a relative offset*r*from the center of gravity.

`body-apply-impulse``body``i``j`procedureAdd the impulse

*j*to*body*at a relative offset*r*from the center of gravity.**Note:**Both the*(body-apply-force)*and*(body-apply-impulse)*functions take a force or impulse in absolute coordinates and applies it at a relative offset in absolute coordinates. (The offset is relative to the center of gravity, but is not rotated with the body)

#### Misc functions

`body-static?``body`procedureReturns

**#t**if body is a static body. Either*(space-static-body)*or a body created with*(create-static-body)*.

`body-roque?``body`procedureReturns

**#t**if body has never been added to a space.

### Collision Shapes

#### Properties

`shape-body``shape`procedure`set!`(`shape-body``shape`)`value`setterThe rigid body the shape is attached to. Can only be set when the shape is not added to a space.

`shape-bb``shape`procedure`set!`(`shape-bb``shape`)`value`setterThe bounding box of the shape. Only guaranteed to be valid after

*(shape-cache-bb)*or*(space-step)*is called. Moving a body that a shape is connected to does not update it’s bounding box. For shapes used for queries that aren’t attached to bodies, you can also use*(shape-update)*.

`shape-sensor``shape`procedure`set!`(`shape-sensor``shape`)`value`setterA boolean value if this shape is a sensor or not. Sensors only call collision callbacks, and never generate real collisions.

`shape-elasticity``shape`procedure`set!`(`shape-elasticity``shape`)`value`setterElasticity of the shape. A value of

*0.0*gives no bounce, while a value of*1.0*will give a “perfect” bounce. However due to inaccuracies in the simulation using*1.0*or greater is not recommended however. The elasticity for a collision is found by multiplying the elasticity of the individual shapes together.

`shape-friction``shape`procedure`set!`(`shape-friction``shape`)`value`setterFriction coefficient. Chipmunk uses the Coulomb friction model, a value of

*0.0*is frictionless. The friction for a collision is found by multiplying the friction of the individual shapes together.

`shape-surface-velocity``shape`procedure`set!`(`shape-surface-velocity``shape`)`value`setterThe surface velocity of the object. Useful for creating conveyor belts or players that move around. This value is only used when calculating friction, not resolving the collision.

`shape-collision-type``shape`procedure`set!`(`shape-collision-type``shape`)`value`setterYou can assign types to Chipmunk collision shapes that trigger callbacks when objects of certain types touch.

`shape-group``shape`procedure`set!`(`shape-group``shape`)`value`setter`High-level`procedure**TODO**

`shape-layers``shape`procedure`set!`(`shape-layers``shape`)`value`setter`High-level`procedure**TODO**

`shape-space``shape`procedureGet the

*space*that*shape*has been added to.

`shape-userdata``shape`procedure`set!`(`shape-userdata``shape`)`value`setterThis can be set to any value.

#### Misc Functions

`shape-cache-bb``shape`procedureSynchronizes shape with the body its attached to.

`shape-update``shape``position``rotation`procedureSets the position and rotation of the shape.

`reset-id-counter`procedureChipmunk keeps a counter so that every new shape is given a unique hash value to be used in the spatial index. Because this affects the order in which the collisions are found and handled, you can reset the shape counter every time you populate a space with new shapes. If you don’t, there might be (very) slight differences in the simulation.

#### Circles

##### Creation

`create-circle``body``radius``offset`procedure*body*is the body to attach the circle to,*offset*is the offset from the body’s center of gravity in body local coordinates.

##### Properties

`circle-offset``cirlce-shape`procedure

`circle-radius``cirlce-shape`procedure

#### Segments

##### Creation

`create-segment-shape``body``vect-a``vect-b``radius`procedure*body*is the body to attach the segment to,*vect-a*and*vect-b*are the endpoints, and radius is the thickness of the segment.

##### Properties

`segment-shape-a``segment-shape`procedure

`segment-shape-b``segment-shape`procedure

`segment-shape-normal``segment-shape`procedure

`segment-shape-radius``segment-shape`procedure

#### Polygons

##### Creation

`create-polygon-shape``body``vertices``offset``#!optional``radius`procedure*body*is the body to attach the poly to, vertices is an list of vectors defining a convex hull with a clockwise winding,*offset*is the offset from the body’s center of gravity in body local coordinates. An assertion will be thrown the vertexes are not convex or do not have a clockwise winding.

##### Properties

`polygon-shape-vertices``polygon`procedure

`polygon-shape-radius`procedure

##### Helper Functions

`valid-polygon?``vertices`procedureCheck if a vertex array is convex and with the correct winding.

`centroid-for-polygon``vertices`procedureCalculate the centroid for a polygon.

`centroid-for-polygon``vertices`procedureCenter a polygon to (0,0). Subtracts the centroid from each vertex.

##### Convex Hull Helper Functions

**TODO**

#### Boxes

**TODO**

### Space

#### Creation

`create-space`procedure

#### Properties

`space-iterations``space`procedure`set!`(`space-iterations``space`)`value`setterIterations allow you to control the accuracy of the solver. Defaults to 10.

`space-gravity``space`procedure`set!`(`space-gravity``space`)`value`setterGlobal gravity applied to the space. Defaults to

*(vect-zero)*. Can be overridden on a per body basis by writing custom integration functions.

`space-damping``space`procedure`set!`(`space-damping``space`)`value`setterAmount of simple damping to apply to the space. A value of 0.9 means that each body will lose 10% of it’s velocity per second. Defaults to 1. Like

*gravity*can be overridden on a per body basis.

`space-idle-speed-treshold``space`procedure`set!`(`space-idle-speed-treshold``space`)`value`setterSpeed threshold for a body to be considered idle. The default value of 0 means to let the space guess a good threshold based on gravity.

`space-sleep-time-treshold``space`procedure`set!`(`space-sleep-time-treshold``space`)`value`setterTime a group of bodies must remain idle in order to fall asleep. The default value of INFINITY disables the sleeping feature.

`space-collision-slop``space`procedure`set!`(`space-collision-slop``space`)`value`setterAmount of overlap between shapes that is allowed. It’s encouraged to set this as high as you can without noticable overlapping as it improves the stability. It defaults to 0.1.

`space-collision-bias``space`procedure`set!`(`space-collision-bias``space`)`value`setterChipmunk allows fast moving objects to overlap, then fixes the overlap over time. Overlapping objects are unavoidable even if swept collisions are supported, and this is an efficient and stable way to deal with overlapping objects. The bias value controls what percentage of overlap remains unfixed after a second and defaults to ~0.2%. Valid values are in the range from 0 to 1, but using 0 is not recommended for stability reasons. The default value is calculated as

*(vect-pow((- 1.0 0.1) 60.0)*meaning that Chipmunk attempts to correct 10% of error ever 1*60th of a second.*'Note<procedure> Very very few games will need to change this value.</procedure>

`space-collision-persistence``space`procedure`set!`(`space-collision-persistence``space`)`value`setterThe number of frames the space keeps collision solutions around for. Helps prevent jittering contacts from getting worse. This defaults to 3 and very very

**very**few games will need to change this value.

`space-current-time-step``space`procedureRetrieves the current (if you are in a callback from

*(space-step)*) or most recent (outside of a*(space-step)*call) timestep.

`space-locked?`procedureReturns true when in a callback meaning that you cannot add''remove objects from the space. Can be used to choose to create a post-step callback instead.

`space-userdata``space`procedure`set!`(`space-userdata``space`)`value`setterThis can be set to any value.

`space-static-body``space`procedureA dedicated static body for the space. You don’t have to use it, but because it’s memory is managed automatically with the space it’s very convenient. You can set its user data pointer to something helpful if you want for callbacks.

`space-bodies``space`procedureReturns a list of all bodies added to this space.

`space-shapes``space`procedureReturns a list of all shapes added to this space.

`space-constraints``space`procedureReturns a list of all constraints added to this space.

#### Operations

**Note:** It is not possible to add/remove something to/from a space inside callbacks other then *post-step*.

`space-add-shape``space``shape`procedure`space-add-static-shape``space``shape`procedure`space-remove-shape``space``shape`procedure`space-has-shape?``space``shape`procedure

`space-add-body``space``body`procedure`space-remove-body``space``body`procedure`space-has-body?``space``body`procedure

`space-add-constraint``space``constraint`procedure`space-remove-constraint``space``constraint`procedure`space-has-constraint?``space``constraint`procedure

#### Iterators

`space-each-body``space``func`procedureThis functions calls

*proc*on every body inside this space.*proc*should have the following form:(lambda (body) ...)

`space-each-shape``space``func`procedureThis functions calls

*proc*on every shape inside this space.*proc*should have the following form:(lambda (shape) ...)

`space-each-constraint``space``func`procedureThis functions calls

*proc*on every constraint inside this space.*proc*should have the following form:(lambda (constraint) ...)

#### Simulating the Space

`space-step``space`procedureUpdate the space for the given time step. Using a fixed time step is

**highly**recommended.

#### Enabling and Tuning the Spatial Hash

If you have thousands of objects that are all approximately the same size, the spatial hash may be for you.

`space-use-spatital-hash``space``dim``count`procedureSwitch the space to use a spatial hash instead of the bounding box tree.

#### Collision Handlers

`space-on-collision-begin``space`procedure`set!`(`space-on-collision-begin``space`)`func`setterTwo shapes just started touching for the first time this step. Return true from the callback to process the collision normally or false to cause Chipmunk to ignore the collision entirely. If you return false, the /presolve/ and /postsolve/ callbacks will never be run, but you will still recieve a separate event when the shapes stop overlapping.

*func*must have the form:(lambda (arbiter space data) ...) -> boolean

Return

**#t**from the callback to process the collision normally or**#f**to cause Chipmunk to ignore the collision entirely. If you return**#f**, the*(presolve)*and*(postSolve)*callbacks will never be run, but you will still recieve a separate event when the shapes stop overlapping.

`space-on-collision-presolve``space`procedure`set!`(`space-on-collision-presolve``space`)`func`setterTwo shapes are touching during this step. Return

**#f**from the callback to make Chipmunk ignore the collision this step or**#t**to process it normally. Additionally, you may override collision values using /(set! arbiter-fricion ...)/ /(set! arbiter-elasticity ...)/ or /(set! arbiter-surface-velocity ...)/ to provide custom friction, elasticity, or surface velocity values.*func*must have the form:(lambda (arbiter space data) ...)

`space-on-collision-postsolve``space`procedure`set!`(`space-on-collision-postsolve``space`)`func`setterTwo shapes are touching and their collision response has been processed. You can retrieve the collision impulse or kinetic energy at this time if you want to use it to calculate sound volumes or damage amounts.

*func*must have the form:(lambda (arbiter space data) ...)

`space-on-collision-seperate``space`procedure`set!`(`space-on-collision-seperate``space`)`func`setterTwo shapes have just stopped touching for the first time this step. To ensure that

*(begin)*and*(separate)*are always called in balanced pairs, it will also be called when removing a shape while its in contact with something or when deallocating the space.*func*must have the form:(lambda (arbiter space data) ...) -> boolean

`space-add-collision-handler``space``type-a``type-b``begin``presolve``postsolve``seperate``#!optional``data`procedureAdds callback functions for collision types

*type-a*and*type-b*see previous sections for the forms of the callback functions.

`space-remove-collision-handler``space``type-a``type-b`procedureRemove a collision handler for a given collision type pair.

`space-add-poststep-callback``space``func``key``#!optional``data`procedureRegister a default collision handler to be used when no specific collision handler is found. The space is given a default handler when created that returns

**#t**for all collisions in*(begin)*and*(presolve)*and does nothing in the*(postsolve)*and*(separate)*callbacks.

### Constraints

#### Properties

`constraint-a``constraint`procedure`constraint-b``constraint`procedureGetters for the two bodies the constraint is attached to.

`constraint-max-force``constraint`procedure`set!`(`constraint-max-force``constraint`)`value`setterThe maximum force that the constraint can use to act on the two bodies. Defaults to

*infinity*.

`constraint-error-bias``constraint`procedure`set!`(`constraint-error-bias``constraint`)`value`setterThe percentage of joint error that remains unfixed after a second. This works exactly the same as the collision bias property of a space, but applies to fixing error (stretching) of joints instead of overlapping collisions.

`constraint-max-bias``constraint`procedure`set!`(`constraint-max-bias``constraint`)`value`setterThe maximum speed at which the constraint can apply error correction. Defaults to

*infinity*.

`constraint-space``constraint`procedureGet the

*space*that constraint has been added to.

`constraint-impulse``constraint`procedureThe most recent impulse that constraint applied. To convert this to a force, divide by the timestep passed to

*(space-step)*. You can use this to implement breakable joints to check if the force they attempted to apply exceeded a certain threshold.

`space-userdata``space`procedure`set!`(`space-userdata``space`)`value`setterThis can be set to any value.

`constraint-userdata``constraint`procedure`set!`(`constraint-userdata``constraint`)`value`setterThis can be set to any value.

#### Pin Joints

##### Creation

<procedure>(create-pin-joint body-a body-b anchor-a anchor-b)<procedure> *a* and *b* are the two bodies to connect, and *anchor-a* and *anchor-b* are the anchor points on those bodies. The distance between the two anchor points is measured when the joint is created. If you want to set a specific distance, use the setter function to override it

##### Properties

#### Slide Joints

##### Creation

`create-slide-joint``body-a``body-b``anchor-a``anchor-b``min``max`procedure*a and*b*are the two bodies to connect,*anchor-a*and*anchor-b*are the anchor points on those bodies, and*min*and*max'' define the allowed distances of the anchor points.

##### Properties

`constraint-min``constraint`procedure`set!`(`constraint-min``constraint`)`value`setter

`constraint-max``constraint`procedure`set!`(`constraint-max``constraint`)`value`setter

#### Pivot Joints

##### Creation

`create-pivot-joint-with-pivot``body-a``body-b``pivot`procedure`create-pivot-joint-with-anchors``body-a``body-b``anchor-a``anchor-b`procedure*a*and*b*are the two bodies to connect, and pivot is the point in world coordinates of the pivot. Because the pivot location is given in world coordinates, you must have the bodies moved into the correct positions already. Alternatively you can specify the joint based on a pair of anchor points, but make sure you have the bodies in the right place as the joint will fix itself as soon as you start simulating the space.

##### Properties

#### Groove Joints

##### Creation

`create-groove-joint``body-a``body-b``groove-a``groove-b``anchor-b`procedureThe groove goes from 'groove-a

*to*groove-b*on*body-a*, and the pivot is attached to*anchor-b*on*body-b''. All coordinates are body local.

##### Properties

#### Damped Spring

##### Creation

`create-damped-spring``body-a``body-b``anchor-a``anchor-b``rest-length``stiffness``damping`procedureDefined much like a slide joint.

*rest-length*is the distance the spring wants to be,*stiffness*is the spring constant (Young’s modulus), and*damping*is how soft to make the damping of the spring.

##### Properties

#### Damped Rotary Spring

##### Creation

`create-damped-rotary-spring``body-a``body-b``anchor-a``anchor-b``rest-angle``stiffness``damping`procedureLike a damped spring, but works in an angular fashion.

*rest-angle*is the relative angle in radians that the bodies want to have,*stiffness*and*damping*work basically the same as on a damped spring.

##### Properties

#### Rotary Limit Joint

##### Creation

`create-rotary-limit-joint``body-a``body-b``min``max`procedureConstrains the relative rotations of two bodies.

*min*and*max*are the angular limits in radians. It is implemented so that it’s possible to for the range to be greater than a full revolution.

##### Properties

`constraint-min``constraint`procedure`set!`(`constraint-min``constraint`)`value`setter

`constraint-max``constraint`procedure`set!`(`constraint-max``constraint`)`value`setter

#### Ratchet Joint

##### Creation

`create-ratchet-joint``body-a``body-b``ratchet``phase`procedureWorks like a socket wrench.

*ratchet*is the distance between “clicks”,*phase*is the initial offset to use when deciding where the ratchet angles are.

##### Properties

#### Gear Joint

##### Creation

`create-gear-joint``body-a``body-b``phase``ratio`procedureKeeps the angular velocity ratio of a pair of bodies constant. 'ratio' is always measured in absolute terms. It is currently not possible to set the ratio in relation to a third body’s angular velocity. 'phase' is the initial angular offset of the two bodies.

##### Properties

#### Simple Motor

##### Creation

`create-simple-motor``body-a``body-b``rate`procedureKeeps the relative angular velocity of a pair of bodies constant.

*rate*is the desired relative angular velocity. You will usually want to set an force (torque) maximum for motors as otherwise they will be able to apply a nearly infinite torque to keep the bodies moving.

##### Properties

### Queries

**TODO** Documentation **TODO** Make something nice for passing layers

`space-bb-query``space``bb``layers``group``func``data`procedure**TODO**Make data optional