8#ifndef META_OCEAN_MATH_RANDOM_H
9#define META_OCEAN_MATH_RANDOM_H
29template <
typename T>
class RandomT;
83 static T
scalar(
const T lower,
const T upper);
353 if (rand() % 2u == 0u)
366 if (randomGenerator.
rand() % 2u == 0u)
379 ocean_assert(std::is_floating_point<T>::value);
381 ocean_assert(upper >= lower);
383 return lower + (upper - lower) * (T(rand()) / T(RAND_MAX));
389 ocean_assert(std::is_floating_point<T>::value);
391 ocean_assert(upper >= lower);
402 unsigned int debugN = 0u;
407 const T randomValue =
scalar(T(-5.0) * sigma, T(5.0) * sigma);
408 const T check =
scalar(T(0.0), maxValue);
415 ocean_assert(++debugN < 1000);
425 unsigned int debugN = 0u;
430 const T randomValue =
scalar(randomGenerator, T(-5.0) * sigma, T(5.0) * sigma);
431 const T check =
scalar(randomGenerator, T(0.0), maxValue);
438 ocean_assert(++debugN < 1000);
473 ocean_assert(
false &&
"This should never happen!");
482 const T x =
scalar(randomGenerator, T(-1.0), T(1.0));
483 const T y =
scalar(randomGenerator, T(-1.0), T(1.0));
493 ocean_assert(
false &&
"This should never happen!");
506 const T x =
scalar(randomGenerator, min, max);
507 const T y =
scalar(randomGenerator, min, max);
521 const T x =
scalar(randomGenerator, xMin, xMax);
522 const T y =
scalar(randomGenerator, yMin, yMax);
530 ocean_assert(range.
x() >= T(0.0) && range.
y() >= T(0.0) && range.
z() >= T(0.0));
538 ocean_assert(range.
x() >= T(0.0) && range.
y() >= T(0.0) && range.
z() >= T(0.0));
540 const T x =
scalar(randomGenerator, -range.
x(), range.
x());
541 const T y =
scalar(randomGenerator, -range.
y(), range.
y());
542 const T z =
scalar(randomGenerator, -range.
z(), range.
z());
560 ocean_assert(
false &&
"This should never happen!");
569 const T x =
scalar(randomGenerator, T(-1.0), T(1.0));
570 const T y =
scalar(randomGenerator, T(-1.0), T(1.0));
571 const T z =
scalar(randomGenerator, T(-1.0), T(1.0));
581 ocean_assert(
false &&
"This should never happen!");
594 const T x =
scalar(randomGenerator, min, max);
595 const T y =
scalar(randomGenerator, min, max);
596 const T z =
scalar(randomGenerator, min, max);
604 const T x =
scalar(randomGenerator, xMin, xMax);
605 const T y =
scalar(randomGenerator, yMin, yMax);
606 const T z =
scalar(randomGenerator, zMin, zMax);
624 ocean_assert(
false &&
"This should never happen!");
633 const T x =
scalar(randomGenerator, T(-1.0), T(1.0));
634 const T y =
scalar(randomGenerator, T(-1.0), T(1.0));
635 const T z =
scalar(randomGenerator, T(-1.0), T(1.0));
636 const T w =
scalar(randomGenerator, T(-1.0), T(1.0));
646 ocean_assert(
false &&
"This should never happen!");
659 const T x =
scalar(randomGenerator, min, max);
660 const T y =
scalar(randomGenerator, min, max);
661 const T z =
scalar(randomGenerator, min, max);
662 const T w =
scalar(randomGenerator, min, max);
718 ocean_assert(minRange <= maxRange);
738 const T yaw =
scalar(randomGenerator, -range, range);
739 const T pitch =
scalar(randomGenerator, -range, range);
740 const T roll =
scalar(randomGenerator, -range, range);
750 ocean_assert(minRange <= maxRange);
752 const T yawSign =
sign(randomGenerator);
753 const T yaw =
scalar(randomGenerator, minRange, maxRange) * yawSign;
755 const T pitchSign =
sign(randomGenerator);
756 const T pitch =
scalar(randomGenerator, minRange, maxRange) * pitchSign;
758 const T rollSign =
sign(randomGenerator);
759 const T roll =
scalar(randomGenerator, minRange, maxRange) * rollSign;
This class implements an euler rotation with angles: yaw, pitch and roll.
Definition Euler.h:82
static constexpr T pi_2()
Returns PI/2 which is equivalent to 90 degree.
Definition Numeric.h:938
static constexpr T pi()
Returns PI which is equivalent to 180 degree.
Definition Numeric.h:926
static T gaussianDistribution(const T x, const T sigma)
Returns a value of the univariate Gaussian distribution centered around the origin.
Definition Numeric.h:3458
This class implements a unit quaternion rotation.
Definition Quaternion.h:100
This class implements a generator for random numbers.
Definition RandomGenerator.h:42
unsigned int rand()
Returns the next random number.
Definition RandomGenerator.h:175
static constexpr unsigned int randMax()
Returns the maximal random value of this generator.
Definition RandomGenerator.h:211
This class provides base random functions and several random functions for integer data types.
Definition RandomI.h:29
This class provides several random functions for different data types using a floating point type for...
Definition Random.h:61
static T gaussianNoise(const T sigma)
Returns a random number with Gaussian distribution.
Definition Random.h:397
static VectorT2< T > vector2(RandomGenerator &randomGenerator, const T xMin, const T xMax, const T yMin, const T yMax)
Returns a random 2D vector with coordinates in a given range using an explicit random generator.
Definition Random.h:519
static QuaternionT< T > quaternion()
Returns a random rotation as unit quaternion.
Definition Random.h:668
static T gaussianNoise(RandomGenerator &randomGenerator, const T sigma)
Returns a random number with Gaussian distribution using an explicit random generator.
Definition Random.h:420
static VectorT2< T > gaussianNoiseVector2(RandomGenerator &randomGenerator, const T sigmaX, const T sigmaY)
Returns a random 2D vector with Gaussian distribution using an explicit random generator.
Definition Random.h:452
static VectorT2< T > vector2(RandomGenerator &randomGenerator, const T min, const T max)
Returns a random 2D vector with coordinates in a given range using an explicit random generator.
Definition Random.h:504
static VectorT2< T > vector2(const T xMin, const T xMax, const T yMin, const T yMax)
Returns a random 2D vector with coordinates in a given range.
Definition Random.h:513
static EulerT< T > euler(RandomGenerator &randomGenerator, const T range)
Returns a random euler with angles in a given range using an explicit random generator.
Definition Random.h:734
static VectorT4< T > vector4(RandomGenerator &randomGenerator)
Returns a random 4D vector with length 1 which is equal distributed within a hyper sphere using an ex...
Definition Random.h:629
static VectorT3< T > vector3()
Returns a random 3D vector with length 1 which is equal distributed within a sphere.
Definition Random.h:548
static VectorT2< T > gaussianNoiseVector2(const T sigmaX, const T sigmaY)
Returns a random 2D vector with Gaussian distribution.
Definition Random.h:443
static RotationT< T > rotation()
Returns a random rotation.
Definition Random.h:684
static VectorT3< T > vector3(RandomGenerator &randomGenerator, const T xMin, const T xMax, const T yMin, const T yMax, const T zMin, const T zMax)
Returns a random 3D vector with coordinates in a given range using an explicit random generator.
Definition Random.h:602
static EulerT< T > euler(const T minRange, const T maxRange)
Returns a random euler with angles in a given range.
Definition Random.h:714
static QuaternionT< T > quaternion(RandomGenerator &randomGenerator)
Returns a random rotation as unit quaternion using an explicit random generator.
Definition Random.h:676
static EulerT< T > euler(RandomGenerator &randomGenerator)
Returns a random euler using an explicit random generator.
Definition Random.h:724
static RotationT< T > rotation(RandomGenerator &randomGenerator)
Returns a random rotation using an explicit random generator.
Definition Random.h:692
static T sign()
Returns a random sign (either +1 or -1).
Definition Random.h:351
static VectorT3< T > vector3(const VectorT3< T > &range)
Returns a random 3D vector with coordinates in a given range.
Definition Random.h:528
static VectorT4< T > vector4()
Returns a random 4D vector with length 1 which is equal distributed within a hyper sphere.
Definition Random.h:612
static EulerT< T > euler(const T range)
Returns a random euler with angles in a given range.
Definition Random.h:706
static T sign(RandomGenerator &randomGenerator)
Returns a random sign (either +1 or -1).
Definition Random.h:364
static VectorT3< T > vector3(RandomGenerator &randomGenerator)
Returns a random 3D vector with length 1 which is equal distributed within a sphere using an explicit...
Definition Random.h:565
static VectorT2< T > vector2()
Returns a random 2D vector with length 1 which is equal distributed within a circle.
Definition Random.h:461
static T scalar(RandomGenerator &randomGenerator, const T lower, const T upper)
Returns a random number between two borders using an explicit random generator.
Definition Random.h:387
static VectorT3< T > vector3(RandomGenerator &randomGenerator, const T min, const T max)
Returns a random 3D vector with coordinates in a given range using an explicit random generator.
Definition Random.h:592
static VectorT3< T > vector3(const T min, const T max)
Returns a random 3D vector with coordinates in a given range.
Definition Random.h:586
static EulerT< T > euler()
Returns a random euler.
Definition Random.h:700
static VectorT2< T > vector2(RandomGenerator &randomGenerator)
Returns a random 2D vector with length 1 which is equal distributed within a circle using an explicit...
Definition Random.h:478
static VectorT4< T > vector4(const T min, const T max)
Returns a random 4D vector with coordinates in a given range.
Definition Random.h:651
static VectorT3< T > vector3(RandomGenerator &randomGenerator, const VectorT3< T > &range)
Returns a random 3D vector with coordinates in a given range using an explicit random generator.
Definition Random.h:536
static EulerT< T > euler(RandomGenerator &randomGenerator, const T minRange, const T maxRange)
Returns a random euler with angles in a given range using an explicit random generator.
Definition Random.h:746
static T scalar(const T lower, const T upper)
Returns a random number between two borders.
Definition Random.h:377
static VectorT4< T > vector4(RandomGenerator &randomGenerator, const T min, const T max)
Returns a random 4D vector with coordinates in a given range using an explicit random generator.
Definition Random.h:657
static VectorT2< T > vector2(const T min, const T max)
Returns a random 2D vector with coordinates in a given range.
Definition Random.h:498
This class implements a axis-angle rotation using floating point values.
Definition Rotation.h:73
This class implements a vector with two elements.
Definition Vector2.h:96
T sqr() const
Returns the square of the vector length.
Definition Vector2.h:626
bool normalize()
Normalizes this vector.
Definition Vector2.h:605
This class implements a vector with three elements.
Definition Vector3.h:97
const T & y() const noexcept
Returns the y value.
Definition Vector3.h:816
bool normalize()
Normalizes this vector.
Definition Vector3.h:651
const T & x() const noexcept
Returns the x value.
Definition Vector3.h:804
const T & z() const noexcept
Returns the z value.
Definition Vector3.h:828
T sqr() const
Returns the square of the vector length.
Definition Vector3.h:674
This class implements a vector with four elements.
Definition Vector4.h:97
T sqr() const
Returns the square of the vector length.
Definition Vector4.h:619
bool normalize()
Normalizes this vector.
Definition Vector4.h:596
RandomT< float > RandomF
Instantiation of the RandomT template class using a single precision float data type.
Definition Random.h:50
RandomT< Scalar > Random
Definition of the Random object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single ...
Definition Random.h:36
RandomT< double > RandomD
Instantiation of the RandomT template class using a double precision float data type.
Definition Random.h:43
The namespace covering the entire Ocean framework.
Definition Accessor.h:15