gizmoball.physics
Class PhysicsSphere

java.lang.Object
  extended by gizmoball.physics.PhysicsSphere
All Implemented Interfaces:
PhysicsObject, PrimitivesCollection

public class PhysicsSphere
extends java.lang.Object
implements PhysicsObject

A PhysicsSphere is a wrapper class for a three dimensional representation of a sphere.

Specification Fields :
sphere : Sphere // the sphere that is wrapped in this

Constructor Summary
PhysicsSphere(Vect3 center, double radius, double mass, double reflectionCoeff, Vect3 velocity)
          Creates a new PhysicsSphere without rotation or texture
PhysicsSphere(Vect3 center, double radius, double mass, double reflectionCoeff, Vect3 velocity, java.lang.String texture)
          Creates a new PhysicsSphere without rotation
PhysicsSphere(Vect3 center, double radius, double mass, double reflectionCoeff, Vect3 rotCenter, Vect3 rotOmega, Vect3 velocity)
          Creates a new PhysicsSphere without texture
PhysicsSphere(Vect3 center, double radius, double mass, double reflectionCoeff, Vect3 rotCenter, Vect3 rotOmega, Vect3 velocity, java.lang.String texture)
          Creates a new PhysicsSphere
 
Method Summary
 boolean containsPoint(Vect3 p)
          Returns whether p is in this.
 Vect3 getBCenter()
           
 Vect3Pair getBoundingBox()
           
 double getBRadius()
           
 java.util.Collection<LateralCylinder> getLateralCylinders()
           
 double getMass()
           
 java.util.Collection<PlaneCircle> getPlaneCircles()
           
 java.util.Collection<PlanePolygon> getPlanePolygons()
           
 Vect3 getPosition()
           
 double getReflectionCoeff()
           
 Vect3 getRotCenter()
           
 Vect3 getRotOmega()
           
 Sphere getSphere()
           
 java.util.Collection<Sphere> getSpheres()
           
 java.util.Collection<Torus> getTori()
           
 Vect3 getVelocity()
           
 double minDistanceToObjectFromP(Vect3 p)
          Returns the minimum distance from p to this
 Vect3 reflect(PhysicsSphere ps)
           
 void rotateAboutAxis(Vect3 center, Vect3 axis, double angle)
           
 void setMass(double mass)
           
 void setPosition(Vect3 pos)
           
 void setReflectionCoeff(double rc)
           
 void setRotCenter(Vect3 rc)
           
 void setRotOmega(Vect3 ro)
           
 void setVelocity(Vect3 vel)
           
 double timeUntilCollision(PhysicsSphere ball, double lookahead)
          Returns the time until a collision between ball and this
 void update(double timestep)
          Updates the state of this after the passage of timestep.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PhysicsSphere

public PhysicsSphere(Vect3 center,
                     double radius,
                     double mass,
                     double reflectionCoeff,
                     Vect3 rotCenter,
                     Vect3 rotOmega,
                     Vect3 velocity,
                     java.lang.String texture)
Creates a new PhysicsSphere

Parameters:
center - the center of the sphere
radius - the radius of the sphere
mass - the mass of the sphere
reflectionCoeff - the coefficient of reflection of the sphere
rotCenter - the center of rotation of the sphere
rotOmega - the angular velocity of the sphere
velocity - the velocity of rotCenter
texture - the texture of the torus
Requires:
(center != null) && (radius != null) && (rotCenter != null) && (rotOmega != null) && (velocity != null) && (mass >= 0) && (0 <= reflectionCoeff <= 1)
Effects:
Creates a new PhysicsSphere ps with the desired parameters such that: ps.sphere.center = center && ps.sphere.radius = radius && ps.mass = mass && ps.reflectionCoeff = reflectionCoeff && ps.rotCenter = rotCenter && ps.rotOmega = rotOmega && ps.velocity = velocity && ps.bcenter = center && ps.bradius = radius + 0.1

PhysicsSphere

public PhysicsSphere(Vect3 center,
                     double radius,
                     double mass,
                     double reflectionCoeff,
                     Vect3 rotCenter,
                     Vect3 rotOmega,
                     Vect3 velocity)
Creates a new PhysicsSphere without texture

Parameters:
center - the center of the sphere
radius - the radius of the sphere
mass - the mass of the sphere
reflectionCoeff - the coefficient of reflection of the sphere
rotCenter - the center of rotation of the sphere
rotOmega - the angular velocity of the sphere
velocity - the velocity of rotCenter
Requires:
(center != null) && (radius != null) && (rotCenter != null) && (rotOmega != null) && (velocity != null) && (mass >= 0) && (0 <= reflectionCoeff <= 1)
Effects:
Creates a new PhysicsSphere ps with the desired parameters such that: ps.sphere.center = center && ps.sphere.radius = radius && ps.mass = mass && ps.reflectionCoeff = reflectionCoeff && ps.rotCenter = rotCenter && ps.rotOmega = rotOmega && ps.velocity = velocity && ps.bcenter = center && ps.bradius = radius + 0.1

PhysicsSphere

public PhysicsSphere(Vect3 center,
                     double radius,
                     double mass,
                     double reflectionCoeff,
                     Vect3 velocity,
                     java.lang.String texture)
Creates a new PhysicsSphere without rotation

Effects:
Creates a new PhysicsSphere with the desired parameters such that: rotCenter = center && rotOmega = Vect3.ZERO

PhysicsSphere

public PhysicsSphere(Vect3 center,
                     double radius,
                     double mass,
                     double reflectionCoeff,
                     Vect3 velocity)
