![]() |
ProtoTracer
1.0
Real-time 3D rendering and animation engine
|
A static utility class for mathematical operations commonly used throughout embedded or real-time applications. More...
#include <Mathematics.h>
Static Public Member Functions | |
static String | DoubleToCleanString (float value) |
Converts a floating-point value to a String, removing trailing decimals if not needed. | |
static bool | IsNaN (float value) |
Checks if a floating-point value is NaN (Not a Number). | |
static bool | IsInfinite (float value) |
Checks if a floating-point value is infinite. | |
static bool | IsFinite (float value) |
Checks if a floating-point value is finite. | |
static bool | IsClose (float v1, float v2, float epsilon) |
Checks if two values are close within a specified epsilon. | |
static int | Sign (float value) |
Determines the sign of a floating-point value. | |
static float | Pow (float value, float exponent) |
Raises a value to a given exponent. | |
static float | Sqrt (float value) |
Computes the square root of a value. | |
static float | Fract (float value) |
Returns the fractional part of a floating-point value. | |
static float | CosineInterpolation (float beg, float fin, float ratio) |
Applies a cosine-based interpolation between two values. | |
static float | CosineTransition (float beg, float fin, float ratio) |
A convenience alias for CosineInterpolation . | |
static float | BounceInterpolation (float beg, float fin, float ratio) |
A 'bounce'-like interpolation between two values. | |
static float | FFloor (float f) |
Floors a floating-point value (rounds down). | |
static float | FAbs (float f) |
Returns the absolute value of a floating-point number. | |
static float | FSqrt (float f) |
Computes the square root of a value (internal wrapper for std::sqrt ). | |
static float | HermiteInterpolation (float t) |
Hermite interpolation function for smooth transitions. | |
static float | QuinticInterpolation (float t) |
Quintic interpolation function for smooth transitions. | |
static float | Lerp (float a, float b, float t) |
Linear interpolation between two values. | |
static float | CubicLerp (float a, float b, float c, float d, float t) |
Cubic interpolation across four points (a, b, c, d). | |
static float | BilinearInterpolation (float scaleX, float scaleY, float x1, float y1, float x2, float y2, float v11, float v12, float v21, float v22) |
Performs a bilinear interpolation on a 2D grid. | |
static float | PingPong (float t) |
Repeats a value between 0 and 1, then mirrors back and forth (like a ping-pong). | |
static int | RoundUpWindow (int value, int multiple) |
Rounds value up to the nearest multiple of multiple . | |
template<typename T > | |
static T | Constrain (T value, T minimum, T maximum) |
Constrains a value between minimum and maximum. | |
template<typename T > | |
static T | DegreesToRadians (T degrees) |
Converts degrees to radians. | |
template<typename T > | |
static T | RadiansToDegrees (T radians) |
Converts radians to degrees. | |
template<typename T > | |
static T | Map (T value, T inLow, T inMax, T outMin, T outMax) |
Maps a value from one range to another. | |
template<typename T > | |
static T | Max (T value1, T value2) |
Returns the maximum of two values. | |
template<typename T > | |
static T | Min (T value1, T value2) |
Returns the minimum of two values. | |
template<typename T > | |
static T | Min (T v1, T v2, T v3) |
Returns the minimum of three values. | |
template<typename T > | |
static T | Max (T v1, T v2, T v3) |
Returns the maximum of three values. | |
template<typename T > | |
static T | ConstrainMap (T value, T inLow, T inMax, T outMin, T outMax) |
Combines Constrain and Map in one step: first maps value from [inLow, inMax] to [outMin, outMax], then constrains it to stay within [outMin, outMax]. | |
Static Public Attributes | |
static const float | EPSILON = 0.001f |
A small constant used for floating-point comparisons. | |
static const float | MPI = 3.14159265358979323846f |
Mathematical constant \(\pi\) (3.14159265358979323846...). | |
static const float | MPID180 = 0.01745329251994329576f |
The value of \(\pi \div 180.0\), useful for converting degrees to radians. | |
static const float | M180DPI = 57.29577951308232087684f |
The value of \(180.0 \div \pi\), useful for converting radians to degrees. | |
static const float | FLTMAX = __FLT_MAX__ |
Maximum float value (shortcut to a large number). | |
static const float | FLTMIN = __FLT_MIN__ |
Minimum float value (shortcut to a very small or near-zero number). | |
A static utility class for mathematical operations commonly used throughout embedded or real-time applications.
This class provides:
EPSILON
, MPI
, FLTMAX
).Definition at line 32 of file Mathematics.h.
|
static |
Performs a bilinear interpolation on a 2D grid.
This is often used for texture sampling or heightmap sampling.
scaleX | Normalized X interpolation factor (0 to 1). |
scaleY | Normalized Y interpolation factor (0 to 1). |
x1 | Left X coordinate. |
y1 | Bottom Y coordinate. |
x2 | Right X coordinate. |
y2 | Top Y coordinate. |
v11 | Value at (x1, y1). |
v12 | Value at (x1, y2). |
v21 | Value at (x2, y1). |
v22 | Value at (x2, y2). |
Definition at line 100 of file Mathematics.cpp.
Referenced by VectorField2D::GetVectorAtPosition().
A 'bounce'-like interpolation between two values.
beg | The start value. |
fin | The end value. |
ratio | A normalized ratio (0 to 1). |
Definition at line 59 of file Mathematics.cpp.
References Map().
Constrains a value between minimum and maximum.
T | A numeric type (e.g., int, float). |
value | The value to constrain. |
minimum | The lower bound. |
maximum | The upper bound. |
Referenced by RGBColor::Add(), VectorField2D::Advect(), HorizontalBlur::ApplyEffect(), PhaseOffsetR::ApplyEffect(), PhaseOffsetX::ApplyEffect(), PhaseOffsetY::ApplyEffect(), RadialBlur::ApplyEffect(), VerticalBlur::ApplyEffect(), BoundaryCube::CollideSphere(), Vector2D::Constrain(), Vector3D::Constrain(), Vector2D::Constrain(), Vector3D::Constrain(), VectorField2D::Diffuse(), DerivativeFilter::Filter(), FFTFilter::Filter(), MaterialMask::GetRGB(), VectorField2D::MovingSquareField(), VectorField2D::ObjectField(), RGBColor::Scale(), Effect::SetRatio(), VectorField2D::SineField(), VectorField2D::SpiralField(), VectorField2D::StepField(), MicrophoneSimple::Update(), Boot::Update(), Crash::Update(), ClockAnimation::Update(), MicrophoneSimple::Update(), and MyntAnimation::UpdateFFTVisemes().
Combines Constrain and Map in one step: first maps value
from [inLow, inMax] to [outMin, outMax], then constrains it to stay within [outMin, outMax].
T | A numeric type. |
value | The value to map/constrain. |
inLow | The lower bound of the input range. |
inMax | The upper bound of the input range. |
outMin | The lower bound of the output range. |
outMax | The upper bound of the output range. |
outMin
and outMax
. Referenced by HeadsUpDisplay::EnableBitFaceRender().
Applies a cosine-based interpolation between two values.
beg | The start value. |
fin | The end value. |
ratio | A normalized ratio (0 to 1). |
Definition at line 46 of file Mathematics.cpp.
References MPI.
Referenced by TriangleGroupDeformer::CosineInterpolationDeformer(), ObjectDeformer::CosineInterpolationDeformer(), CosineTransition(), Crash::FadeIn(), Crash::FadeOut(), AudioReactiveGradient::GetRGB(), Oscilloscope::GetRGB(), SpectrumAnalyzer::GetRGB(), and Boot::Update().
A convenience alias for CosineInterpolation
.
beg | The start value. |
fin | The end value. |
ratio | A normalized ratio (0 to 1). |
Definition at line 52 of file Mathematics.cpp.
References CosineInterpolation().
Cubic interpolation across four points (a, b, c, d).
a | First point. |
b | Second point (start). |
c | Third point (end). |
d | Fourth point. |
t | A normalized ratio (0 to 1). |
Definition at line 91 of file Mathematics.cpp.
Converts degrees to radians.
T | A numeric type. |
degrees | The angle in degrees. |
Referenced by Rotation::AxisAngleToQuaternion(), Rotation::EulerAnglesToQuaternion(), RotationMatrix::RotateX(), RotationMatrix::RotateY(), and RotationMatrix::RotateZ().
Converts a floating-point value to a String, removing trailing decimals if not needed.
value | The float to convert. |
String
without unnecessary trailing zeros. Definition at line 10 of file Mathematics.cpp.
Referenced by AxisAngle::ToString(), DirectionAngle::ToString(), Quaternion::ToString(), Vector2D::ToString(), Vector3D::ToString(), and YawPitchRoll::ToString().
Returns the absolute value of a floating-point number.
f | The float to evaluate. |
f
if f
>= 0, otherwise -f
. Definition at line 71 of file Mathematics.cpp.
Floors a floating-point value (rounds down).
f | The float to floor. |
f
. Definition at line 67 of file Mathematics.cpp.
Returns the fractional part of a floating-point value.
For example, Fract(3.75) = 0.75.
value | The float to evaluate. |
value
. Definition at line 42 of file Mathematics.cpp.
Referenced by SpiralMaterial::GetRGB().
Computes the square root of a value (internal wrapper for std::sqrt
).
f | The float to take the square root of. |
f
. Definition at line 75 of file Mathematics.cpp.
Hermite interpolation function for smooth transitions.
t | A normalized value (0 to 1). |
Definition at line 79 of file Mathematics.cpp.
Checks if two values are close within a specified epsilon.
v1 | The first value. |
v2 | The second value. |
epsilon | The tolerance for comparison. |
true
if v1
and v2
differ by less than epsilon
. Definition at line 26 of file Mathematics.cpp.
Referenced by DampedSpring::Calculate(), Quaternion::Divide(), Vector2D::Divide(), RampFilter::Filter(), ObjectAlign::GetPlaneOrientation(), AudioReactiveGradient::GetRGB(), Oscilloscope::GetRGB(), SpectrumAnalyzer::GetRGB(), VectorField2D::GetVectorAtPosition(), Quaternion::MultiplicativeInverse(), Quaternion::Multiply(), Vector2D::Multiply(), Vector2D::Normal(), Vector3D::Normal(), Vector2D::UnitCircle(), and Vector3D::UnitSphere().
Checks if a floating-point value is finite.
value | The float value to check. |
true
if finite, otherwise false
. Definition at line 22 of file Mathematics.cpp.
Referenced by Quaternion::IsInfinite().
Checks if a floating-point value is infinite.
value | The float value to check. |
true
if value
is infinite, otherwise false
. Definition at line 18 of file Mathematics.cpp.
Referenced by Quaternion::IsFinite().
Checks if a floating-point value is NaN (Not a Number).
value | The float value to check. |
true
if value
is NaN, otherwise false
. Definition at line 14 of file Mathematics.cpp.
Referenced by Quaternion::IsNaN().
Linear interpolation between two values.
a | The start value. |
b | The end value. |
t | A normalized ratio (0 to 1). |
Definition at line 87 of file Mathematics.cpp.
Maps a value from one range to another.
T | A numeric type. |
value | The value to map. |
inLow | The lower bound of the input range. |
inMax | The upper bound of the input range. |
outMin | The lower bound of the output range. |
outMax | The upper bound of the output range. |
Referenced by GlitchX::ApplyEffect(), HorizontalBlur::ApplyEffect(), PhaseOffsetR::ApplyEffect(), PhaseOffsetX::ApplyEffect(), PhaseOffsetY::ApplyEffect(), RadialBlur::ApplyEffect(), ShiftR::ApplyEffect(), VerticalBlur::ApplyEffect(), BounceInterpolation(), AudioReactiveGradient::GetRGB(), Oscilloscope::GetRGB(), SpectrumAnalyzer::GetRGB(), DepthMaterial::GetRGB(), Image::GetRGB(), UVMap::GetRGB(), VectorField2D::GetVectorAtPosition(), DrGonzoProject::Loading(), FunctionGenerator::SawtoothWave(), FanController::SetSpeed(), FunctionGenerator::SineWave(), FunctionGenerator::SquareWave(), FunctionGenerator::TriangleWave(), Boot::Update(), TVStatic::Update(), GalaxyAnimation::Update(), ClockAnimation::Update(), AlphaAnimation::Update(), PhysicsSimulator::Update(), and Controller::UpdateBrightness().
Returns the maximum of three values.
T | A numeric type. |
v1 | The first value. |
v2 | The second value. |
v3 | The third value. |
v1
, v2
, and v3
. Returns the maximum of two values.
T | A numeric type. |
value1 | The first value. |
value2 | The second value. |
value1
if value1
>= value2
, otherwise value2
. Referenced by Vector3D::AverageHighestTwoComponents(), Triangle2D::DidIntersectSAT(), ObjectAlign::GetPlaneOrientation(), and Vector3D::Max().
Returns the minimum of three values.
T | A numeric type. |
v1 | The first value. |
v2 | The second value. |
v3 | The third value. |
v1
, v2
, and v3
. Returns the minimum of two values.
T | A numeric type. |
value1 | The first value. |
value2 | The second value. |
value1
if value1
<= value2
, otherwise value2
. Referenced by ObjectAlign::AlignObjects(), Triangle2D::DidIntersectSAT(), ObjectAlign::GetObjectPlanarityRatio(), ObjectAlign::GetTransform(), and Vector3D::Min().
Repeats a value between 0 and 1, then mirrors back and forth (like a ping-pong).
For example, PingPong(t) toggles between [0..1..0..1...] as t
increases.
t | The time or input value. |
Definition at line 114 of file Mathematics.cpp.
Raises a value to a given exponent.
value | The base value. |
exponent | The exponent to raise by. |
value
raised to exponent
. Definition at line 34 of file Mathematics.cpp.
Referenced by Quaternion::Power(), and Quaternion::Power().
Quintic interpolation function for smooth transitions.
t | A normalized value (0 to 1). |
Definition at line 83 of file Mathematics.cpp.
Converts radians to degrees.
T | A numeric type. |
radians | The angle in radians. |
Referenced by Rotation::GetAxisAngle(), Rotation::GetDirectionAngle(), Rotation::GetEulerAngles(), and Rotation::GetYawPitchRoll().
Rounds value
up to the nearest multiple of multiple
.
value | The integer to round up. |
multiple | The multiple to round to. |
value
rounded up to the nearest multiple of multiple
. Definition at line 119 of file Mathematics.cpp.
Referenced by TriangleGroupDeformer::CosineInterpolationDeformer(), and ObjectDeformer::CosineInterpolationDeformer().
Determines the sign of a floating-point value.
value | The float to check. |
+1
if value
> 0, -1
if value
< 0, and 0
if value
== 0. Definition at line 30 of file Mathematics.cpp.
Computes the square root of a value.
value | The float to take the square root of. |
value
. Definition at line 38 of file Mathematics.cpp.
Referenced by Quaternion::Magnitude(), Vector2D::Magnitude(), Vector3D::Magnitude(), and Quaternion::Normal().
A small constant used for floating-point comparisons.
Definition at line 37 of file Mathematics.h.
Referenced by Quaternion::DeltaRotation(), Quaternion::Divide(), Vector2D::Divide(), Quaternion::Divide(), Vector2D::LineSegmentsIntersect(), Quaternion::MultiplicativeInverse(), Quaternion::Multiply(), Vector2D::Multiply(), Quaternion::Multiply(), Vector2D::Normal(), Vector3D::Normal(), Quaternion::RotateVector(), Quaternion::RotateVector(), Quaternion::RotateVectorUnit(), Quaternion::SphericalInterpolation(), Vector2D::UnitCircle(), Vector3D::UnitSphere(), Quaternion::UnrotateVector(), and Quaternion::UnrotateVector().
|
static |
Maximum float value (shortcut to a large number).
Definition at line 57 of file Mathematics.h.
|
static |
Minimum float value (shortcut to a very small or near-zero number).
Definition at line 62 of file Mathematics.h.
The value of \(180.0 \div \pi\), useful for converting radians to degrees.
Definition at line 52 of file Mathematics.h.
Referenced by Vector2D::RadiansToDegrees(), and Vector3D::RadiansToDegrees().
Mathematical constant \(\pi\) (3.14159265358979323846...).
Definition at line 42 of file Mathematics.h.
Referenced by PhaseOffsetR::ApplyEffect(), PhaseOffsetX::ApplyEffect(), PhaseOffsetY::ApplyEffect(), CosineInterpolation(), AudioReactiveGradient::GetRGB(), SpiralMaterial::GetRGB(), RGBColor::HueShift(), RGBColor::HueShift(), VectorField2D::MovingSquareField(), Rotation::QuaternionFromDirectionVectors(), VectorField2D::StepField(), and Menu::Update().
The value of \(\pi \div 180.0\), useful for converting degrees to radians.
Definition at line 47 of file Mathematics.h.
Referenced by Vector2D::DegreesToRadians(), Vector3D::DegreesToRadians(), Ellipse::IsInShape(), Rectangle::IsInShape(), and Vector2D::Rotate().