stanford.androidlib.graphics

## Class 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

All Methods
Modifier and Type Method and Description
`static float` ```angle(float x, float y)```
Returns the angle in degrees from the origin to the point (`x``y`).
`static float` ```angle(float x0, float y0, float x1, float y1)```
Computes the angle in degrees formed by a line segment from the point (`x0``y0`) and (`x1``y1`).
`static float` `cosDegrees(float angle)`
Returns the trigonometric cosine of its argument where `angle` is expressed in degrees.
`static float` ```distance(float x, float y)```
Computes the distance between the origin and the point (`x``y`).
`static float` ```distance(float x0, float y0, float x1, float y1)```
Computes the distance between the points (`x0``y0`) and (`x1``y1`).
`static int` `round(float x)`
Rounds a `float` value to the nearest `int`.
`static float` `sinDegrees(float angle)`
Returns the trigonometric sine of its argument where `angle` is expressed in degrees.
`static float` `tanDegrees(float angle)`
Returns the trigonometric tangent of its argument where `angle` is expressed in degrees.
`static float` `toDegrees(float radians)`
Converts an angle from radians to degrees.
`static float` `toRadians(float 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

• #### round

`public static int round(float x)`
Rounds a `float` value to the nearest `int`.
Parameters:
`x` - A `float` value
Returns:
The nearest `int` value
Usage:
int n = round(x);
• #### sinDegrees

`public static float sinDegrees(float 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
Usage:
float s = sinDegrees(angle);
• #### cosDegrees

`public static float cosDegrees(float 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
Usage:
float c = cosDegrees(angle);
• #### tanDegrees

`public static float tanDegrees(float 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
Usage:
float t = tanDegrees(angle);
• #### toDegrees

`public static float toDegrees(float 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
Usage:

`public static float toRadians(float 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:
Usage:
• #### distance

```public static float distance(float x,
float y)```
Computes the distance between the origin and the point (`x``y`).
Parameters:
`x` - The x-coordinate of the point
`y` - The y-coordinate of the point
Returns:
The distance from the origin to the point (`x``y`)
Usage:
float d = distance(x, y);
• #### distance

```public static float distance(float x0,
float y0,
float x1,
float y1)```
Computes the distance between the points (`x0``y0`) and (`x1``y1`).
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 (`x0``y0`) and (`x1``y1`)
Usage:
float d = distance(x0, y0, x1, y1);
• #### angle

```public static float angle(float x,
float y)```
Returns the angle in degrees from the origin to the point (`x``y`). 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 (`x``y`) measured in degrees counterclockwise from the +x axis
Usage:
float theta = angle(x, y);
• #### angle

```public static float angle(float x0,
float y0,
float x1,
float y1)```
Computes the angle in degrees formed by a line segment from the point (`x0``y0`) and (`x1``y1`).
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 (`x0``y0`) to (`x1``y1`)
Usage:
float theta = angle(x0, y0, x1, y1);