Class myphysicslab.lab.engine2D.Polygon
Provided By  

Extends  
All Implemented Interfaces 
A RigidBody made of connected Edges and Vertexes.
See 2D Physics Engine Overview about the rigid body physics engine.
Body Coordinates
For explanation of body vs. world coordinates see
Body Coordinates,
myphysicslab.lab.model.MassObject
and myphysicslab.lab.model.CoordType
.
Methods that return a location often have names ending with either 'body' or 'world' to indicate the coordinate system. Similarly, parameters of methods often end with 'body' or 'world'.
Structure of a Polygon
A Polygon consists of a set of connected Edges, which together form one or more paths. A Polygon can have more than one path, for example a donut shape would have 2 paths: one for the outer Edge and one for the inner Edge.
A path in a Polygon consists of a linked list of Edges and Vertexes:
An Edge has a starting and ending Vertex, and a Vertex has a previous and next Edge. So we can follow a path from the starting Vertex until returning again to the starting Vertex when the path is then closed.
The list of paths is simply a list of starting Vertexes. Each path wraps around to its starting Vertex to form a closed loop. A path must have at least one Vertex and one Edge.
A path is used when drawing the Polygon. For collision handling, the collection of Edges and Vertexes are what matters, how they are linked into a path is irrelevant.
The Edges in a Polygon are stored in an array, and Edges can be referred to by their
index in this array, see #getEdges
and
myphysicslab.lab.engine2D.Edge#getIndex
.
The list of Vertexes may include automatically generated 'midpoint Vertexes' for curved
Edges. These Vertexes are added to give better collision detection for curved Edges. See
myphysicslab.lab.engine2D.Vertex
about endpoint vs. midpoint Vertexes.
Creating a Polygon

First create a Polygon with the constructor; it has no Vertexes or Edges.

Call
#startPath
to begin making a path. You can start with a single Vertex or an Edge. 
Use
#addEdge
as many times as desired to add Edges. Or use the shortcut methods#addStraightEdge
,#addCircularEdge
or#addCircularEdge2
. 
(optional) Use
#closePath
if you want to add another path withstartPath
. 
Call
#finish
which will close the current path and calculate the centroid for the Polygon.
Note that just creating an Edge can add it to the existing linked list of Vertexes
and Edges being formed in the currently open path. The #addEdge
method completes
the process of adding the Edge to the Polygon.
For examples of creating a Polygon see myphysicslab.lab.engine2D.Shapes
.
Centroids & Proximity Testing
We need a quick way to know if objects are close enough to warrant the more expensive tests that are done to find collisions and contacts. To this end, we find the smallest circle that encloses the object. The center of this circle is the 'centroid' or geometric center of the object. The radius is the "centroid radius".
There is a similar centroid and centroid radius for each Edge, which gives the smallest
circle that encloses that Edge. We use a cache to keep the world coordinates of the
centroid of each Edge, to avoid the cost of repeatedly calling the bodyToWorld
method.
See #getEdgeCentroidWorld
.
Some of the proximity tests can be found in
myphysicslab.lab.engine2D.UtilityCollision#checkVertexes
. Of note is that we expand the
centroid radius by the distance that the Vertex has travelled during the current time
step. And that we use the distance squared in these tests, to avoid the computational
cost of the square root function.
Special Edge for Proximity Testing
Walls are a special case for proximity testing. Because they are typically long and thin, their proximity circle is huge compared to the wall object; and so the proximity test fires many false positives.
To remedy this, we allow specifying a 'special edge' via #setSpecialEdge
which
changes how the proximity testing is done for this object.
When there is a special edge (there can only be one per object), then the proximity test still looks at the distance between the centroid of each object, but now only the portion of that distance that is normal to the special edge. Also, a special centroid radius is defined for the object that is used in this proximity test. For a wall, this special centroid radius is half of the (short) width of the wall object.
Only the special edge is tested for collisions, so care should be taken to avoid objects being able to collide into any of the nonspecial edge walls.
Old Copy Is Used For Collision Detection
A Polygon keeps a copy of its previous state before the last time step of the
differential equation solver. The copy is used for collision detection, to determine how
a collision may have happened; for example whether a Vertex crossed over an Edge during
the last time step. The copy is not a fully functional Polygon, it is only useful for
the purposes of looking at the previous location and orientation of the body. See
#saveOldCopy
, #getOldCopy
, and #eraseOldCopy
.
Minimum Height
The minimum height of a Polygon is used for potential energy calculations, see
myphysicslab.lab.engine2D.Polygon#getMinHeight
.
The minimum height can be explicitly set for each Polygon, see #setMinHeight
.
If it is not set, the method #getMinHeight
will try
to determine the minumum height by calculating the smallest distance between the center
of mass and the body's Edges.
Some cautions about getMinHeight
:

