Building Parsers with Java

sjm.examples.sling
Class Sling

java.lang.Object
  |
  +--sjm.examples.sling.SlingFunction
        |
        +--sjm.examples.sling.Sling

public class Sling
extends SlingFunction

This class represents the location of a sling stone in terms of the length of a sling's strap, and the speed of the stone's rotation around the slinger's head.

The constructor accepts two source functions. The y component of the first function represents the length of the strap, and the y component of the second function represents the stone's angular speed. A speed of 1 represents one full rotation that occurs during the course of a plot.


Fields inherited from class sjm.examples.sling.SlingFunction
source
 
Constructor Summary
Sling()
          Constructs sling(t, t), which is mainly useful for a prototypical sling.
Sling(SlingFunction radius, SlingFunction speed)
          Constructs a sling from the given sources, using the y component of the first function as a sling's strap length, and the y component of the second function as the sling's speed.
 
Method Summary
 Point f(double t)
          Combine the y components of the sources into a new point, using the first source for the sling's strap length, and the second source for the stone's speed.
 java.lang.String toString()
          Return a string representation of this function.
 
Methods inherited from class sjm.examples.sling.SlingFunction
eval, extrema, fresh
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Sling

public Sling()
Constructs sling(t, t), which is mainly useful for a prototypical sling.

Sling

public Sling(SlingFunction radius,
             SlingFunction speed)
Constructs a sling from the given sources, using the y component of the first function as a sling's strap length, and the y component of the second function as the sling's speed.
Method Detail

f

public Point f(double t)
Combine the y components of the sources into a new point, using the first source for the sling's strap length, and the second source for the stone's speed.
Overrides:
f in class SlingFunction
Parameters:
t - a number that represents how far along a plot is, and thus tells which point to return
Returns:
a new point that represents a stone's location given the length of the strap and the number of rotations. If r is the strap length, then r = f1.f(t).y. If s is the speed, then s = f2.f(t).y. If the angle through which the stone has swept is theta, then theta = pi*2*speed * t. The returned point, then, is (r*cos(theta), r*sin(theta));

toString

public java.lang.String toString()
Return a string representation of this function.
Overrides:
toString in class java.lang.Object

by Steve Metsker