|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--hockey.api.Util
The class Util
contains methods for performing basic
numeric operations such as the elementary squaring, euclidean distance,
angle conversion, trigonometric functions in degrees and clamping.
Many of the Util
functions simply delegate to the equivalent
functions in Math
for their implementations.
Math
Constructor Summary | |
Util()
|
Method Summary | |
static double |
clamp(double a,
double x,
double b)
Clamps a double value to a given range. |
static int |
clamp(int a,
int x,
int b)
Clamps an int value to a given range. |
static double |
clampAbs(double x,
double a)
Clamps a double value between zero and a given maximum
value. |
static int |
clampAbs(int x,
int a)
Clamps an int value to a given maximum absolute value. |
static double |
clampPos(double x,
double b)
Clamps a double value between zero and a given maximum
value. |
static int |
clampPos(int x,
int b)
Clamps an int value between zero and a given maximum
value. |
static int |
collisionHeading(IObject target,
IObject origin,
int speed)
Calculate the heading for collision from origin to
target travelling at speed speed
relative to the ice. |
static double |
cosd(double deg)
Returns the trigonometric cosine of an angle given in degrees. |
static double |
dangle(double v1,
double v2)
Returns the minimal angular distance between two angles in degrees. |
static double |
datan2(double y,
double x)
Returns the angle in degrees to a point (x,y). |
static double |
datan2(IObject to,
IObject origin)
Returns the absolute angle in degrees to an IObject
with another IObject as origin. |
static double |
deg(double rad)
Converts an angle measured in radians to the equivalent angle measured in degrees. |
static double |
dist(double x,
double y)
Returns the distance from the origin to a coordinate. |
static double |
dist(IObject o1,
IObject o2)
Returns the distance between two IObject s. |
static double |
dist2(double x,
double y)
Returns the squared distance from the origin to a double coordinate. |
static int |
dist2(int x,
int y)
Returns the squared distance from the origin to an int coordinate. |
static int |
dist2(IObject o1,
IObject o2)
Returns the squared distance between two IObject s. |
static double |
rad(double deg)
Converts an angle measured in degrees to the equivalent angle measured in radians. |
static double |
sind(double deg)
Returns the trigonometric sine of an angle given in degrees. |
static double |
solve(double a,
double b,
double c,
boolean pos)
Solve ax^2 + 2bx + c = 0 for x. |
static double |
sqr(double x)
Returns the square of a double value. |
static int |
sqr(int x)
Returns the square of an int value. |
static double |
tand(double deg)
Returns the trigonometric tangent of an angle given in degrees. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Util()
Method Detail |
public static int sqr(int x)
int
value.
x
- an int
value.
x
.public static double sqr(double x)
double
value.
x
- a double
value.
x
.public static double dist(double x, double y)
x
- the x-coordinate.y
- the y-coordinate.
public static double dist(IObject o1, IObject o2)
IObject
s.
o1
- the first IObject
.o2
- the second IObject
.
IObject
s.public static double dist2(double x, double y)
double
coordinate.
x
- the x-coordinate.y
- the y-coordinate.
public static int dist2(int x, int y)
int
coordinate.
x
- the x-coordinate.y
- the y-coordinate.
public static int dist2(IObject o1, IObject o2)
IObject
s.
o1
- the first IObject
.o2
- the second IObject
.
IObject
s.public static double dangle(double v1, double v2)
Math.IEEEremainder(v1 - v2, 360)
.
v1
- the first angle, in degrees.v2
- the second angle, in degrees.
public static double rad(double deg)
Math.toRadians(deg)
.
deg
- an angle, in degrees.
deg
in radians.public static double deg(double rad)
Math.toDegrees(rad)
.
rad
- an angle, in radians.
rad
in degrees.public static double cosd(double deg)
Math.cos(rad(deg))
.
deg
- the angle, in degrees.
public static double sind(double deg)
Math.sin(rad(deg))
.
deg
- the angle, in degrees.
public static double tand(double deg)
Math.tan(rad(deg))
.
deg
- the angle, in degrees.
public static double datan2(double y, double x)
deg(Math.atan2(y, x))
.
Note that the point is given with the y-coordinate first, as for
Math.atan2
.
y
- the y-coordinate of the point.x
- the x-coordinate of the point.
public static double datan2(IObject to, IObject origin)
IObject
with another IObject
as origin. The angle is absolute
in the x-y-coordinate system of the IObject
s, the heading
of the origin IObject
is not considered.
to
- the IObject
to get the absolute angle to.origin
- the IObject
to use as origin.
to
with origin
as origin.public static int clamp(int a, int x, int b)
int
value to a given range.
The returned value is a
if x<a
,
x
if it is in the range, or b
if
x>b
. The metod is the same as calling
Math.min(Math.max(a, x), b)
.
a
- the minimum value of the range.x
- the int
value.b
- the maximum value of the range.
x
clamped to the range
a
-b
.public static int clampPos(int x, int b)
int
value between zero and a given maximum
value.
The returned value is 0
if x<0
,
x
if it is in the range, or b
if
x>b
. The metod is the same as calling
clamp(0, x, b)
.
x
- the int
value.b
- the maximum value of the range.
x
clamped to the range
0
-b
.public static int clampAbs(int x, int a)
int
value to a given maximum absolute value.
The returned value is -a
if x<-a
,
x
if it is in the range, or a
if
x>a
. The metod is the same as calling
clamp(-a, x, a)
.
x
- the int
value.a
- the maximum absolute value.
x
clamped to the range
-a
-a
.public static double clamp(double a, double x, double b)
double
value to a given range.
The returned value is a
if x<a
,
x
if it is in the range, or b
if
x>b
. The metod is the same as calling
Math.min(Math.max(a, x), b)
.
a
- the minimum value of the range.x
- the int
value.b
- the maximum value of the range.
x
clamped to the range
a
-b
.public static double clampPos(double x, double b)
double
value between zero and a given maximum
value.
The returned value is 0
if x<0
,
x
if it is in the range, or b
if
x>b
. The metod is the same as calling
clamp(0, x, b)
.
x
- the int
value.b
- the maximum value of the range.
x
clamped to the range
0
-b
.public static double clampAbs(double x, double a)
double
value between zero and a given maximum
value.
The returned value is 0
if x<0
,
x
if it is in the range, or a
if
x>a
. The metod is the same as calling
clamp(-a, x, a)
.
x
- the int
value.a
- the maximum absolute value.
x
clamped to the range
-a
-a
.public static double solve(double a, double b, double c, boolean pos)
a
- the quadratic factor.b
- half the linear factor.c
- the constant factor.pos
- determines whether to return the +
solution.
(-b +/- sqrt(b*b - a*c)) / a
or NaN
if there is no solution.
or -c / 2 / b
if a +
solution is requested
and the equation is (nearly) linear.
public static int collisionHeading(IObject target, IObject origin, int speed)
origin
to
target
travelling at speed speed
relative to the ice.
target
- the target.origin
- the origin.speed
- the speed.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |