Aria  2.8.0
ArMath Class Reference

Common math operations. More...

#include <ariaUtil.h>

Static Public Member Functions

static double addAngle (double ang1, double ang2)
 This adds two angles together and fixes the result to [-180, 180]. More...
 
static bool angleBetween (double angle, double startAngle, double endAngle)
 Finds if one angle is between two other angles.
 
static double atan2 (double y, double x)
 Finds the arctan of the given y/x pair. More...
 
static bool compareFloats (double f1, double f2, double epsilon)
 
static bool compareFloats (double f1, double f2)
 
static double cos (double angle)
 Finds the cos, from angles in degrees. More...
 
static double degToRad (double deg)
 Converts an angle in degrees to an angle in radians. More...
 
static double distanceBetween (double x1, double y1, double x2, double y2)
 Finds the distance between two coordinates. More...
 
static double epsilon ()
 
static double fabs (double val)
 Finds the absolute value of a double. More...
 
static double fixAngle (double angle)
 Takes an angle and returns the angle in range (-180,180]. More...
 
static long getRandMax ()
 Maximum of value returned by random()
 
static bool isFinite (float f)
 
static bool isFinite (double d)
 
static bool isNan (double d)
 Platform-independent call to determine whether the given double is not-a-number.
 
static bool isNan (float f)
 
static double log2 (double x)
 Base-2 logarithm.
 
static void pointRotate (double *x, double *y, double th)
 Rotates a point around 0 by degrees given.
 
static double radToDeg (double rad)
 Converts an angle in radians to an angle in degrees. More...
 
static long random (void)
 Returns a random number between 0 and RAND_MAX on Windows, 2^31 on Linux (see ArUtil::getRandMax()). More...
 
static long randomInRange (long m, long n)
 Returns a random number between m and n. More...
 
static int roundInt (double val)
 Finds the closest integer to double given. More...
 
static short roundShort (double val)
 Finds the closest short to double given. More...
 
static double sin (double angle)
 Finds the sin, from angles in degrees. More...
 
static double squaredDistanceBetween (double x1, double y1, double x2, double y2)
 Finds the squared distance between two coordinates. More...
 
static double subAngle (double ang1, double ang2)
 This subtracts one angle from another and fixes the result to [-180,180]. More...
 
static double tan (double angle)
 Finds the tan, from angles in degrees. More...
 

Detailed Description

Common math operations.

Member Function Documentation

◆ addAngle()

static double ArMath::addAngle ( double  ang1,
double  ang2 
)
inlinestatic

This adds two angles together and fixes the result to [-180, 180].

Parameters
ang1first angle
ang2second angle, added to first
Returns
sum of the angles, in range [-180,180]
See also
subAngle
fixAngle

◆ atan2()

static double ArMath::atan2 ( double  y,
double  x 
)
inlinestatic

Finds the arctan of the given y/x pair.

Parameters
ythe y distance
xthe x distance
Returns
the angle y and x form

◆ cos()

static double ArMath::cos ( double  angle)
inlinestatic

Finds the cos, from angles in degrees.

Parameters
angleangle to find the cos of, in degrees
Returns
the cos of the angle
See also
sin

◆ degToRad()

static double ArMath::degToRad ( double  deg)
inlinestatic

Converts an angle in degrees to an angle in radians.

Parameters
degthe angle in degrees
Returns
the angle in radians
See also
radToDeg

◆ distanceBetween()

static double ArMath::distanceBetween ( double  x1,
double  y1,
double  x2,
double  y2 
)
inlinestatic

Finds the distance between two coordinates.

Parameters
x1the first coords x position
y1the first coords y position
x2the second coords x position
y2the second coords y position
Returns
the distance between (x1, y1) and (x2, y2)

◆ epsilon()

double ArMath::epsilon ( )
static
Returns
a very small number which can be used for comparisons of floating point values, etc.

◆ fabs()

static double ArMath::fabs ( double  val)
inlinestatic

Finds the absolute value of a double.

Parameters
valthe number to find the absolute value of
Returns
the absolute value of the number
Examples:
actsColorFollowingExample.cpp.

◆ fixAngle()

static double ArMath::fixAngle ( double  angle)
inlinestatic

Takes an angle and returns the angle in range (-180,180].

Parameters
anglethe angle to fix
Returns
the angle in range (-180,180]
See also
addAngle
subAngle

◆ radToDeg()

static double ArMath::radToDeg ( double  rad)
inlinestatic

Converts an angle in radians to an angle in degrees.

Parameters
radthe angle in radians
Returns
the angle in degrees
See also
degToRad

◆ random()

static long ArMath::random ( void  )
inlinestatic

Returns a random number between 0 and RAND_MAX on Windows, 2^31 on Linux (see ArUtil::getRandMax()).

On Windows, rand() is used, on Linux, lrand48().

◆ randomInRange()

long ArMath::randomInRange ( long  m,
long  n 
)
static

Returns a random number between m and n.

On Windows, rand() is used, on Linux lrand48().

◆ roundInt()

static int ArMath::roundInt ( double  val)
inlinestatic

Finds the closest integer to double given.

Parameters
valthe double to find the nearest integer to
Returns
the integer the value is nearest to (also caps it within int bounds)

◆ roundShort()

static short ArMath::roundShort ( double  val)
inlinestatic

Finds the closest short to double given.

Parameters
valthe double to find the nearest short to
Returns
the integer the value is nearest to (also caps it within short bounds)

◆ sin()

static double ArMath::sin ( double  angle)
inlinestatic

Finds the sin, from angles in degrees.

Parameters
angleangle to find the sin of, in degrees
Returns
the sin of the angle
See also
cos

◆ squaredDistanceBetween()

static double ArMath::squaredDistanceBetween ( double  x1,
double  y1,
double  x2,
double  y2 
)
inlinestatic

Finds the squared distance between two coordinates.

use this only where speed really matters

Parameters
x1the first coords x position
y1the first coords y position
x2the second coords x position
y2the second coords y position
Returns
the distance between (x1, y1) and (x2, y2)

◆ subAngle()

static double ArMath::subAngle ( double  ang1,
double  ang2 
)
inlinestatic

This subtracts one angle from another and fixes the result to [-180,180].

Parameters
ang1first angle
ang2second angle, subtracted from first angle
Returns
resulting angle, in range [-180,180]
See also
addAngle
fixAngle

◆ tan()

static double ArMath::tan ( double  angle)
inlinestatic

Finds the tan, from angles in degrees.

Parameters
angleangle to find the tan of, in degrees
Returns
the tan of the angle

The documentation for this class was generated from the following files: