Interface myphysicslab.lab.engine2D.RigidBody
Provided By  

All Extended Interfaces  
All Known Implementations 
A 2D rigid body with a specified geometry that can experience collisions and contact forces. A RigidBody handles the geometry calculations for intersections and collisions, as well as energy and momentum calculations.
Noncolliding RigidBodys
There are cases where RigidBodys should not collide with each other. For example, when
there is a Joint between two RigidBodys. See #addNonCollide
and
#doesNotCollide
The Polygon class has a way of specifying a subset of Edges which do not collide with
another Polygon. See myphysicslab.lab.engine2D.Polygon#setNonCollideEdge
.
Instance Methods
this.addNonCollide( bodies ) → void
void
Adds to set of RigidBodys that do not collide with this body.
No collisions or contacts are generated between this body and the given bodies.
See #doesNotCollide
.
Parameters 


this.alignTo( p_body, p_world, opt_angle ) → void
void
Moves this body so that a certain point on this body is aligned to the given world
coordinates location; optionally sets the angle of this body by rotating around the
center of mass angle
radians counterclockwise from the body coordinates
orientation.
Parameters 
 

Throws 

this.bodyToWorld( p_body ) → myphysicslab.lab.util.Vector
myphysicslab.lab.util.Vector
Returns the world coordinates of the given body coordinates point, based on current position of this object.
Parameters 
 

Returns 

this.bodyToWorldTransform() → myphysicslab.lab.util.AffineTransform
myphysicslab.lab.util.AffineTransform
Returns the AffineTransform from body to world coordinates.
Parameters  None.  

Returns 

this.createCanvasPath( context ) → void
void
Creates the JavaScript Canvas path that represents the shape of this object
in the given Canvas context using body coordinates. Note that this calls
CanvasRenderingContext2D.beginPath()
which discards any currently defined path and
begins a new one. Also, this concept of 'path' is different from the path of Edges
that makes up a Polygon (though the Canvas path is created from those Polygon
paths).
Parameters 


this.doesNotCollide( body ) → boolean
boolean
Returns true if this body does not collide with the given body. See
#addNonCollide
.
Parameters 
 

Returns 

this.eraseOldCopy() → void
void
Erases the internal copy of this RigidBody. See #saveOldCopy
,
#getOldCopy
.
this.getAccuracy() → number
number
Returns the collision distance accuracy, a fraction between zero and one; when the
collision distance is within accuracy * targetGap
of the target gap distance, then
the collision is considered close enough to handle (apply an impulse).
Parameters  None.  

Returns 

this.getAngle() → number
number
Returns the counterclockwise angle of rotation of this body about its center of mass, in radians, relative to 'body coordinates' orientation.
Parameters  None.  

Returns 

this.getAngularVelocity() → number
number
Returns angular velocity of rotation of this body about its center of mass.
Parameters  None.  

Returns 

this.getBottomBody() → number
number
Returns vertical coordinate of bottommost point of this body, in body coordinates
Parameters  None.  

Returns 

this.getBottomWorld() → number
number
Returns vertical coordinate of bottommost point of this body, based on its current position and orientation, in world coordinates. This is approximate when the body has curved edges; because this looks at all the Vertex's of the body, and curved edges have a series of 'decorated' Vertexes on them which don't capture the exact nature of the geometric curve.
Parameters  None.  

Returns 

this.getBoundsBody() → myphysicslab.lab.util.DoubleRect
myphysicslab.lab.util.DoubleRect
Returns rectangle that contains this body in body coordinates.
Parameters  None.  

Returns 

this.getBoundsWorld() → myphysicslab.lab.util.DoubleRect
myphysicslab.lab.util.DoubleRect
Returns rectangle that contains this SimObject in world coordinates.
Parameters  None.  

Returns 

this.getCenterOfMassBody() → myphysicslab.lab.util.Vector
myphysicslab.lab.util.Vector
Returns the location of center of mass, in local body coordinates.
Parameters  None.  

Returns 

this.getCentroidBody() → myphysicslab.lab.util.Vector
myphysicslab.lab.util.Vector
Returns the center of the circle to use for proximity testing, in body coords. A
circle centered at this location with radius getCentroidRadius()
should enclose this
RigidBody. See #getCentroidRadius
, #getCentroidWorld
.
Parameters  None.  

Returns 

this.getCentroidRadius() → number
number
Returns the radius of the circle to use for proximity testing. A circle
centered at getCentroidBody()
with this radius should enclose this RigidBody.
See #getCentroidBody
, #getCentroidWorld
.
Parameters  None.  

Returns 

this.getCentroidWorld() → myphysicslab.lab.util.Vector
myphysicslab.lab.util.Vector
Returns the center of the circle to use for proximity testing, in world coords. A
circle centered at this location with radius getCentroidRadius()
should enclose this
RigidBody. See #getCentroidBody
, #getCentroidRadius
.
Parameters  None.  

Returns 

this.getDistanceTol() → number
number
Returns distance tolerance used to determine if this RigidBody is in contact with another RigidBody.
Parameters  None.  

Returns 

this.getDragPoints() → Array<myphysicslab.lab.util.Vector>
Array<myphysicslab.lab.util.Vector>
Returns the locations in body coordinates where a mouse can drag this object
Parameters  None.  

Returns 

this.getElasticity() → number
number
Returns the elasticity used when calculating collisions; a value of 1.0 means perfect elasticity where the kinetic energy after collision is the same as before (extremely bouncy), while a value of 0 means no elasticity (no bounce). A collision uses the lesser elasticity value of the two bodies involved.
Parameters  None.  

Returns 

this.getExpireTime() → number
number
Returns the expiration time, when this SimObject should be removed from the SimList. This is intended for temporary SimObjects that illustrate, for example, contact forces or collisions.
Parameters  None.  

Returns 

this.getHeight() → number
number
Returns the height of this body, when drawn in body coordinates.
Parameters  None.  

Returns 

this.getKineticEnergy() → number
number
Returns kinetic energy of this body
Parameters  None.  

Returns 

this.getLeftBody() → number
number
Returns horizontal coordinate of leftmost point of this body, in body coordinates
Parameters  None.  

Returns 

this.getLeftWorld() → number
number
Returns vertical coordinate of leftmost point of this body, based on its current position and orientation, in world coordinates. This is approximate when the body has curved edges; because this looks at all the Vertex's of the body, and curved edges have a series of 'decorated' Vertexes on them which don't capture the exact nature of the geometric curve.
Parameters  None.  

Returns 

this.getMass() → number
number
this.getMinHeight() → number
number
Returns the minimum height that this body's center of gravity can reach, used for potential energy calculations. Put another way: this is how low the center of gravity of this body can be when resting on the ground, and the ground is at height zero.
Parameters  None.  

Returns 

this.getName( opt_localized ) → string
string
Name of this SimObject, either the languageindependent name for scripting purposes or the localized name for display to user.
The languageindependent name should be the same as the English version but
capitalized and with spaces and dashes replaced by underscore,
see myphysicslab.lab.util.UtilityCore#toName
and #nameEquals
.
The name should give an idea of the role of the SimObject in the simulation. This allows us to to treat an object in a special way depending on its name. For example, we might use the name to decide what type of DisplayObject to create to represent the SimObject.
Parameters 
 

Returns 

this.getOldCopy() → myphysicslab.lab.engine2D.RigidBody
myphysicslab.lab.engine2D.RigidBody
Returns the most recent internal copy of this RigidBody.
Warning: The copy is not a fully functional RigidBody; it is used for collision
checking to see the position of bodies just before a collision occurred. See
#saveOldCopy
and #eraseOldCopy
. The RigidBody returned should only be used to
call position information methods such as #bodyToWorld
and #worldToBody
.
Parameters  None.  

Returns 

this.getPosition() → myphysicslab.lab.util.Vector
myphysicslab.lab.util.Vector
Returns the position of the center of mass of this object, in world coordinates.
Parameters  None.  

Returns 

this.getRightBody() → number
number
Returns horizontal coordinate of rightmost point of this body, in body coordinates
Parameters  None.  

Returns 

this.getRightWorld() → number
number
Returns vertical coordinate of rightmost point of this body, based on its current position and orientation, in world coordinates. This is approximate when the body has curved edges; because this looks at all the Vertex's of the body, and curved edges have a series of 'decorated' Vertexes on them which don't capture the exact nature of the geometric curve.
Parameters  None.  

Returns 

this.getTopBody() → number
number
Returns vertical coordinate of topmost point of this body, in body coordinates
Parameters  None.  

Returns 

this.getTopWorld() → number
number
Returns vertical coordinate of topmost point of this body, based on its current position and orientation, in world coordinates. This is approximate when the body has curved edges; because this looks at all the Vertex's of the body, and curved edges have a series of 'decorated' Vertexes on them which don't capture the exact nature of the geometric curve.
Parameters  None.  

Returns 

this.getVarsIndex() → number
number
Returns the index into the VarsList
for
this RigidBody. The VarsList contains 6 values for each RigidBody,
 xposition,
 xvelocity,
 yposition,
 yvelocity,
 angle,
 angular velocity
