acm.graphics
Class GMath

java.lang.Object
  extended by acm.graphics.GMath

public class GMath
extends Object

This class defines a variety of static mathematical methods that are useful for the acm.graphics package.


Method Summary
static double angle(double x, double y)
          Returns the angle in degrees from the origin to the point (xy).
static double angle(double x0, double y0, double x1, double y1)
          Computes the angle in degrees formed by a line segment from the point (x0y0) and (x1y1).
static double cosDegrees(double angle)
          Returns the trigonometric cosine of its argument where angle is expressed in degrees.
static double distance(double x, double y)
          Computes the distance between the origin and the point (xy).
static double distance(double x0, double y0, double x1, double y1)
          Computes the distance between the points (x0y0) and (x1y1).
static int round(double x)
          Rounds a double value to the nearest int.
static double sinDegrees(double angle)
          Returns the trigonometric sine of its argument where angle is expressed in degrees.
static double tanDegrees(double angle)
          Returns the trigonometric tangent of its argument where angle is expressed in degrees.
static double toDegrees(double radians)
          Converts an angle from radians to degrees.
static double toRadians(double degrees)
          Converts an angle from degrees to radians.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

angle

public static double angle(double x,
                           double y)
Returns the angle in degrees from the origin to the point (xy). This method is easier to use than atan2 because it specifies the displacements in the usual x/y order and because it takes care of the fact that the Java coordinate system is flipped. The point (0, 0) is arbitrarily defined to be at angle 0.

Parameters:
x - The x-coordinate of the point
y - The y-coordinate of the point
Returns:
The angle from the origin to the point (xy) measured in degrees counterclockwise from the +x axis

angle

public static double angle(double x0,
                           double y0,
                           double x1,
                           double y1)
Computes the angle in degrees formed by a line segment from the point (x0y0) and (x1y1).

Parameters:
x0 - The x-coordinate of one point
y0 - The y-coordinate of that point
x1 - The x-coordinate of the other point
y1 - The y-coordinate of that point
Returns:
The angle formed by the line segment from (x0y0) to (x1y1)

cosDegrees

public static double cosDegrees(double angle)
Returns the trigonometric cosine of its argument where angle is expressed in degrees.

Parameters:
angle - An angle measured in degrees
Returns:
The trigonometric cosine of the angle

distance

public static double distance(double x,
                              double y)
Computes the distance between the origin and the point (xy).

Parameters:
x - The x-coordinate of the point
y - The y-coordinate of the point
Returns:
The distance from the origin to the point (xy)

distance

public static double distance(double x0,
                              double y0,
                              double x1,
                              double y1)
Computes the distance between the points (x0y0) and (x1y1).

Parameters:
x0 - The x-coordinate of one point
y0 - The y-coordinate of that point
x1 - The x-coordinate of the other point
y1 - The y-coordinate of that point
Returns:
The distance between the points (x0y0) and (x1y1)

round

public static int round(double x)
Rounds a double value to the nearest int.

Parameters:
x - A double value
Returns:
The nearest int value

sinDegrees

public static double sinDegrees(double angle)
Returns the trigonometric sine of its argument where angle is expressed in degrees.

Parameters:
angle - An angle measured in degrees
Returns:
The trigonometric sine of the angle

tanDegrees

public static double tanDegrees(double angle)
Returns the trigonometric tangent of its argument where angle is expressed in degrees.

Parameters:
angle - An angle measured in degrees
Returns:
The trigonometric tangent of the angle

toDegrees

public static double toDegrees(double radians)
Converts an angle from radians to degrees. This method is defined in the Math class, but was added only in JDK1.2, which is not supported in all browsers.

Parameters:
radians - An angle measured in radians
Returns:
The equivalent angle in degrees

toRadians

public static double toRadians(double degrees)
Converts an angle from degrees to radians. This method is defined in the Math class, but was added only in JDK1.2, which is not supported in all browsers.

Parameters:
degrees - An angle measured in degrees
Returns:
The equivalent angle in radians