Creates a new PhysicsSphere without rotation or texture

Effects:
Creates a new PhysicsSphere with the desired parameters such that: rotCenter = center && rotOmega = Vect3.ZERO
Method Detail

containsPoint

public boolean containsPoint(Vect3 p)
Description copied from interface: PhysicsObject
Returns whether p is in this.

Specified by:
containsPoint in interface PhysicsObject
Returns:
true if true if Vect3.isAbout(this.minDistanceToObjectFromP(p),0), false otherwise

getBCenter

public Vect3 getBCenter()
Specified by:
getBCenter in interface PhysicsObject
Returns:
this.bcenter

getBRadius

public double getBRadius()
Specified by:
getBRadius in interface PhysicsObject
Returns:
this.bradius

getMass

public double getMass()
Specified by:
getMass in interface PhysicsObject
Returns:
this.mass

getPosition

public Vect3 getPosition()
Specified by:
getPosition in interface PhysicsObject
Returns:
this.position

getRotCenter

public Vect3 getRotCenter()
Specified by:
getRotCenter in interface PhysicsObject
Returns:
this.rotCenter

getRotOmega

public Vect3 getRotOmega()
Specified by:
getRotOmega in interface PhysicsObject
Returns:
this.rotOmega

getVelocity

public Vect3 getVelocity()
Specified by:
getVelocity in interface PhysicsObject
Returns:
this.velocity

getReflectionCoeff

public double getReflectionCoeff()
Specified by:
getReflectionCoeff in interface PhysicsObject
Returns:
this.reflectionCoeff

getSphere

public Sphere getSphere()
Returns:
this.sphere

minDistanceToObjectFromP

public double minDistanceToObjectFromP(Vect3 p)
Description copied from interface: PhysicsObject
Returns the minimum distance from p to this

Specified by:
minDistanceToObjectFromP in interface PhysicsObject
Returns:
the minimum distance between p and this
Requires:
p != null

reflect

public Vect3 reflect(PhysicsSphere ps)
Specified by:
reflect in interface PhysicsObject
Returns:
the velocity of the ball after impacting the given sphere
Effects:
computes the new velocity of a ball reflecting off of a sphere. The velocity resulting from this method corresponds to a collision against a surface with the reflection coefficient of this. A reflection coefficient of 1 indicates a perfectly elastic collision. This method assumes that the ball is at the point of impact.

setMass

public void setMass(double mass)
Specified by:
setMass in interface PhysicsObject
Requires:
mass >= 0
Effects:
this.mass = mass

setPosition

public void setPosition(Vect3 pos)
Specified by:
setPosition in interface PhysicsObject
Requires:
pos != null
Effects:
this.position = pos

setRotCenter

public void setRotCenter(Vect3 rc)
Specified by:
setRotCenter in interface PhysicsObject
Requires:
rc != null
Effects:
this.rotCenter = rc

setRotOmega

public void setRotOmega(Vect3 ro)
Specified by:
setRotOmega in interface PhysicsObject
Requires:
ro != null
Effects:
this.rotOmega = ro

setVelocity

public void setVelocity(Vect3 vel)
Specified by:
setVelocity in interface PhysicsObject
Requires:
vel != null
Effects:
this.velocity = vel

setReflectionCoeff

public void setReflectionCoeff(double rc)
Specified by:
setReflectionCoeff in interface PhysicsObject
Requires:
0 <= rc <= 1
Effects:
this.reflectionCoeff = rc

rotateAboutAxis

public void rotateAboutAxis(Vect3 center,
                            Vect3 axis,
                            double angle)
Specified by:
rotateAboutAxis in interface PhysicsObject

update

public void update(double timestep)
Updates the state of this after the passage of timestep.

Specified by:
update in interface PhysicsObject
Requires:
timestep >= 0
Effects:
this.rotCenter_post = this.rotCenter_pre + this.velocity * timestep this.position_post = this.rotCenter_post + this.rotOmega x (this.position_pre - this.rotCenter_pre)* timestep

timeUntilCollision

public double timeUntilCollision(PhysicsSphere ball,
                                 double lookahead)
Returns the time until a collision between ball and this

Specified by:
timeUntilCollision in interface PhysicsObject
Returns:
the time until collision or POSITIVE_INFINITY if the collision will not occur
Effects:
computes the time until ball and this, travelling at their current specified velocities, collide. If no collision will occur POSITIVE_INFINITY is returned. This method assumes that both objects will travel at constant velocity until impact.

getPlanePolygons

public java.util.Collection<PlanePolygon> getPlanePolygons()
Specified by:
getPlanePolygons in interface PrimitivesCollection
Returns:
this.planePolygons

getPlaneCircles

public java.util.Collection<PlaneCircle> getPlaneCircles()
Specified by:
getPlaneCircles in interface PrimitivesCollection
Returns:
this.planeCircles

getSpheres

public java.util.Collection<Sphere> getSpheres()
Specified by:
getSpheres in interface PrimitivesCollection
Returns:
this.spheres

getLateralCylinders

public java.util.Collection<LateralCylinder> getLateralCylinders()
Specified by:
getLateralCylinders in interface PrimitivesCollection
Returns:
this.lateralCylinders

getTori

public java.util.Collection<Torus> getTori()
Specified by:
getTori in interface PrimitivesCollection
Returns:
this.torii

getBoundingBox

public Vect3Pair getBoundingBox()
Specified by:
getBoundingBox in interface PhysicsObject
Returns:
a bounding box consisting of one Vect3 with smaller coordinates and one Vect3 with larger coordinates