The
getMinHeight
calculation can fail for more complicated shapes or when the center of mass is outside of the body. 
The
getMinHeight
calculation will be incorrect for a circle or oval when the center of mass is not on one of the axes of the circle/ellipse. 
The minimum height is cached, and should be recalculated if the center of mass changes. To do so, call
setMinHeight(NaN)
and the next timegetMinHeight
is called it will recalculate.
new Polygon( opt_name, opt_localName )
Parameters 


Instance Methods
this.addCircularEdge( p_body, center_body, clockwise, outsideIsOut ) → myphysicslab.lab.engine2D.CircularEdge
myphysicslab.lab.engine2D.CircularEdge
Adds a CircularEdge to the open path of this Polygon, starting at the current last
Vertex and ending at the given point, with the given center for the circular arc, and
moving clockwise or counterclockwise from the start Vertex. See
#lastOpenVertex
and #startPath
.
Parameters 
 

Returns 
 
Throws 

this.addCircularEdge2( p_body, radius, aboveRight, clockwise, outsideIsOut ) → myphysicslab.lab.engine2D.CircularEdge
myphysicslab.lab.engine2D.CircularEdge
Adds a CircularEdge to the open path of this Polygon, starting at the current last
Vertex and ending at the given point, with the given radius for the circular arc, and
moving clockwise or counterclockwise from the start Vertex. See
#lastOpenVertex
and #startPath
.
The center point is calculated from the two endpoints, the radius, the direction
(clockwise or counterclockwise), and the aboveRight
parameter. The center is at the
vertex of an isoceles triangle with edges of length radius
and base being the line
from the last point to p_body
.
There are two choices for where to put the center in relation to the line connecting the
two given points: either above or below the line. The aboveRight
parameter specifies
which choice to make. For a vertical connecting line, the choice is right or left of the
line.
Parameters 
 

Returns 
 
Throws 

this.addEdge( edge ) → void
void
Adds the Edge to current open path. The start Vertex of the Edge must
match the end Vertex of last Edge in open path as given by #lastOpenVertex
.
See #startPath
.
Parameters 
 

Throws 

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
.
Specified by  

Parameters 

this.addStraightEdge( p_body, outsideIsUp ) → myphysicslab.lab.engine2D.StraightEdge
myphysicslab.lab.engine2D.StraightEdge
Adds a StraightEdge to the open path of this Polygon, starting at the current last
Vertex and ending at the given point. See #lastOpenVertex
and
#startPath
.
Parameters 
 

Returns 
 
Throws 

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.
Overrides  

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.
Overrides  

Parameters 
 
Returns 

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

Parameters  None.  
Returns 

this.checkCollision( collisions, body, time ) → void
void
Checks if this Polygon has a collision or contact with another Polygon, if so adds a new RigidBodyCollision to the list of collisions.
Parameters 


this.closePath() → boolean
boolean
Closes the current path of the Polygon. Connects the starting Vertex of the open
path with the last Edge of the open path. See #startPath
, #lastOpenEdge
,
and #getStartVertex
.
Parameters  None.  

Returns 
 
Throws 

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).
Overrides  

Specified by  
Parameters 

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

Parameters 
 
Returns 

this.eraseOldCopy() → void
void
Erases the internal copy of this RigidBody. See #saveOldCopy
,
#getOldCopy
.
Specified by  

Parameters  None. 
this.findCentroid() → myphysicslab.lab.util.Vector
myphysicslab.lab.util.Vector
Finds the geometric center or 'centroid' of this Polygon, which is the point that minimizes the distance to all Vertexes.
Parameters  None.  

Returns 

this.finish() → void
void
Finish the construction of the Polygon. Close any open path; calculate the bounding box, centroid, centroid radius; set to default values the center of mass, moment, and drag point.
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).
Specified by  

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.
Overrides  

Parameters  None.  
Returns 

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