Parameters  None.  

Returns 

this.getVelocity( p_body ) → myphysicslab.lab.util.Vector
myphysicslab.lab.util.Vector
Returns velocity of the given point on this object. The point is specified in body coordinates, but the velocity is in world coordinates.
Parameters 
 

Returns 

this.getVelocityTol() → number
number
Returns velocity tolerance used to determine if this RigidBody is in contact with another RigidBody.
Velocity tolerance is set on each RigidBody, but we expect it to be the same for all RigidBodys. ImpulseSim 'owns' the velocity tolerance, it is merely passed along to the RigidBody because it is needed during collision finding and RigidBody has no way of finding ImpulseSim.
Note however that because Scrim is immutable, it always returns zero for velocity tolerance. In this case, use the velocity tolerance of the other nonScrim RigidBody involved in the collision.
Parameters  None.  

Returns 

this.getVerticesBody() → Array<myphysicslab.lab.util.Vector>
Array<myphysicslab.lab.util.Vector>
Returns the locations of vertices that define a bounding area, in body coordinates. The vertices might lie outside of the body: for example a circle could have vertices at corners of a bounding box.
Parameters  None.  

Returns 

this.getWidth() → number
number
Returns the width of this body, when drawn in body coordinates.
Parameters  None.  

Returns 

this.getZeroEnergyLevel() → (numbernull)
(numbernull)
Returns the vertical coordinate where the body has zero potential gravitational energy under standard constant gravity when the body's center of mass is at this vertical coordinate.
Parameters  None.  

Returns 

this.isMassObject() → boolean
boolean
Whether this implements the myphysicslab.lab.model.MassObject
interface.
Parameters  None.  

Returns 

this.momentAboutCM() → number
number
Returns moment of inertia about center of mass. This measures how much force is
needed to rotate the body about the center of mass. Note that this is the number set
via #setMomentAboutCM
multiplied by the mass of the body.
Parameters  None.  

Returns 

Returns the linear and angular momentum of this body. Angular momentum about a fixed point in space is defined as
I_cm vw k + r x m v_cm
where:
I_cm = moment about center of mass
vw = angular velocity
k = unit z vector,
r = vector from a fixed point to the center of mass (cm)
m = mass
v_cm = velocity of center of mass
cross product in the plane is (ax,ay,0) x (bx,by,0) = k(ax by  ay bx)
so we get
I_cm w + m (rx vy  ry vx)
take the fixed point to be the origin (0,0)
, so (rx,ry)
is center of mass.
Parameters  None.  

Returns 

this.nameEquals( name ) → boolean
boolean
Whether this SimObject has the given name, adjusting for the transformation to a
languageindependent form of the name, as is done by
myphysicslab.lab.util.UtilityCore#toName
.
Parameters 
 

Returns 

this.removeNonCollide( bodies ) → void
void
Removes from set of RigidBodys that do not collide with this body.
Parameters 


this.rotateBodyToWorld( v_body ) → myphysicslab.lab.util.Vector
myphysicslab.lab.util.Vector
Rotates a body coordinates vector to its orientation in world coordinates. The vector goes from the origin (0, 0), to the given point in body coordinates. The vector is rotated about the origin by the current angle of this body.
Parameters 
 

Returns 

this.rotateWorldToBody( v_world ) → myphysicslab.lab.util.Vector
myphysicslab.lab.util.Vector
Rotates a world coordinates vector to its orientation in body coordinates, the
inverse of #rotateBodyToWorld
method. The vector goes from the origin (0, 0), to
the given point in world coordinates. The vector is rotated about the origin by the
opposite of the current angle of this body.
Parameters 
 

Returns 

this.rotationalEnergy() → number
number
Returns the rotational energy of this body.
Defined to be: 0.5 * momentAboutCM * vw^2
where vw =
angular velocity.
Parameters  None.  

Returns 

this.saveOldCopy() → void
void
Makes an internal copy of the geometry of this RigidBody, which is used
for future collision checking. This copy becomes a record of the last location
of this object, so that collision checking can determine how the object moved
over the last time step. For example, a small object moving at high velocity
can pass through a narrow object in a single time step; there is then no
interpenetration of the two objects, but if you use the previous position of
the small fast object you can see that it has passed through the narrow object.
See #getOldCopy
, #eraseOldCopy
.
this.setAccuracy( value ) → void
void
Sets the collision distance accuracy, a fraction between zero and one; when the
collision distance is within accuracy * targetGap
of the target gap distance, then
the collision is considered close enough to handle (apply an impulse).
Parameters 
 

