8 #ifndef META_OCEAN_MATH_RANDOM_H
9 #define META_OCEAN_MATH_RANDOM_H
29 template <
typename T>
class RandomT;
68 static inline T
sign();
83 static T
scalar(
const T lower,
const T upper);
361 template <
typename T>
364 if (rand() % 2u == 0u)
374 template <
typename T>
377 if (randomGenerator.
rand() % 2u == 0u)
387 template <
typename T>
390 ocean_assert(std::is_floating_point<T>::value);
392 ocean_assert(upper >= lower);
394 return T(rand()) * inverseMaxRand() * (upper - lower) + lower;
397 template <
typename T>
400 ocean_assert(std::is_floating_point<T>::value);
402 ocean_assert(upper >= lower);
404 return T(randomGenerator.
rand()) * inverseMaxRandomGenerator() * (upper - lower) + lower;
407 template <
typename T>
413 unsigned int debugN = 0u;
418 const T randomValue = scalar(T(-5.0) * sigma, T(5.0) * sigma);
419 const T check = scalar(T(0.0), maxValue);
426 ocean_assert(++debugN < 1000);
430 template <
typename T>
436 unsigned int debugN = 0u;
441 const T randomValue = scalar(randomGenerator, T(-5.0) * sigma, T(5.0) * sigma);
442 const T check = scalar(randomGenerator, T(0.0), maxValue);
449 ocean_assert(++debugN < 1000);
453 template <
typename T>
456 const T x = gaussianNoise(sigmaX);
457 const T y = gaussianNoise(sigmaY);
462 template <
typename T>
465 const T x = gaussianNoise(randomGenerator, sigmaX);
466 const T y = gaussianNoise(randomGenerator, sigmaY);
471 template <
typename T>
476 VectorT2<T> vector(scalar(T(-1.0), T(1.0)), scalar(T(-1.0), T(1.0)));
484 ocean_assert(
false &&
"This should never happen!");
488 template <
typename T>
493 const T x = scalar(randomGenerator, T(-1.0), T(1.0));
494 const T y = scalar(randomGenerator, T(-1.0), T(1.0));
504 ocean_assert(
false &&
"This should never happen!");
508 template <
typename T>
511 return VectorT2<T>(scalar(min, max), scalar(min, max));
514 template <
typename T>
517 const T x = scalar(randomGenerator, min, max);
518 const T y = scalar(randomGenerator, min, max);
523 template <
typename T>
526 return VectorT2<T>(scalar(xMin, xMax), scalar(yMin, yMax));
529 template <
typename T>
532 const T x = scalar(randomGenerator, xMin, xMax);
533 const T y = scalar(randomGenerator, yMin, yMax);
538 template <
typename T>
541 ocean_assert(range.
x() >= T(0.0) && range.
y() >= T(0.0) && range.
z() >= T(0.0));
543 return VectorT3<T>(scalar(-range.
x(), range.
x()), scalar(-range.
y(), range.
y()), scalar(-range.
z(), range.
z()));
546 template <
typename T>
549 ocean_assert(range.
x() >= T(0.0) && range.
y() >= T(0.0) && range.
z() >= T(0.0));
551 const T x = scalar(randomGenerator, -range.
x(), range.
x());
552 const T y = scalar(randomGenerator, -range.
y(), range.
y());
553 const T z = scalar(randomGenerator, -range.
z(), range.
z());
558 template <
typename T>
563 VectorT3<T> vector(scalar(T(-1.0), T(1.0)), scalar(T(-1.0), T(1.0)), scalar(T(-1.0), T(1.0)));
571 ocean_assert(
false &&
"This should never happen!");
575 template <
typename T>
580 const T x = scalar(randomGenerator, T(-1.0), T(1.0));
581 const T y = scalar(randomGenerator, T(-1.0), T(1.0));
582 const T z = scalar(randomGenerator, T(-1.0), T(1.0));
592 ocean_assert(
false &&
"This should never happen!");
596 template <
typename T>
599 return VectorT3<T>(scalar(min, max), scalar(min, max), scalar(min, max));
602 template <
typename T>
605 const T x = scalar(randomGenerator, min, max);
606 const T y = scalar(randomGenerator, min, max);
607 const T z = scalar(randomGenerator, min, max);
612 template <
typename T>
615 const T x = scalar(randomGenerator, xMin, xMax);
616 const T y = scalar(randomGenerator, yMin, yMax);
617 const T z = scalar(randomGenerator, zMin, zMax);
622 template <
typename T>
627 VectorT4<T> vector(scalar(T(-1.0), T(1.0)), scalar(T(-1.0), T(1.0)), scalar(T(-1.0), T(1.0)), scalar(T(-1.0), T(1.0)));
635 ocean_assert(
false &&
"This should never happen!");
639 template <
typename T>
644 const T x = scalar(randomGenerator, T(-1.0), T(1.0));
645 const T y = scalar(randomGenerator, T(-1.0), T(1.0));
646 const T z = scalar(randomGenerator, T(-1.0), T(1.0));
647 const T w = scalar(randomGenerator, T(-1.0), T(1.0));
657 ocean_assert(
false &&
"This should never happen!");
661 template <
typename T>
664 return VectorT4<T>(scalar(min, max), scalar(min, max), scalar(min, max), scalar(min, max));
667 template <
typename T>
670 const T x = scalar(randomGenerator, min, max);
671 const T y = scalar(randomGenerator, min, max);
672 const T z = scalar(randomGenerator, min, max);
673 const T w = scalar(randomGenerator, min, max);
678 template <
typename T>
684 template <
typename T>
693 template <
typename T>
699 template <
typename T>
708 template <
typename T>
714 template <
typename T>
719 return EulerT<T>(scalar(-range, range), scalar(-range, range), scalar(-range, range));
722 template <
typename T>
727 ocean_assert(minRange <= maxRange);
729 return EulerT<T>(scalar(minRange, maxRange) * sign(), scalar(minRange, maxRange) * sign(), scalar(minRange, maxRange) * sign());
732 template <
typename T>
742 template <
typename T>
747 const T yaw = scalar(randomGenerator, -range, range);
748 const T pitch = scalar(randomGenerator, -range, range);
749 const T roll = scalar(randomGenerator, -range, range);
754 template <
typename T>
759 ocean_assert(minRange <= maxRange);
761 const T yawSign = sign(randomGenerator);
762 const T yaw = scalar(randomGenerator, minRange, maxRange) * yawSign;
764 const T pitchSign = sign(randomGenerator);
765 const T pitch = scalar(randomGenerator, minRange, maxRange) * pitchSign;
767 const T rollSign = sign(randomGenerator);
768 const T roll = scalar(randomGenerator, minRange, maxRange) * rollSign;
773 template <
typename T>
776 return T(1.0) / T(RAND_MAX);
779 template <
typename T>
This class implements an euler rotation with angles: yaw, pitch and roll.
Definition: Euler.h:80
This class provides basic numeric functionalities.
Definition: Numeric.h:57
static T gaussianDistribution(const T x, const T sigma)
Returns a value of the univariate Gaussian distribution centered around the origin.
Definition: Numeric.h:3433
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:161
static constexpr unsigned int randMax()
Returns the maximal random value of this generator.
Definition: RandomGenerator.h:183
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:408
static QuaternionT< T > quaternion()
Returns a random rotation as unit quaternion.
Definition: Random.h:679
static VectorT3< T > vector3()
Returns a random 3D vector with length 1 which is equal distributed within a sphere.
Definition: Random.h:559
static VectorT2< T > gaussianNoiseVector2(const T sigmaX, const T sigmaY)
Returns a random 2D vector with Gaussian distribution.
Definition: Random.h:454
static RotationT< T > rotation()
Returns a random rotation.
Definition: Random.h:694
static T sign()
Returns a random sign (either +1 or -1).
Definition: Random.h:362
static constexpr T inverseMaxRand()
Returns the inverse of MAX_RAND.
Definition: Random.h:774
static VectorT4< T > vector4()
Returns a random 4D vector with length 1 which is equal distributed within a hyper sphere.
Definition: Random.h:623
static VectorT2< T > vector2()
Returns a random 2D vector with length 1 which is equal distributed within a circle.
Definition: Random.h:472
static constexpr T inverseMaxRandomGenerator()
Returns the inverse of RandomGenerator::randMax().
Definition: Random.h:780
static EulerT< T > euler()
Returns a random euler.
Definition: Random.h:709
static T scalar(const T lower, const T upper)
Returns a random number between two borders.
Definition: Random.h:388
This class implements a axis-angle rotation using floating point values.
Definition: Rotation.h:79
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:621
bool normalize()
Normalizes this vector.
Definition: Vector2.h:600
This class implements a vector with three elements.
Definition: Vector3.h:97
const T & y() const noexcept
Returns the y value.
Definition: Vector3.h:812
bool normalize()
Normalizes this vector.
Definition: Vector3.h:647
const T & x() const noexcept
Returns the x value.
Definition: Vector3.h:800
const T & z() const noexcept
Returns the z value.
Definition: Vector3.h:824
T sqr() const
Returns the square of the vector length.
Definition: Vector3.h:670
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:616
bool normalize()
Normalizes this vector.
Definition: Vector4.h:593
RandomT< double > RandomD
Instantiation of the RandomT template class using a double precision float data type.
Definition: Random.h:43
RandomT< Scalar > Random
Definition of the Random object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single ...
Definition: Random.h:29
RandomT< float > RandomF
Instantiation of the RandomT template class using a single precision float data type.
Definition: Random.h:50
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15