PinBallDomain
Class Ball

java.lang.Object
  extended by PinBallDomain.Ball

public class Ball
extends java.lang.Object

Object to represent the ball for the PinBall domain.

Author:
George Konidaris (gdk at cs dot umass dot edu)

Field Summary
static double DRAG
          Drag coefficient
 
Constructor Summary
Ball(Point p, double rad)
          Constructs a new ball given a point and radius.
 
Method Summary
 void addDrag()
          Applies drag to the ball.
 void addImpulse(double tox, double toy)
          Add a velocity impulse to the ball.
static Ball create(java.lang.String line)
          Creates a ball object from a line in a config file.
 Point getCenter()
          Obtain the center point of the ball.
 double getRadius()
          Obtain the ball's radius.
 double getVelocity()
          Return the ball's speed.
 double getX()
          Obtain the ball's X co-ordinate
 double getXDot()
          Obtain the ball's X velocity.
 double getY()
          Obtain the ball's Y co-ordinate
 double getYDot()
          Obtain the ball's Y velocity.
static boolean matchTag(java.lang.String line)
          Determines whether a config file line refers to the ball.
 void setPosition(double xx, double yy)
          Set the ball's position.
 void setVelocities(double dx, double dy)
          Explicity set the ball's velocities.
 void step()
          Moves the ball one step forward, in the direction of xdot and ydot.
 void write(java.io.FileWriter f)
          Writes the ball to a config file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DRAG

public static final double DRAG
Drag coefficient

See Also:
Constant Field Values
Constructor Detail

Ball

public Ball(Point p,
            double rad)
Constructs a new ball given a point and radius. X and Y velocities are set to zero.

Parameters:
p - desired X and Y co-ordinates
rad - desired radius
Method Detail

getRadius

public double getRadius()
Obtain the ball's radius.

Returns:
the radius

getX

public double getX()
Obtain the ball's X co-ordinate

Returns:
the ball's X co-ordinate

getY

public double getY()
Obtain the ball's Y co-ordinate

Returns:
the ball's Y co-ordinate

getXDot

public double getXDot()
Obtain the ball's X velocity.

Returns:
the ball's X velocity.

getYDot

public double getYDot()
Obtain the ball's Y velocity.

Returns:
the ball's Y velocity.

matchTag

public static boolean matchTag(java.lang.String line)
Determines whether a config file line refers to the ball.

Parameters:
line - the text line from the config file
Returns:
true if the line refers to a ball, false otherwise

create

public static Ball create(java.lang.String line)
Creates a ball object from a line in a config file. The line should first have been matched, and is of format: "ball radius".

The line specifies the ball's radius, but not it's position, because it may have multiple potential starting positions.

Parameters:
line - the line
Returns:
a new Ball object
See Also:
Ball

write

public void write(java.io.FileWriter f)
           throws java.io.IOException
Writes the ball to a config file.

Parameters:
f - file to be written to.
Throws:
java.io.IOException

step

public void step()
Moves the ball one step forward, in the direction of xdot and ydot.


addDrag

public void addDrag()
Applies drag to the ball.


getVelocity

public double getVelocity()
Return the ball's speed.

Returns:
speed

addImpulse

public void addImpulse(double tox,
                       double toy)
Add a velocity impulse to the ball.

Parameters:
tox - impulse to add to xdot
toy - impulse to add to ydot

setVelocities

public void setVelocities(double dx,
                          double dy)
Explicity set the ball's velocities.

Parameters:
dx - X velocity
dy - Y velocity

setPosition

public void setPosition(double xx,
                        double yy)
Set the ball's position. This also halts the ball (sets its X and Y velocities to zero).

Parameters:
xx - X position
yy - Y position

getCenter

public Point getCenter()
Obtain the center point of the ball.

Returns:
the center point
See Also:
Point