-
-
Notifications
You must be signed in to change notification settings - Fork 558
Math Functions (FXGL 11)
All commonly used math methods are located in FXGLMath
.
Page author: dltt83
Value: 1.1920928955078125E-7
Type: double
"Close to zero" epsilon value
Value: Math.PI
/ 3.141592653589793
Type: double
Constant number PI
Value: PI * 2
Type: double
Math.PI
value multiplied by 2
Value: PI / 2
Type: double
Math.PI
value divided by 2
Value: (float) Math.PI
/ 3.141592653589793
Type: float
Float version of Math.PI
value
Value: (float) Math.PI * 2
Type: float
Float version of PI2
value
Value: PI_F / 2
Type: float
Float version of HALF_PI
value
Value: Math.E
/ 2.718281828459045
Type: double
Euler's number for natural base logarithms etc
Parameters: double radians
Returns: double
Returns sine value for given radians
sin(0.0); //@return 0.0
sin(HALF_PI); //@return 1.0
sin(PI / 4); //@return 0.7072423542137346
Parameters: double radians
Returns: double
Returns cosine value for given radians
cos(0.0); //@return 1.0
cos(HALF_PI); //@return 1.2246467991473532E-16 (almost 0 due to inaccuracies)
cos(PI / 4); //@return 0.7069711821610654
Parameters: double degrees
Returns: double
Returns sine value for given degrees
sin(0); //@return 0.0
sin(90); //@return 1.0
sin(45); //@return 0.7072423542137346
Parameters: double degrees
Returns: double
Returns cosine value for given degrees
cos(0); //@return 1.0
cos(90); //@return 1.2246467991473532E-16 (almost 0 due to inaccuracies)
cos(45); //@return 0.7069711821610654
Parameters: double radians
Returns: float
Returns sine value as float for given radians
sin(0.0); //@return 0.0
sin(HALF_PI); //@return 1.0
sin(PI / 4); //@return 0.7072423542137346
Parameters: double radians
Returns: float
Returns cosine value as float for given radians
cos(0.0); //@return 1.0
cos(HALF_PI); //@return 1.2246467991473532E-16 (almost 0 due to inaccuracies)
cos(PI / 4); //@return 0.7069711821610654
Parameters: double degrees
Returns: float
Returns sine value as float for given degrees
sin(0); //@return 0.0
sin(90); //@return 1.0
sin(45); //@return 0.7072423542137346
Parameters: double degrees
Returns: float
Returns cosine value as float for given degrees
cos(0); //@return 1.0
cos(90); //@return 1.2246467991473532E-16 (almost 0 due to inaccuracies)
cos(45); //@return 0.7069711821610654
Parameters: double radians
Returns double
Returns value in degrees given in radians
toDegrees(PI); //@return 180.0
toDegrees(HALF_PI); //@return 90.0
Parameters: double radians
Returns double
Returns value in degrees given in radians
toDegrees(180); //@return 3.141592653589793
toDegrees(90); //@return 1.5707963267948966
Parameters: double y
, double x
Returns: double
Gives 2-argument arctangent for given x and y values
atan2(1, 1); //@return 0.7895463267948966
atan2(1, 3); //@return 0.3232758620689655
Parameters: double y
, double x
Returns: double
Gives 2-argument arctangent in degrees for given x and y values
atan2Deg(1, 1); //@return 45.23767225540443
atan2Deg(1, 3); //@return 18.52234251500506
Parameters: Random random
Returns: void
Sets new value for FXGLMath.random
Returns: Random
Returns current value of FXGLMath.random
Parameters: long seed
Returns: Random
Returns random value from seed
Parameters: int start
, int end
Returns: int
Returns random int between start
(inclusive) and end
(inclusive)
random(1, 10); //@return random number between 1 and 10
Parameters: long start
, long end
Returns: long
Returns random long between start
(inclusive) and end
(inclusive)
Parameters: double start
, double end
Returns: double
Returns random double between start
(inclusive) and end
(exclusive)
Returns: double
Returns random double between 0.0 (inclusive) and 1.0 (exclusive)
Returns: float
Returns random float between 0.0 (inclusive) and 1.0 (exclusive)
Returns: boolean
Returns random boolean value
Parameters: double chance
Returns: boolean
Returns boolean true if random double is less than chance given
// 10% chance of crit strike
float chance = 0.1f; // 10%
if (FXGLMath.randomBoolean(chance)) {
strikeCritical();
} else {
strikeNormal();
}
Returns: int
Returns randomly either 1 or -1
// move randomly either left or right
object.moveX(randomSign() * distance)
Parameters: Rectangle2D bounds
Returns: Point2D
returns random point in 2d space bound by bounds
rectangle
given by minX <= x < maxX, minY <= y < maxY
Returns: Vec2
returns random vector as vec2
// move randomly in any direction
object.move(randomVec2() * distance)
Returns: Point2D
returns random unit length vector as point2d
Returns: Color
returns random color using random doubles as RGB values
Parameters: T[] array
Returns: Optional<T>
returns random element of array or Optional.empty()
if array is empty
Parameters: List<T> list
Returns: Optional<T>
returns random element of list or Optional.empty()
if list is empty
Parameters: double x
Returns: double
returns square root of given x value
Parameters: float x
Returns: float
returns square root of given x value as float
Parameters: double value
, double currentRangeStart
, double currentRangeStop
, double targetRangeStart
, double targetRangeStop
Returns: double
Maps current value from current range onto target range as double
map(5, 0, 10, 0, 20) //@return 10.0
map(5, 0, 10, 10, 20) //@return 15.0
Parameters: float a
, float low
, float high
Returns: float
returns closest value to a
which is within low
and high
Parameters: float x
Returns: int
Returns x
rounded down to nearest int
Parameters: float value
Returns: float
Returns absolute value of given float value
Parameters: double value
Returns: double
Returns absolute value of given double value
Parameters: float a
, float b
Return: float
Returns smallest out of given float values a
and b
no NaN check
Parameters: float a
, float b
Return: float
Returns largest out of given float values a
and b
no NaN check
Parameters: Point2D p1
, Point2D p2
, Point2D p3
, double t
Returns: Point2D
Returns point at t
on bezier curve defined by points p1
, p2
, p3
Parameters: Point2D p1
, Point2D p2
, Point2D p3
, Point2D p4
, double t
Returns: Point2D
Returns point at t
on bezier curve defined by points p1
, p2
, p3
, p4
Parameters: double t
Returns: double
returns value of perlin noise at point given by t
Parameters: double x
, double y
Returns: double
returns value of simplex noise at point given by x
and y
Parameters: double x
, double y
, double z
Returns: double
returns value of simplex noise at point given by x
, y
and z
Parameters: long seed
Returns: PerlinNoiseGenerator
returns value of noise generator
Parameters: Rectangle2D rect1
, Rectangle2D rect2
Returns: double
returns distance between 2 rectangles rect1
and rect2