|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Observable | +--fi.utu.cs.physics.Universe
A universe comprising a collection of Body
objects.
The type of the universe can be infinite, finite or toroid.
Classes implementing the Observer
interface can
observe the universe for detecting collisions between the corporeal bodies;
an instance of the CollisionPair
inner class is
submitted to the observers.
Particle
,
Body
,
Boundary
Nested Class Summary | |
class |
Universe.CollisionNotification
Comprises a Body object and a Particle
object that have been the counterparts in a collision. |
Field Summary | |
static int |
FINITE
A finite universe which limits the position of the bodies. |
static int |
INFINITE
An infinite universe which does not impose any limits to the position of the bodies. |
static int |
TOROID
An infinite universe of finite size where the opposite vertical and horizontal edges are connected to form a torus. |
Constructor Summary | |
Universe()
Creates an infinite universe. |
|
Universe(int t,
Point2 min,
Point2 max)
Creates a universe. |
Method Summary | |
void |
addBody(Body b)
Adds the body b to the universe, which is also set
to be the owner of the body. |
void |
addBoundary(Boundary b)
Adds the boundary b to the universe, which is also set
to be the owner of the body. |
void |
advance(double dt)
Advances the time dt seconds and
updates its bodies accordingly.
|
java.util.List |
bodies()
Returns an unmodifiable (i.e., "read-only") list of the bodies in the universe. |
int |
bodySize()
Returns the number of bodies in the universe. |
int |
bodySize(java.lang.Class t)
Returns the number of bodies of the type t
in the universe. |
java.util.List |
boundaries()
Returns an unmodifiable (i.e., "read-only") list of the boundaries in the universe. |
int |
boundarySize()
Returns the number of boundaries in the universe. |
int |
boundarySize(java.lang.Class t)
Returns the number of boundaries of the type t
in the universe. |
void |
clearInelasticCollision(java.lang.Class bc,
java.lang.Class pc)
Sets the collisions between instances of the classes bc and pc to be elastic. |
double |
getAccelerationOfGravity()
Returns the acceleration of gravity of this universe. |
Point2 |
getCenter()
Returns the center of the universe or null
if the universe is infinite. |
Point2 |
getMaximumCorner()
Returns the maximum corner of the universe or null
if the universe is infinite. |
Point2 |
getMinimumCorner()
Returns the minimum corner of the universe or null
if the universe is infinite. |
int |
getType()
Returns the type of the universe. |
boolean |
isInelasticCollision(Body b,
Particle p)
Returns true if a collision between the body
b and the particle p is inelastic; otherwise,
returns false . |
boolean |
isInelasticCollision(java.lang.Class bc,
java.lang.Class pc)
Returns true if collisions between instances of the classes
bc and pc are inelastic; otherwise,
returns false . |
void |
removeAll()
Removes all bodies and boundaries from the universe and sets their owner to null . |
void |
removeBody(Body b)
Removes the body b from the universe and sets its
owner to null . |
void |
removeBoundary(Boundary b)
Removes the boundary b from the universe and sets its
owner to null . |
void |
setAccelerationOfGravity(double g)
Sets the acceleration of gravity of this universe to g . |
void |
setInelasticCollision(java.lang.Class bc,
java.lang.Class pc)
Sets the collisions between instances of the classes bc and pc to be inelastic. |
int |
size()
Deprecated. As of version 1.1, replaced by bodySize() . |
int |
size(java.lang.Class t)
Deprecated. As of version 1.1, replaced by bodySize(Class) . |
Point2 |
transpose(Point2 p)
Transposes the point p according to the type
of the universe. |
Methods inherited from class java.util.Observable |
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int INFINITE
public static final int FINITE
getMinimumCorner()
, getMaximumCorner()
).
getMinimumCorner()
,
getMaximumCorner()
,
Constant Field Valuespublic static final int TOROID
getMinimumCorner()
, getMaximumCorner()
).
getMinimumCorner()
,
getMaximumCorner()
,
Constant Field ValuesConstructor Detail |
public Universe()
public Universe(int t, Point2 min, Point2 max)
t
- The type of the universe (infinite, finite or toroid).min
- The minimum corner of the universe.max
- The maximum corner of the universe.INFINITE
,
FINITE
,
TOROID
Method Detail |
public int getType()
INFINITE
,
FINITE
,
TOROID
public Point2 getMinimumCorner()
null
if the universe is infinite.
public Point2 getMaximumCorner()
null
if the universe is infinite.
public Point2 getCenter()
null
if the universe is infinite.
public boolean isInelasticCollision(java.lang.Class bc, java.lang.Class pc)
true
if collisions between instances of the classes
bc
and pc
are inelastic; otherwise,
returns false
.
setInelasticCollision(Class,Class)
,
clearInelasticCollision(Class,Class)
public boolean isInelasticCollision(Body b, Particle p)
true
if a collision between the body
b
and the particle p
is inelastic; otherwise,
returns false
.
public void setInelasticCollision(java.lang.Class bc, java.lang.Class pc)
bc
and pc
to be inelastic.
isInelasticCollision(Class,Class)
,
clearInelasticCollision(Class,Class)
public void clearInelasticCollision(java.lang.Class bc, java.lang.Class pc)
bc
and pc
to be elastic.
isInelasticCollision(Class,Class)
,
setInelasticCollision(Class,Class)
public void addBody(Body b)
b
to the universe, which is also set
to be the owner of the body.
Particle.setOwner(Universe)
public void removeBody(Body b)
b
from the universe and sets its
owner to null
.
Particle.setOwner(Universe)
public void addBoundary(Boundary b)
b
to the universe, which is also set
to be the owner of the body.
Particle.setOwner(Universe)
public void removeBoundary(Boundary b)
b
from the universe and sets its
owner to null
.
Particle.setOwner(Universe)
public void removeAll()
null
.
Particle.setOwner(Universe)
,
Particle.setOwner(Universe)
public java.util.List bodies()
UnsupportedOperationException
.
boundaries()
,
Collections.unmodifiableList(List)
public int bodySize()
public int bodySize(java.lang.Class t)
t
in the universe.
public java.util.List boundaries()
UnsupportedOperationException
.
bodies()
,
Collections.unmodifiableList(List)
public int boundarySize()
public int boundarySize(java.lang.Class t)
t
in the universe.
public int size()
bodySize()
.
public int size(java.lang.Class t)
bodySize(Class)
.
t
in the universe.
public void advance(double dt)
dt
seconds and
updates its bodies accordingly.
The methods advances the bodies iteratively. After each
advancement, it examines whether the body in question is corporeal
and does it collide with any of the remaining (i.e., not yet
advanced) corporeal bodies or boundaries. If a collision occurs,
the method realizes an elastic collision between the bodies.
If either particle have requested a collision notification on
the other particle, all observers will be notified.
Body.advance(double)
,
Particle.isCorporeal()
,
Body.isColliding(Body)
,
Body.elasticCollision(Body)
,
Universe.CollisionNotification
public Point2 transpose(Point2 p)
p
according to the type
of the universe. If the universe is infinite, the method returns
p
. Otherwise, the method returns a new point where
getMinimumCorner.getX() <= result.getX() <=
getMaximumCorner.getX()
and getMinimumCorner.getY()
<= result.getY() <= getMaximumCorner.getY()
.
If the universe is finite, an exceeding point is moved back inside
the rectangle. If the universe is toroid, an exceeding point is
transposed back inside the rectangle by regarding it as a torus
surface.
getType()
,
getMinimumCorner()
,
getMaximumCorner()
public double getAccelerationOfGravity()
setAccelerationOfGravity(double)
,
OrientedBody
public void setAccelerationOfGravity(double g)
g
.
getAccelerationOfGravity()
,
OrientedBody
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |