|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--fi.utu.cs.physics.Particle | +--fi.utu.cs.physics.Body
A moving physical body with mass and dimensionality. The outline of
the body is approximated with a bounding circle of a given radius,
which is used in detecting overlaps. The body can be owned by
an instance of the class Universe
, which may impose limits
to the position.
Universe
Constructor Summary | |
protected |
Body(double m,
double r)
Constructs a body with the mass m and
the radius r . |
protected |
Body(double m,
double r,
Point2 p)
Constructs a body with the mass m ,
the radius r and the position p .
|
protected |
Body(double m,
double r,
Point2 p,
Vector2 v)
Constructs a body with the mass m ,
the radius r , the position p
and the velocity v . |
protected |
Body(double m,
double r,
Point2 p,
Vector2 v,
Vector2 a)
Constructs a body with the mass m ,
the radius r , the position p ,
the velocity v and the acceleration a .
|
Method Summary | |
void |
advance(double dt)
Advances the time dt seconds and
updates the position and velocity of the body accordingly. |
void |
elasticCollision(Body other)
Realizes an elastic collision for both the body and the body other . |
Point2 |
futurePosition(double dt)
Returns the position of the body after seconds. |
Vector2 |
futureVelocity(double dt)
Returns the velocity of the body after seconds. |
Vector2 |
getAcceleration()
Returns the acceleration of the body. |
double |
getMass()
Returns the mass of the body. |
Point2 |
getPosition()
Returns the position of the body. |
double |
getRadius()
Returns the radius of the bounding circle. |
Vector2 |
getVelocity()
Returns the velocity of the body. |
void |
inelasticCollision(Body other)
Realizes an inelastic collision for both the body and the body other . |
boolean |
isColliding(Body other)
Returns whether the body collides with the body other . |
boolean |
isOverlapping(Body other)
Checks whether the body overlaps the body other . |
void |
setAcceleration(double ax,
double ay)
Sets the acceleration of the body. |
void |
setAcceleration(Vector2 a)
Sets the acceleration of the body to a . |
void |
setMass(double m)
Sets the mass of the body to m . |
void |
setPosition(double x,
double y)
Sets the position of the body. |
void |
setPosition(Point2 p)
Sets the position of the body to p . |
void |
setRadius(double r)
Sets the radius of the bounding circle to r . |
void |
setVelocity(double vx,
double vy)
Sets the velocity of the body. |
void |
setVelocity(Vector2 v)
Sets the velocity of the body to v . |
java.lang.String |
toString()
Returns a string that contains the values of the attributes. |
Methods inherited from class fi.utu.cs.physics.Particle |
addCollisionNotification, clearCollisionNotifications, getOwner, isCollisionNotified, isCollisionNotified, isCorporeal, removeCollisionNotification, setCorporeal, setEthereal, setOwner |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
protected Body(double m, double r)
m
and
the radius r
. The body resides in the
origin and has a zero velocity and a zero acceleration.
The body is corporeal and has no owner.
protected Body(double m, double r, Point2 p)
m
,
the radius r
and the position p
.
The body has a zero velocity and a zero acceleration.
The body is corporeal and has no owner.
protected Body(double m, double r, Point2 p, Vector2 v)
m
,
the radius r
, the position p
and the velocity v
. The body has a
zero acceleration.
The body is corporeal and has no owner.
protected Body(double m, double r, Point2 p, Vector2 v, Vector2 a)
m
,
the radius r
, the position p
,
the velocity v
and the acceleration a
.
The body is corporeal and has no owner.
Method Detail |
public double getMass()
public double getRadius()
public Point2 getPosition()
public Vector2 getVelocity()
public Vector2 getAcceleration()
public void setMass(double m)
m
.
public void setRadius(double r)
r
.
public void setPosition(double x, double y)
x
- The x coordinate of the position.y
- The y coordinate of the position.setPosition(Point2)
public void setPosition(Point2 p)
p
.
public void setVelocity(double vx, double vy)
vx
- The horizontal velocity.vy
- The vertical velocity.setVelocity(Vector2)
public void setVelocity(Vector2 v)
v
.
public void setAcceleration(double ax, double ay)
ax
- The horizontal acceleration.ay
- The vertical acceleration.setAcceleration(Vector2)
public void setAcceleration(Vector2 a)
a
.
public void advance(double dt)
dt
seconds and
updates the position and velocity of the body accordingly.
futurePosition(double)
,
futureVelocity(double)
public Point2 futurePosition(double dt)
advance(double)
,
futureVelocity(double)
public Vector2 futureVelocity(double dt)
advance(double)
,
futurePosition(double)
public boolean isOverlapping(Body other)
other
. An overlap occurs if the distance
between the centers of the bodies is smaller than
the sum of the respective radii.
isColliding(Body)
public boolean isColliding(Body other)
other
. A collision occurs when the bodies
overlap each other for the first time (i.e., at the
moment of impact) and both bodies are corporeal.
isOverlapping(Body)
,
Particle.isCorporeal()
public void elasticCollision(Body other)
other
. The linear momentum and kinetic
energy of the bodies is conserved in the collision.
The new velocity v1' is calculated from
the equation
v1' =
v1 (m1 - m2)
/ (m1 + m2) +
v2 2m2 /
(m1 + m2)
and v2' from the equation
v2' =
v1 2m1 /
(m1 + m2) +
v2 (m2 - m1)
/ (m2 + m1).
The new acceleration a1' is calculated from
from the equation
a1' =
m2a2 / m1,
and the new acceleration a2' is
calculated accordingly.
The collision is realized regardless whether the bounding circles
ovelap or not.
elasticCollision
in class Particle
inelasticCollision(Body)
,
isOverlapping(Body)
public void inelasticCollision(Body other)
other
. The linear momentum of the bodies is
conserved but kinetic energy is lost.
inelasticCollision
in class Particle
elasticCollision(Body)
,
isOverlapping(Body)
public java.lang.String toString()
toString
in class Particle
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |