|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--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 set boundaries
to the position. The body can be either corporeal or ethereal, which
determines whether it can collide or not (i.e., only the corporeal bodies
can collide).
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 . |
Vector2 |
getAcceleration()
Returns the acceleration of the body. |
double |
getMass()
Returns the mass of the body. |
Universe |
getOwner()
Returns the owner of the body or null if
the body has no owner. |
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. |
boolean |
isColliding(Body other)
Returns whether the body collides with the body other . |
boolean |
isCorporeal()
Returns true if the body is corporeal or
false if the body is ethereal. |
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 |
setCorporeal()
Sets the body to be corporeal. |
void |
setEthereal()
Sets the body to be ethereal. |
void |
setMass(double m)
Sets the mass of the body to m . |
void |
setOwner(Universe u)
Sets the universe that owns the body to u . |
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 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 Universe getOwner()
null
if
the body has no owner.public void setOwner(Universe u)
u
.public boolean isCorporeal()
true
if the body is corporeal or
false
if the body is ethereal.public void setCorporeal()
isColliding(Body)
public void setEthereal()
isColliding(Body)
public void advance(double dt)
dt
seconds and
updates the position and velocity of the body accordingly.
The new horizontal position x' is calculated from the equation
x' = ½axt² +
vxt + x, and the vertical
position is calculated accordingly. The new horizontal velocity
vx' is calculated from the equation
vx' =
axt + vx, and the vertical
velocity is calculated accordingly.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)
,
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.isOverlapping(Body)
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |