Additional functions for common mathematical operations. More...
Functions | |
template<typename T , typename U > | |
constexpr U | playrho::Secant (T target, U a1, T s1, U a2, T s2) noexcept |
Secant method. More... | |
template<typename T > | |
constexpr T | playrho::Bisect (T a1, T a2) noexcept |
Bisection method. More... | |
template<typename T > | |
constexpr bool | playrho::IsOdd (T val) noexcept |
Is-odd. More... | |
template<class TYPE > | |
constexpr auto | playrho::Square (TYPE t) noexcept |
Squares the given value. | |
template<typename T > | |
auto | playrho::Atan2 (T y, T x) |
Computes the arc-tangent of the given y and x values. More... | |
template<typename T , typename = std::enable_if_t< IsIterable<T>::value && IsAddable<decltype(*begin(std::declval<T>()))>::value> | |
auto | playrho::Average (const T &span) |
Computes the average of the given values. | |
template<typename T > | |
std::enable_if_t< IsArithmetic< T >::value, T > | playrho::RoundOff (T value, unsigned precision=100000) |
Computes the rounded value of the given value. | |
Vec2 | playrho::RoundOff (Vec2 value, std::uint32_t precision=100000) |
Computes the rounded value of the given value. | |
template<typename T , std::size_t N> | |
constexpr Vector< T, N > | playrho::abs (const Vector< T, N > &v) noexcept |
Absolute value function for vectors. | |
d2::UnitVec | playrho::abs (const d2::UnitVec &v) noexcept |
Gets the absolute value of the given value. | |
template<typename T > | |
constexpr std::enable_if_t< std::is_arithmetic< T >::value, bool > | playrho::AlmostZero (T value) |
Gets whether a given value is almost zero. More... | |
template<typename T > | |
constexpr std::enable_if_t< std::is_floating_point< T >::value, bool > | playrho::AlmostEqual (T x, T y, int ulp=2) |
Determines whether the given two values are "almost equal". | |
template<typename T > | |
auto | playrho::ModuloViaFmod (T dividend, T divisor) noexcept |
Modulo operation using std::fmod . More... | |
template<typename T > | |
auto | playrho::ModuloViaTrunc (T dividend, T divisor) noexcept |
Modulo operation using std::trunc . More... | |
Angle | playrho::GetNormalized (Angle value) noexcept |
Gets the "normalized" value of the given angle. More... | |
template<class T > | |
Angle | playrho::GetAngle (const Vector2< T > value) |
Gets the angle. More... | |
template<typename T > | |
constexpr auto | playrho::GetMagnitudeSquared (T value) noexcept |
Gets the square of the magnitude of the given iterable value. More... | |
template<typename T > | |
auto | playrho::GetMagnitude (T value) |
Gets the magnitude of the given value. More... | |
template<typename T1 , typename T2 > | |
constexpr auto | playrho::Dot (const T1 a, const T2 b) noexcept |
Performs the dot product on two vectors (A and B). More... | |
template<class T1 , class T2 , std::enable_if_t< std::tuple_size< T1 >::value==2 &&std::tuple_size< T2 >::value==2, int > = 0> | |
constexpr auto | playrho::Cross (T1 a, T2 b) noexcept |
Performs the 2-element analog of the cross product of two vectors. More... | |
template<typename T , typename U > | |
constexpr auto | playrho::Solve (const Matrix22< U > mat, const Vector2< T > b) noexcept |
Solves A * x = b, where b is a column vector. More... | |
template<class IN_TYPE > | |
constexpr auto | playrho::Invert (const Matrix22< IN_TYPE > value) noexcept |
Inverts the given value. | |
constexpr Vec3 | playrho::Solve33 (const Mat33 &mat, const Vec3 b) noexcept |
Solves A * x = b, where b is a column vector. More... | |
template<typename T > | |
constexpr T | playrho::Solve22 (const Mat33 &mat, const T b) noexcept |
Solves A * x = b, where b is a column vector. More... | |
constexpr Mat33 | playrho::GetInverse22 (const Mat33 &value) noexcept |
Gets the inverse of the given matrix as a 2-by-2. More... | |
constexpr Mat33 | playrho::GetSymInverse33 (const Mat33 &value) noexcept |
Gets the symmetric inverse of this matrix as a 3-by-3. More... | |
template<class T > | |
constexpr auto | playrho::GetRevPerpendicular (const T vector) noexcept |
Gets a vector counter-clockwise (reverse-clockwise) perpendicular to the given vector. More... | |
template<class T > | |
constexpr auto | playrho::GetFwdPerpendicular (const T vector) noexcept |
Gets a vector clockwise (forward-clockwise) perpendicular to the given vector. More... | |
template<std::size_t M, typename T1 , std::size_t N, typename T2 > | |
constexpr auto | playrho::Transform (const Vector< T1, M > v, const Matrix< T2, M, N > &m) noexcept |
Multiplies an M-element vector by an M-by-N matrix. More... | |
constexpr Vec2 | playrho::Transform (const Vec2 v, const Mat33 &A) noexcept |
Multiplies a vector by a matrix. | |
constexpr Vec2 | playrho::InverseTransform (const Vec2 v, const Mat22 &A) noexcept |
Multiply a matrix transpose times a vector. If a rotation matrix is provided, then this transforms the vector from one frame to another (inverse transform). | |
constexpr Mat22 | playrho::MulT (const Mat22 &A, const Mat22 &B) noexcept |
Computes A^T * B. | |
Mat22 | playrho::abs (const Mat22 &A) |
Gets the absolute value of the given value. | |
template<typename T > | |
constexpr T | playrho::NextPowerOfTwo (T x) |
Gets the next largest power of 2. More... | |
Real | playrho::Normalize (Vec2 &vector) |
Converts the given vector into a unit vector and returns its original length. | |
Length2 | playrho::ComputeCentroid (const Span< const Length2 > &vertices) |
Computes the centroid of a counter-clockwise array of 3 or more vertices. More... | |
template<typename T > | |
constexpr T | playrho::GetModuloNext (T value, T count) noexcept |
Gets the modulo next value. | |
template<typename T > | |
constexpr T | playrho::GetModuloPrev (T value, T count) noexcept |
Gets the modulo previous value. | |
Angle | playrho::GetDelta (Angle a1, Angle a2) noexcept |
Gets the shortest angular distance to go from angle 1 to angle 2. More... | |
constexpr Angle | playrho::GetRevRotationalAngle (Angle a1, Angle a2) noexcept |
Gets the reverse (counter) clockwise rotational angle to go from angle 1 to angle 2. More... | |
std::vector< Length2 > | playrho::GetCircleVertices (Length radius, unsigned slices, Angle start=0_deg, Real turns=Real{1}) |
Gets the vertices for a circle described by the given parameters. | |
NonNegative< Area > | playrho::GetAreaOfCircle (Length radius) |
Gets the area of a circle. | |
NonNegative< Area > | playrho::GetAreaOfPolygon (Span< const Length2 > vertices) |
Gets the area of a polygon. More... | |
SecondMomentOfArea | playrho::GetPolarMoment (Span< const Length2 > vertices) |
Gets the polar moment of the area enclosed by the given vertices. More... | |
template<typename T , std::size_t N> | |
constexpr Vector< T, N > | abs (const Vector< T, N > &v) noexcept |
Absolute value function for vectors. | |
Additional functions for common mathematical operations.
These are non-member non-friend functions for mathematical operations especially those with mixed input and output types.
|
constexpr |
Gets whether a given value is almost zero.
An almost zero value is "subnormal". Dividing by these values can lead to odd results like a divide by zero trap occurring.
true
if the given value is almost zero, false
otherwise.
|
inline |
Computes the arc-tangent of the given y and x values.
Referenced by playrho::d2::GetAngle(), and playrho::GetAngle().
|
constexprnoexcept |
Bisection method.
Referenced by playrho::d2::GetToiViaSat().
Computes the centroid of a counter-clockwise array of 3 or more vertices.
Referenced by playrho::d2::PolygonShapeConf::Set().
|
constexprnoexcept |
Performs the 2-element analog of the cross product of two vectors.
Cross-products the given two values.
Defined as the result of: (a.x * b.y) - (a.y * b.x)
.
a | Value A of a 3-element type. |
b | Value B of a 3-element type. |
Referenced by playrho::d2::ApplyForce(), playrho::d2::ApplyLinearImpulse(), playrho::d2::Simplex::CalcMetric(), playrho::d2::CalcSearchDirection(), playrho::ComputeCentroid(), playrho::d2::Simplex::Get(), playrho::d2::GetConvexHullAsVector(), playrho::d2::GetEffectiveInvMass(), playrho::d2::GetMassData(), playrho::d2::VelocityConstraint::GetPoint(), playrho::GetPolarMoment(), playrho::GetSymInverse33(), playrho::d2::InitVelocity(), playrho::Invert(), playrho::d2::RayCast(), playrho::d2::SetForce(), playrho::Solve(), playrho::Solve33(), playrho::d2::SolvePosition(), playrho::d2::SolveVelocity(), and playrho::d2::Validate().
|
constexprnoexcept |
Performs the dot product on two vectors (A and B).
The dot product of two vectors is defined as: the magnitude of vector A, multiplied by, the magnitude of vector B, multiplied by, the cosine of the angle between the two vectors (A and B). Thus the dot product of two vectors is a value ranging between plus and minus the magnitudes of each vector times each other. The middle value of 0 indicates that two vectors are perpendicular to each other (at an angle of +/- 90 degrees from each other).
GetMagnitudeSquared(Vec2)
returns the same value using effectively one less input parameter. std::inner_product
standard library algorithm except benchmark tests suggest this implementation is faster at least for Vec2
like instances.Referenced by playrho::d2::ClipSegmentToLine(), playrho::d2::Simplex::Get(), playrho::d2::GetGearJointConf(), playrho::d2::GetJointTranslation(), playrho::d2::GetLinearVelocity(), playrho::d2::GetManifold(), playrho::d2::VelocityConstraint::GetPoint(), playrho::d2::GetSeparationScenario(), playrho::d2::GetSupportIndex(), playrho::GetSymInverse33(), playrho::d2::InitVelocity(), playrho::InverseTransform(), playrho::MulT(), playrho::d2::RayCast(), playrho::Solve33(), playrho::d2::SolvePosition(), playrho::d2::SolveVelocity(), and playrho::d2::TestPoint().
Gets the angle.
Referenced by playrho::d2::Body::SetAcceleration().
NonNegative< Area > playrho::GetAreaOfPolygon | ( | Span< const Length2 > | vertices | ) |
Gets the area of a polygon.
Gets the shortest angular distance to go from angle 1 to angle 2.
This gets the angle to rotate angle 1 by in order to get to angle 2 with the least amount of rotation.
|
constexprnoexcept |
Gets a vector clockwise (forward-clockwise) perpendicular to the given vector.
This takes a vector of form (x, y) and returns the vector (y, -x).
vector | Vector to return a clockwise perpendicular equivalent for. |
Referenced by playrho::d2::ConvexHull::Get().
Gets the inverse of the given matrix as a 2-by-2.
Referenced by playrho::d2::InitVelocity().
|
inline |
Gets the magnitude of the given value.
GetMagnitudeSquared
also works. Referenced by playrho::d2::Simplex::CalcMetric(), playrho::d2::GetCentripetalForce(), playrho::d2::GetCurrentLengthA(), playrho::d2::GetCurrentLengthB(), playrho::d2::GetDistanceJointConf(), playrho::d2::ChainShapeConf::GetMassData(), playrho::d2::GetMassData(), playrho::d2::GetPulleyJointConf(), playrho::Normalize(), and playrho::d2::SolvePosition().
|
constexprnoexcept |
Gets the square of the magnitude of the given iterable value.
GetMagnitude(T value)
(if possible). Referenced by playrho::d2::CalcGravitationalAcceleration(), playrho::d2::Cap(), playrho::d2::Distance(), playrho::d2::VertexSet::find(), playrho::d2::FindClosestBody(), playrho::d2::GetConvexHullAsVector(), playrho::d2::GetLocalRotInertia(), playrho::GetMagnitude(), playrho::d2::GetManifold(), playrho::d2::GetMassData(), playrho::d2::GetToiViaSat(), playrho::d2::IsUnderActive(), playrho::d2::RayCast(), playrho::d2::Body::SetAcceleration(), playrho::d2::SolvePosition(), playrho::d2::SolveVelocity(), playrho::d2::TestOverlap(), playrho::d2::TestPoint(), and playrho::d2::WorldImpl::Update().
Gets the "normalized" value of the given angle.
Referenced by playrho::GetDelta(), and playrho::d2::GetNormalized().
SecondMomentOfArea playrho::GetPolarMoment | ( | Span< const Length2 > | vertices | ) |
Gets the polar moment of the area enclosed by the given vertices.
vertices | Collection of three or more vertices. |
Referenced by playrho::d2::GetMassData().
|
constexprnoexcept |
Gets a vector counter-clockwise (reverse-clockwise) perpendicular to the given vector.
This takes a vector of form (x, y) and returns the vector (-y, x).
vector | Vector to return a counter-clockwise perpendicular equivalent for. |
Gets the reverse (counter) clockwise rotational angle to go from angle 1 to angle 2.
Gets the symmetric inverse of this matrix as a 3-by-3.
Referenced by playrho::d2::InitVelocity().
|
constexprnoexcept |
Is-odd.
Determines whether the given integral value is odd (as opposed to being even).
Referenced by playrho::d2::GetToiViaSat().
|
inlinenoexcept |
Modulo operation using std::fmod
.
std::fmod
appears slower than via std::trunc
. Referenced by playrho::GetNormalized().
|
inlinenoexcept |
Modulo operation using std::trunc
.
std::fmod
appears slower than via std::trunc
. Referenced by playrho::GetNormalized().
|
constexpr |
Gets the next largest power of 2.
Given a binary integer value x, the next largest power of 2 can be computed by a S.W.A.R. algorithm that recursively "folds" the upper bits into the lower bits. This process yields a bit vector with the same most significant 1 as x, but all one's below it. Adding 1 to that value yields the next largest power of 2.
Referenced by playrho::d2::DynamicTree::Reserve().
|
constexprnoexcept |
Secant method.
Referenced by playrho::d2::GetToiViaSat().
|
constexprnoexcept |
Solves A * x = b, where b is a column vector.
Referenced by playrho::d2::SolvePosition().
|
constexprnoexcept |
Solves A * x = b, where b is a column vector.
Referenced by playrho::d2::SolvePosition(), and playrho::d2::SolveVelocity().
Solves A * x = b, where b is a column vector.
Referenced by playrho::d2::SolvePosition(), and playrho::d2::SolveVelocity().
|
constexprnoexcept |
Multiplies an M-element vector by an M-by-N matrix.
v | Vector that's interpreted as a matrix with 1 row and M-columns. |
m | An M-row by N-column transformation matrix to multiply the vector by. |