fi.utu.cs.physics
Class Particle

java.lang.Object
  |
  +--fi.utu.cs.physics.Particle
Direct Known Subclasses:
Body, Boundary

public abstract class Particle
extends java.lang.Object

A fundamental particle. The particle can be owned by an instance of the class Universe. The particle's elasticity is used in collisions. The particle can be either corporeal or ethereal, which determines whether it can collide or not (i.e., only the corporeal particles can collide). However, the particle can report on collisions (whether they are corporeal or not) through the owning Universe object.

Since:
1.1
See Also:
Universe

Constructor Summary
protected Particle()
          Constructs a particle that is corporeal, does not report on collisions and has no owner.
 
Method Summary
 void addCollisionNotification(java.lang.Class c)
          Adds the class c to the collision notifications.
 void clearCollisionNotifications()
          Removes all collision notifications.
abstract  void elasticCollision(Body other)
          Realizes an elastic collision for the particle and the body other.
 Universe getOwner()
          Returns the owner of the particle or null if it has no owner.
abstract  void inelasticCollision(Body other)
          Realizes an inelastic collision for the particle and the body other.
 boolean isCollisionNotified(java.lang.Class c)
          Returns whether the collisions of and to this particle by instances of the class c are notified.
 boolean isCollisionNotified(Particle p)
          Returns whether the collisions of and to this particle by the particle p are notified.
 boolean isCorporeal()
          Returns true if the particle is corporeal or false if the particle is ethereal.
 void removeCollisionNotification(java.lang.Class c)
          Removes the class c from the collision notifications.
 void setCorporeal()
          Sets the particle to be corporeal.
 void setEthereal()
          Sets the particle to be ethereal.
 void setOwner(Universe u)
          Sets the universe that owns the particle to u.
 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

Particle

protected Particle()
Constructs a particle that is corporeal, does not report on collisions and has no owner.

Method Detail

getOwner

public Universe getOwner()
Returns the owner of the particle or null if it has no owner.


setOwner

public void setOwner(Universe u)
Sets the universe that owns the particle to u.


isCorporeal

public boolean isCorporeal()
Returns true if the particle is corporeal or false if the particle is ethereal.


setCorporeal

public void setCorporeal()
Sets the particle to be corporeal.


setEthereal

public void setEthereal()
Sets the particle to be ethereal.


isCollisionNotified

public boolean isCollisionNotified(java.lang.Class c)
Returns whether the collisions of and to this particle by instances of the class c are notified. Although only corporeal particles can have an actual impact in a collision, ethereal particles can report on collisions.

See Also:
addCollisionNotification(Class), Universe.CollisionNotification

isCollisionNotified

public boolean isCollisionNotified(Particle p)
Returns whether the collisions of and to this particle by the particle p are notified. Although only corporeal particles can have an actual impact in a collision, ethereal particles can report on collisions.


addCollisionNotification

public void addCollisionNotification(java.lang.Class c)
Adds the class c to the collision notifications.


removeCollisionNotification

public void removeCollisionNotification(java.lang.Class c)
Removes the class c from the collision notifications.


clearCollisionNotifications

public void clearCollisionNotifications()
Removes all collision notifications.


elasticCollision

public abstract void elasticCollision(Body other)
Realizes an elastic collision for the particle and the body other. The linear momentum and kinetic energy are conserved in the collision. The collision is realized regardless whether the body overlaps or crosses the particle or not.

See Also:
inelasticCollision(Body)

inelasticCollision

public abstract void inelasticCollision(Body other)
Realizes an inelastic collision for the particle and the body other. The linear momentum and kinetic energy are lost in the collision. After the collision, the particle and the body are at rest (i.e., the velocity and acceleration are zero). The collision is realized regardless whether the body overlaps or crosses the particle or not.

See Also:
elasticCollision(Body)

toString

public java.lang.String toString()
Returns a string that contains the values of the attributes.

Overrides:
toString in class java.lang.Object