8#ifndef META_OCEAN_MATH_RANDOM_H
9#define META_OCEAN_MATH_RANDOM_H
29template <
typename T>
class RandomT;
68 static inline T
sign();
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);
445 const T x = gaussianNoise(sigmaX);
446 const T y = gaussianNoise(sigmaY);
454 const T x = gaussianNoise(randomGenerator, sigmaX);
455 const T y = gaussianNoise(randomGenerator, sigmaY);
465 VectorT2<T> vector(scalar(T(-1.0), T(1.0)), scalar(T(-1.0), T(1.0)));
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!");
500 return VectorT2<T>(scalar(min, max), scalar(min, max));
506 const T x = scalar(randomGenerator, min, max);
507 const T y = scalar(randomGenerator, min, max);
515 return VectorT2<T>(scalar(xMin, xMax), scalar(yMin, yMax));
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));
532 return VectorT3<T>(scalar(-range.
x(), range.
x()), scalar(-range.
y(), range.
y()), scalar(-range.
z(), range.
z()));
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());
552 VectorT3<T> vector(scalar(T(-1.0), T(1.0)), scalar(T(-1.0), T(1.0)), scalar(T(-1.0), T(1.0)));
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!");
588 return VectorT3<T>(scalar(min, max), scalar(min, max), scalar(min, max));
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);
616 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)));
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!");
653 return VectorT4<T>(scalar(min, max), scalar(min, max), scalar(min, max), scalar(min, max));
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);
710 return EulerT<T>(scalar(-range, range), scalar(-range, range), scalar(-range, range));
718 ocean_assert(minRange <= maxRange);
720 return EulerT<T>(scalar(minRange, maxRange) * sign(), scalar(minRange, maxRange) * sign(), scalar(minRange, maxRange) * sign());
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
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: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 QuaternionT< T > quaternion()
Returns a random rotation as unit quaternion.
Definition Random.h:668
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 T sign()
Returns a random sign (either +1 or -1).
Definition Random.h:351
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 VectorT2< T > vector2()
Returns a random 2D vector with length 1 which is equal distributed within a circle.
Definition Random.h:461
static EulerT< T > euler()
Returns a random euler.
Definition Random.h:700
static T scalar(const T lower, const T upper)
Returns a random number between two borders.
Definition Random.h:377
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:633
bool normalize()
Normalizes this vector.
Definition Vector2.h:612
This class implements a vector with three elements.
Definition Vector3.h:97
const T & y() const noexcept
Returns the y value.
Definition Vector3.h:824
bool normalize()
Normalizes this vector.
Definition Vector3.h:659
const T & x() const noexcept
Returns the x value.
Definition Vector3.h:812
const T & z() const noexcept
Returns the z value.
Definition Vector3.h:836
T sqr() const
Returns the square of the vector length.
Definition Vector3.h:682
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:628
bool normalize()
Normalizes this vector.
Definition Vector4.h:605
The namespace covering the entire Ocean framework.
Definition Accessor.h:15