sjm.examples.sling
Class Polar
java.lang.Object
|
+--sjm.examples.sling.SlingFunction
|
+--sjm.examples.sling.Polar
- public class Polar
- extends SlingFunction
This class represents the location of a sling stone in
terms of the length of a sling's strap, and the angle (in
radians) 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 strap's angle.
When you whirl a sling, the stone's path covers 2*pi
"radians" of arc as the stone makes one revolution. The
number "pi" is equal to the ratio of a circle's
circumference to its diameter, about 3.1416. As a stone
makes one revolution, its arc varies from 0 to 2*pi,
starting in the positive x direction and rotating
counterclockwise.
We can use the variable r to represent the strap's length,
and the variable theta to represent the strap's angle. At
any point in time, the stone's position is polar(r,
theta). This is equivalent to cartesian(r *
cos(theta), r * sin(theta)), since the cos
and sin functions represent the x and
y components of a stone's path.
|
Constructor Summary |
Polar()
Constructs polar(t, t). |
Polar(SlingFunction radius,
SlingFunction theta)
Constructs a polar function object 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 angle. |
|
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 angle. |
java.lang.String |
toString()
Return a string representation of this function. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Polar
public Polar()
- Constructs
polar(t, t).
Polar
public Polar(SlingFunction radius,
SlingFunction theta)
- Constructs a polar function object 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 angle.
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 angle.
- 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:
(r * Math.cos(theta),
r * Math.sin(theta)), where r is f1.f(t).y
and theta is f2.f(t).y.
toString
public java.lang.String toString()
- Return a string representation of this function.
- Overrides:
- toString in class java.lang.Object