public class GMath extends Object
acm.graphics package.| Modifier and Type | Method and Description |
|---|---|
static double |
angle(double x,
double y)
Returns the angle in degrees from the origin to the point (
x
, y). |
static double |
angle(double x0,
double y0,
double x1,
double y1)
Computes the angle in degrees formed by a line segment from the point (
x0, y0) and (x1,
y1). |
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 (
x
, y). |
static double |
distance(double x0,
double y0,
double x1,
double y1)
Computes the distance between the points (
x0,
y0) and (x1, y1). |
static boolean |
isBoolean(String s)
Returns true if the given string could be interpreted as a boolean, such as "true" or "false".
|
static boolean |
isChar(String s)
Returns true if the given string could be interpreted as a char, such as "Q" or "\n".
|
static boolean |
isDouble(String s)
Returns true if the given string could be interpreted as a double, such as "123.45".
|
static boolean |
isInteger(String s)
Returns true if the given string could be interpreted as an integer, such as "12345".
|
static boolean |
isLong(String s)
Returns true if the given string could be interpreted as an long, such as "12345".
|
static int |
round(double x)
Rounds a
double value to the nearest int. |
static double |
round(double x,
int digitsAfterDecimal)
Rounds a
double value to the given number of decimal places. |
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.
|
public static boolean isBoolean(String s)
s - a stringpublic static boolean isChar(String s)
s - a stringpublic static boolean isDouble(String s)
s - a stringpublic static boolean isInteger(String s)
s - a stringpublic static boolean isLong(String s)
s - a stringpublic static int round(double x)
double value to the nearest int.x - A double valueint valuepublic static double round(double x,
int digitsAfterDecimal)
double value to the given number of decimal places.
For example, round(3.141592, 2) returns 3.14.x - A double valuedigitsAfterDecimal - number of digits after decimal to keepint valuepublic static double sinDegrees(double angle)
angle
is expressed in degrees.angle - An angle measured in degreespublic static double cosDegrees(double angle)
angle
is expressed in degrees.angle - An angle measured in degreespublic static double tanDegrees(double angle)
angle is expressed in degrees.angle - An angle measured in degreespublic static double toDegrees(double radians)
Math class, but was added only in JDK1.2, which is not
supported in all browsers.radians - An angle measured in radianspublic static double toRadians(double degrees)
Math class, but was added only in JDK1.2, which is not
supported in all browsers.degrees - An angle measured in degreespublic static double distance(double x,
double y)
x
, y).x - The x-coordinate of the pointy - The y-coordinate of the pointx,
y)public static double distance(double x0,
double y0,
double x1,
double y1)
x0,
y0) and (x1, y1).x0 - The x-coordinate of one pointy0 - The y-coordinate of that pointx1 - The x-coordinate of the other pointy1 - The y-coordinate of that pointx0,
y0) and (x1, y1)public static double angle(double x,
double y)
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.x - The x-coordinate of the pointy - The y-coordinate of the pointx,
y) measured in degrees counterclockwise from the +x
axispublic static double angle(double x0,
double y0,
double x1,
double y1)
x0, y0) and (x1,
y1).x0 - The x-coordinate of one pointy0 - The y-coordinate of that pointx1 - The x-coordinate of the other pointy1 - The y-coordinate of that pointx0,
y0) to (x1, y1)