Parameters  None.  
Returns 

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

Specified by  
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.
Overrides  

Parameters  None.  
Returns 

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

Parameters  None.  
Returns 

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

Parameters  None.  
Returns 

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

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
.
Overrides  

Specified by  
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
.
Overrides  

Specified by  
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
.
Overrides  

Parameters  None.  
Returns 

this.getClassName() → string
string
Returns name of class of this object.
Overrides  

Parameters  None.  
Returns 

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

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
Overrides  

Parameters  None.  
Returns 

this.getEdgeCentroidWorld( index ) → (myphysicslab.lab.util.Vectornull)
(myphysicslab.lab.util.Vectornull)
Returns centroid of an Edge, in world coords. This implements a cache to avoid
costs of repeatedly calling bodyToWorld()
on the centroid. The cache is stored on
Polygon because it corresponds to the current position of the Polygon.
See myphysicslab.lab.engine2D.Edge#getCentroidWorld
.
Parameters 
 

Returns 

this.getEdges() → Array<myphysicslab.lab.engine2D.Edge>
Array<myphysicslab.lab.engine2D.Edge>
Returns clone of the list of edges of this body.
Parameters  None.  

Returns 

this.getEdges_() → Array<myphysicslab.lab.engine2D.Edge>
Array<myphysicslab.lab.engine2D.Edge>
Returns the actual list of edges of this body, for engine2D package use only.
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.
Specified by  

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.
Overrides  

Parameters  None.  
Returns 

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

Parameters  None.  
Returns 

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

Parameters  None.  
Returns 

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

Specified by  
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.
Overrides  

Parameters  None.  
Returns 

this.getMass() → number
number
Returns the mass of this object.
Overrides  

Parameters  None.  
Returns 

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.
Overrides  

Specified by  
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.
Overrides  

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
.
Specified by  

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.
Overrides  

Parameters  None.  
Returns 

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

Specified by  
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.
Overrides  

Parameters  None.  
Returns 

this.getSpecialNormalWorld() → (myphysicslab.lab.util.Vectornull)
(myphysicslab.lab.util.Vectornull)
The normal vector (if any) used in the special edge proximity test. When a special
edge has been specified, that Edge that takes priority for collision handling, as in a
wall object, and this method returns the normal vector to use for special proximity
testing. Otherwise this returns null
and regular proximity testing is done. A normal
is a unitlength Vector that is perpendicular to an Edge. This maintains a cache to
avoid computational costs.
See Special Edge for Proximity Testing.
See #setSpecialEdge
.
Parameters  None.  

Returns 

this.getStartVertex() → (myphysicslab.lab.engine2D.Vertexnull)
(myphysicslab.lab.engine2D.Vertexnull)
Returns starting Vertex for current open path, or null
if there is no open path.
See #startPath
.
Parameters  None.  

Returns 

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

Specified by  
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.
Overrides  

Parameters  None.  
Returns 

this.getVarName( index, localized ) → string
string
Returns the name of the specified variable.
Parameters 
 

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
Specified by  

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.
Overrides  

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.
Specified by  

Parameters  None.  
Returns 

this.getVertexes_() → Array<myphysicslab.lab.engine2D.Vertex>
Array<myphysicslab.lab.engine2D.Vertex>
Returns the list of Vertexes of this body, for engine2D package use only.
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.
Overrides  

Specified by  
Parameters  None.  
Returns 

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

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.
Overrides  

Parameters  None.  
Returns 

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

Parameters  None.  
Returns 

this.lastOpenEdge() → (myphysicslab.lab.engine2D.Edgenull)
(myphysicslab.lab.engine2D.Edgenull)
Returns last Edge in current open path or null
when there is no last Edge or no
open path.
Parameters  None.  

Returns 

this.lastOpenVertex() → myphysicslab.lab.engine2D.Vertex
myphysicslab.lab.engine2D.Vertex
Returns last Vertex in current open path. This is the ending Vertex of the last Edge
in the linked list of Edges that makes up the open path. If there is no Edge in the path
then this is the starting Vertex, see #startPath
and #getStartVertex
.
Parameters  None.  

Returns 
 
Throws 

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.
Overrides  

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.
Overrides  

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
.
Overrides  

Parameters 
 
Returns 

this.nonCollideEdge( edge ) → boolean
boolean
Whether this Polygon can collide with an Edge or Vertex of another Polygon.
Returns true
when passing null
for the Edge.
Parameters 
 

