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 counter-clockwise from the body coordinates
orientation.
the point on this body to be
aligned to the new p_world
location, in body coordinates
the world coordinates location to
move the specified p_body
point to
Optional
opt_angle: numberthe angle in radians to rotate this body counter-clockwise from 'body coordinates' orientation; if not specified then leave the angle as is.
if this MassObject is immoveable
Returns the world coordinates of the given body coordinates point, based on current position of this object.
the point, in body coordinates
the point in world coordinates
Returns the AffineTransform from body to world coordinates.
the AffineTransform from body to world coordinates.
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).
the CanvasRenderingContext2D to create the path in
Returns the counter-clockwise angle of rotation of this body about its center of mass, in radians, relative to 'body coordinates' orientation.
the counter-clockwise angle of rotation of this body about its center of mass, in radians, relative to 'body coordinates' orientation
Returns vertical coordinate of bottom-most 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.
vertical coordinate of bottom-most point of this body, in world coordinates
Returns rectangle that contains this body in body coordinates.
rectangle that contains this body in body coordinates
Returns a rectangle that contains this SimObject in world coordinates.
rectangle that contains this SimObject in world coordinates
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
MassObject. See getCentroidRadius,
getCentroidWorld.
the center of the circle to use for proximity testing, in body coords
Returns the radius of the circle to use for proximity testing. A circle
centered at getCentroidBody()
with this radius should enclose this MassObject.
See getCentroidBody, getCentroidWorld.
the radius of the circle to use for proximity testing.
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
MassObject. See getCentroidBody,
getCentroidRadius.
the center of the circle to use for proximity testing, in world coords
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.
the expiration time, in time frame of the Simulation clock
Returns vertical coordinate of left-most 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.
vertical coordinate of left-most point of this body, in world coordinates
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.
the minimum height this body can reach.
Name of this SimObject, either the language-independent name for scripting purposes or the localized name for display to user.
The language-independent name should be the same as the English version but capitalized and with spaces and dashes replaced by underscore, see Util.toName, 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.
Optional
opt_localized: booleantrue
means return the localized version of the name;
default is false
which means return the language independent name.
name of this SimObject
Returns vertical coordinate of right-most 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.
vertical coordinate of right-most point of this body, in world coordinates
Returns vertical coordinate of top-most 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.
vertical coordinate of top-most point of this body, in world coordinates
Returns velocity of the given point on this object. The point is specified in body coordinates, but the velocity is in world coordinates.
Optional
p_body: GenericVectorthe point to find the velocity of, in body coordinates; if undefined, then center of mass is used
the velocity of the given point, in world coordinates
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.
the vertical world coordinate where this body has zero potential energy; or null to use the default zero energy level
Whether this implements the MassObject interface.
Whether this implements the MassObject interface.
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.
moment of inertia about center of mass
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.
the momentum of this body as array containing horizontal, vertical and angular momentum in that order.
Whether this SimObject has the given name, adjusting for transformation to the language-independent form of the name, as is done by Util.toName.
the English or language-independent version of the name
whether this SimObject has the given name (adjusted to language-independent form)
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.
the vector, in body coordinates
the rotated vector in world coordinates.
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.
the the vector to be rotated, in world coordinates
the rotated vector in body coordinates.
Sets the angle in radians of counter-clockwise 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.
the angle in radians to rotate this object counter-clockwise about its center of mass from 'body coordinates' orientation
Sets location of center of mass, in body coordinates.
the position of the center of mass, in body coordinates.
Sets the locations where a mouse can drag this object, in body coordinates.
the locations where a mouse can drag this object, in body coordinates
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.
the expiration time, in time frame of the Simulation clock
Set the mass of this MassObject.
Note that when setting the mass on a MassObject you should also set accordingly the moment of inertia about center of mass, see setMomentAboutCM.
the mass of this MassObject
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.
the moment of inertia about the center of mass for this body divided by the mass of this body
Moves this body so that the center of mass is at the given world coordinates location; rotates this body counter-clockwise about center of mass from 'body coordinates' orientation by the given angle in radians.
the location in world coordinates
Optional
angle: numberthe angle in radians to rotate this body counter-clockwise from 'body coordinates' orientation; if undefined then angle is not changed
Set the linear velocity of this objects's center of mass, and (optional) angular velocity of rotation about the objects's center of mass.
the velocity in world coordinates/second
Optional
angular_velocity: numberthe angular velocity, in radians/second, with positive meaning counter-clockwise rotation about the body's center of mass; if undefined, then angular velocity is not changed
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.
Optional
height: numberthe vertical world coordinate where this body has zero
potential energy; NaN
means to use default level;
undefined
means use the body's current vertical location is used
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 SimList.getSimilar.
the SimObject to compare to
Optional
opt_tolerance: numberthe amount the object components can differ by
true if this SimObject is similar to obj
for display purposes
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'}}
a minimal string representation of this object.
Returns the body coordinates of the given world coordinates point, based on current position of this object.
the point, in world coordinates
the point in body coordinates
Generated using TypeDoc
An object that has mass, position, velocity and a local coordinate system, and can potentially be dragged by the user.
Body Coordinates
See also the 2D Physics Engine Overview section about Body Coordinates, and CoordType.
Each MassObject has its own local coordinate system called body coordinates, distinct from world coordinates (also called simulation coordinates). There are methods for converting between body and world coordinates, see bodyToWorld and worldToBody.
When the MassObject is positioned in world coordinates, we specify the location of the center of mass and the rotation around the center of mass. The rotation is with respect to body coordinates. A rotation of
pi/2
would rotate the MassObject 90 degrees counter clockwise from its starting position.Drag Points
A MassObject can have one or more drag points specified to which we typically attach a Spring for the user to be able to move the object. See setDragPoints.
See EventHandler and SimController for information about how MassObjects are used for user interface interactions like dragging an object.
Potential Energy
For simulations where gravity operates in the vertical direction, there are methods here to help calculate the potential energy of a MassObject. See setZeroEnergyLevel, getZeroEnergyLevel, getMinHeight, and EnergyInfo.