HighMap library (C++)
Loading...
Searching...
No Matches
math.hpp File Reference

Provides core mathematical utilities for procedural generation, including trigonometry, exponential/logarithmic functions, smooth transitions (smoothstep), distance metrics (Chebyshev, Euclidian), and phasor profiles. Offers optimized approximations (hypotenuse, inverse sqrt) and array-based operations for terrain modeling and noise synthesis. More...

Go to the source code of this file.

Namespaces

namespace  hmap
 

Enumerations

enum  hmap::DistanceFunction : int { hmap::CHEBYSHEV , hmap::EUCLIDIAN , hmap::EUCLISHEV , hmap::MANHATTAN }
 Distance function type. More...
 
enum  hmap::PhasorProfile : int {
  hmap::COSINE_BULKY , hmap::COSINE_PEAKY , hmap::COSINE_SQUARE , hmap::COSINE_STD ,
  hmap::TRIANGLE
}
 Phasor angular profile type. More...
 

Functions

Array hmap::abs (const Array &array)
 Return the absolute value of the array elements.
 
Array hmap::abs_smooth (const Array &array, float mu, const Array &vshift)
 Return the smooth absolute value of the array elements.
 
Array hmap::abs_smooth (const Array &array, float mu, float vshift)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
Array hmap::abs_smooth (const Array &array, float mu)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
float hmap::abs_smooth (float a, float mu)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
Array hmap::almost_unit_identity (const Array &array)
 Return the almost unit identity function.
 
float hmap::almost_unit_identity (float x)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
float hmap::almost_unit_identity_c2 (float x)
 Return the almost unit identity function (with a second-order derivative equals 0 at x = 1 also to avoid discontinuities in some cases)
 
float hmap::approx_hypot (float a, float b)
 Return the approximate hypothenuse of two numbers.
 
float hmap::approx_rsqrt (float a)
 Return the approximate inverse square root of a number.
 
Array hmap::atan (const Array &array)
 Return the arctan of the array elements.
 
Array hmap::atan2 (const Array &y, const Array &x)
 Computes the element-wise arctangent of two arrays, considering the signs of both inputs.
 
Array hmap::cos (const Array &array)
 Return the cosine of the array elements.
 
Array hmap::exp (const Array &array)
 Return the exponantial of the array elements.
 
float hmap::gain (float x, float factor)
 
Array hmap::gaussian_decay (const Array &array, float sigma)
 Return the Gaussian of the array elements.
 
std::function< float(float, float)> hmap::get_distance_function (DistanceFunction dist_fct)
 Return the requested distance function.
 
std::function< float(float)> hmap::get_phasor_profile_function (const PhasorProfile &phasor_profile, float delta, float *p_profile_avg=nullptr)
 Generates a function representing a phasor profile based on the specified type and parameters.
 
int hmap::highest_power_of_2 (int n)
 Computes the highest power of 2 less than or equal to the given number.
 
Array hmap::lerp (const Array &array1, const Array &array2, const Array &t)
 Return the linear interpolation between two arrays by a parameter t.
 
Array hmap::lerp (const Array &array1, const Array &array2, float t)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
float hmap::lerp (float a, float b, float t)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
Array hmap::log10 (const Array &array)
 Return the log10 of the array elements.
 
Array hmap::pow (const Array &array, float exp)
 Return the array elements raised to the power 'exp'.
 
void hmap::radial_displacement_to_xy (const Array &dr, Array &dx, Array &dy, float smoothing=1.f, Vec2< float > center={0.5f, 0.5f}, Vec4< float > bbox={0.f, 1.f, 0.f, 1.f})
 Interpret the input array dr as a radial displacement and convert it to a pair of displacements dx and dy in cartesian coordinates.
 
Array hmap::sin (const Array &array)
 Return the sine of the array elements.
 
Array hmap::smoothstep3 (const Array &array, float vmin=0.f, float vmax=1.f)
 Return the 3rd order smoothstep function of the array elements.
 
float hmap::smoothstep3 (float x)
 Return the 3rd order smoothstep function.
 
float hmap::smoothstep3_lower (float x)
 Return the 3rd order smoothstep function, with zero derivative only at 0.
 
Array hmap::smoothstep3_lower (const Array &x)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
float hmap::smoothstep3_upper (float x)
 Return the 3rd order smoothstep function, with zero derivative only at 1.
 
Array hmap::smoothstep3_upper (const Array &x)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
Array hmap::smoothstep5 (const Array &array, float vmin=0.f, float vmax=1.f)
 Return the 5rd order smoothstep function of the array elements.
 
Array hmap::smoothstep5 (const Array &array, const Array &vmin, const Array &vmax)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
float hmap::smoothstep5 (float x)
 Return the 5rd order smoothstep function.
 
float hmap::smoothstep5_lower (float x)
 Return the 5rd order smoothstep function, with zero derivative only at 0.
 
Array hmap::smoothstep5_lower (const Array &x)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
float hmap::smoothstep5_upper (float x)
 Return the 5rd order smoothstep function, with zero derivative only at 1.
 
Array hmap::smoothstep5_upper (const Array &x)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
float hmap::smoothstep7 (float x)
 Return the 7th order smoothstep function.
 
Array hmap::smoothstep7 (const Array &x)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
Array hmap::sqrt (const Array &array)
 Return the square root of the array elements.
 
Array hmap::sqrt_safe (const Array &array)
 

Detailed Description

Provides core mathematical utilities for procedural generation, including trigonometry, exponential/logarithmic functions, smooth transitions (smoothstep), distance metrics (Chebyshev, Euclidian), and phasor profiles. Offers optimized approximations (hypotenuse, inverse sqrt) and array-based operations for terrain modeling and noise synthesis.

Author
Otto Link (otto..nosp@m.link.nosp@m..bv@g.nosp@m.mail.nosp@m..com)
Author
Otto Link (otto..nosp@m.link.nosp@m..bv@g.nosp@m.mail.nosp@m..com)
Version
0.1
Date
2023-04-30