Returns 

this.printAll() → void
void
Prints all edges and Vertexes to console for debugging.
this.probablyPointInside( p_body ) → boolean
boolean
Returns true if the given body coords point is probably inside this polygon.
WARNING: For debugging only. Does not work for complex (nonconvex) shapes.
Parameters 
 

Returns 

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

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.
Overrides  

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.
Overrides  

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.
Overrides  

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
.
Specified by  

Parameters  None. 
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).
Specified by  

Parameters 

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.
Overrides  

Parameters 

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

Parameters 

this.setCenterOfMass( x_body, y_body ) → void
void
this.setCentroid( centroid_body ) → myphysicslab.lab.engine2D.Polygon
myphysicslab.lab.engine2D.Polygon
Sets the center of the circle to use for proximity testing and also calculates the
radius of the circle. A circle centered at this centroid with radius
getCentroidRadius()
should encompass this Polygon.
Parameters 
 

Returns 
 
Throws 

this.setDistanceTol( value ) → void
void
Sets distance tolerance to use to determine if this RigidBody is in contact with another RigidBody.
Specified by  

Parameters 

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

Parameters 

this.setEdgeCentroidWorld( index, v ) → void
void
Set centroid of an Edge, in world coords. This implements a cache to avoid
costs of repeatedly calling bodyToWorld()
on the centroid. The cache is stored on
Polygon because it corresponds to the current position of the Polygon.
See myphysicslab.lab.engine2D.Edge#getCentroidWorld
.
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.
Specified by  

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.
Overrides  

Parameters 
 
Returns 

this.setMass( mass ) → myphysicslab.lab.engine2D.Polygon
myphysicslab.lab.engine2D.Polygon
Set the mass of this Polygon.
Overrides  

Specified by  
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?
Overrides  

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.
Overrides  

Parameters 

this.setNonCollideEdge( nonCollideSet ) → void
void
Specifies that this Polygon does not collide with the given set of Edges of
other Polygons; replaces any existing noncollide EdgeSet. No collisions or contacts
are generated between this Polygon and the Edges in the given EdgeSet.
Use this when some parts of a Polygon DO interact. If NO parts interact then
see myphysicslab.lab.engine2D.RigidBody#addNonCollide
.
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
.
Overrides  

Specified by  
Parameters 

this.setSpecialEdge( edgeIndex, radius ) → void
void
Sets which Edge takes priority for collision handling, as in a wall object. Can only
be called on a rectangular Polygon.
Sets the centroid radius of the nonspecial edges on this Polygon to zero, which makes
all those nonspecial edges inoperative for collision detection purposes.
See Special Edge for Proximity Testing.
See #getSpecialNormalWorld
.
Parameters 
 

Throws 

this.setVarsIndex( index ) → void
void
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.
Overrides  

Parameters 

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

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.
Overrides  

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
.
Overrides  

Parameters 
 
Returns 

this.startPath( vertexOrEdge ) → void
void
Start creating a path in this Polygon at the given Vertex or Edge.
Parameters 


this.toString() → string
string
Overrides  

Parameters  None.  
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'}}
Overrides  

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.
Overrides  

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.
Overrides  

Parameters 
 
Returns 

Instance Properties
this.angle_ → number
number
this.angular_velocity_ → number
number
this.cm_body_ → myphysicslab.lab.util.Vector
myphysicslab.lab.util.Vector
this.cosAngle_ → number
number
this.dragPts_ → Array<myphysicslab.lab.util.Vector>
Array<myphysicslab.lab.util.Vector>
No information.
this.loc_world_ → myphysicslab.lab.util.Vector
myphysicslab.lab.util.Vector
this.mass_ → number
number
this.minHeight_ → number
number
the minimum value the vertical position of this body can take on, used in energy calculations
Overrides 

this.moment_ → number
number
moment about center of mass divided by mass
this.sinAngle_ → number
number
this.velocity_ → myphysicslab.lab.util.Vector
myphysicslab.lab.util.Vector
this.zeroEnergyLevel_ → (numbernull)
(numbernull)
the vertical coordinate where this body has zero potential energy; or null to use the default zero energy level.
Static Properties
Polygon.ID → number
number
Counter used for naming Polygons.
No information.
Type Definitions
Set of internationalized strings.