Throws 

this.setAngle( angle ) → void
void
Sets the angle in radians of counterclockwise rotation of this object around its
center of mass. Angle zero draws the object in the same orientation as in body
coordinates. Angle Math.PI/2
rotates the body clockwise 90 degrees from its
body coordinates orientation.
Parameters 


this.setAngularVelocity( angular_velocity ) → void
void
Sets angular velocity of rotation of this body about its center of mass.
Parameters 


this.setCenterOfMass( x_body, y_body ) → void
void
this.setDistanceTol( value ) → void
void
Sets distance tolerance to use to determine if this RigidBody is in contact with another RigidBody.
Parameters 


this.setDragPoints( dragPts ) → void
void
Sets the locations where a mouse can drag this object, in body coordinates.
Parameters 


this.setElasticity( value ) → void
void
Sets the elasticity used when calculating collisions; a value of 1.0 means perfect elasticity where the kinetic energy after collision is the same as before (extremely bouncy), while a value of 0 means no elasticity (no bounce). A collision uses the lesser elasticity value of the two bodies involved.
Parameters 


this.setExpireTime( time ) → myphysicslab.lab.model.SimObject
myphysicslab.lab.model.SimObject
Sets the expiration time, when this SimObject should be removed from the SimList. This is intended for temporary SimObjects that illustrate, for example, contact forces or collisions.
Parameters 
 

Returns 

this.setMass( mass ) → myphysicslab.lab.model.MassObject
myphysicslab.lab.model.MassObject
Set the mass of this MassObject.
Parameters 
 

Returns 

this.setMinHeight( minHeight ) → void
void
Sets the minimum height that this body can reach, used for potential energy calculations. That is, how low can the center of gravity of this body go?
Parameters 


this.setMomentAboutCM( moment ) → void
void
Sets the moment of inertia about the center of mass for this body divided by the
mass of this body. The moment of inertia, Icm
, measures how much force is needed to
rotate the body about the center of mass. Icm
depends on the shape of the object and
how mass is distributed. For a thin rectangular plate:
Icm = mass * (width^2 + height^2) / 12
For a thin circular plate:
Icm = mass * radius^2 / 2
Note that #momentAboutCM
returns the number specified here multiplied by the
mass of the body.
Parameters 


this.setPosition( loc_world, angle ) → void
void
Moves this body so that the center of mass is at the given world coordinates location; rotates this body counterclockwise about center of mass from 'body coordinates' orientation by the given angle in radians.
Note that when setting the mass on a RigidBody you should also set accordingly the
moment about center of
mass
.
Parameters 


this.setVelocity( velocity_world, angular_velocity ) → void
void
Set the linear velocity of this objects's center of mass, and (optional) angular velocity of rotation about the objects's center of mass. A MassObject keeps track of its current velocity as a convenience for various calculations.
Parameters 


this.setVelocityTol( value ) → void
void
Sets velocity tolerance to use to determine if this RigidBody is in contact with another RigidBody
Parameters 


this.setZeroEnergyLevel( height ) → myphysicslab.lab.model.MassObject
myphysicslab.lab.model.MassObject
Sets the vertical coordinate where the body has zero potential gravitational energy under standard constant gravity when the body's center of mass is at this vertical coordinate.
Parameters 
 

Returns 

this.similar( obj, opt_tolerance ) → boolean
boolean
Returns true if the given SimObject is similar to this SimObject for display
purposes. SimObjects are similar when they are the same type and nearly the same size
and location. Mainly used when showing forces  to avoid adding too many objects
to the display. See myphysicslab.lab.model.SimList#getSimilar
.
Parameters 
 

Returns 

this.toStringShort() → string
string
Returns a minimal string representation of this object, usually giving just identity information like the class name and name of the object.
For an object whose main purpose is to represent another Printable object, it is
recommended to include the result of calling toStringShort
on that other object. For
example, calling toStringShort()
on a DisplayShape might return something like
this:
DisplayShape{polygon:Polygon{'chain3'}}
Parameters  None.  

Returns 

this.translationalEnergy() → number
number
Returns the translational energy of this body.
Defined to be: 0.5*mass*(vx^2 + vy^2)
where
vx =
horizontal velocity, and
vy =
vertical velocity.
Parameters  None.  

Returns 

this.worldToBody( p_world ) → myphysicslab.lab.util.Vector
myphysicslab.lab.util.Vector
Returns the body coordinates of the given world coordinates point, based on current position of this object.
Parameters 
 

Returns 
