This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.
#include "ofMath.h"
#include "ofNoise.h"
#include "ofPolyline.h"
#include <float.h>
#include <sys/time.h>
Functions | |
int | ofNextPow2 (int a) |
Calculates the next larger power of 2. | |
void | ofSeedRandom () |
Seeds the random number generator with a unique value. | |
void | ofSetRandomSeed (unsigned long new_seed) |
Seed the random number generator. | |
void | ofSeedRandom (int val) |
Seed the random number generator. | |
float | ofRandom (float max) |
Get a random floating point number between 0 and max. | |
float | ofRandom (float x, float y) |
Get a random number between two values. | |
float | ofRandomf () |
Get a random floating point number. | |
float | ofRandomuf () |
Get a random unsigned floating point number. | |
float | ofNormalize (float value, float min, float max) |
Given a value and an input range, map the value to be within 0 and 1. | |
float | ofMap (float value, float inputMin, float inputMax, float outputMin, float outputMax, bool clamp) |
Given a value and an input range, map the value to an output range. | |
float | ofDist (float x1, float y1, float x2, float y2) |
Calculates the 2D distance between two points. | |
float | ofDist (float x1, float y1, float z1, float x2, float y2, float z2) |
Calculates the 3D distance between two points. | |
float | ofDistSquared (float x1, float y1, float x2, float y2) |
Calculates the squared 2D distance between two points. | |
float | ofDistSquared (float x1, float y1, float z1, float x2, float y2, float z2) |
Calculates the squared 3D distance between two points. | |
float | ofClamp (float value, float min, float max) |
Clamp a value between min and max. | |
int | ofSign (float n) |
Returns the sign of a number. | |
bool | ofInRange (float t, float min, float max) |
Determine if a number is inside of a giv(float)(en range. | |
float | ofRadToDeg (float radians) |
Convert radians to degrees. | |
float | ofDegToRad (float degrees) |
Convert degrees to radians. | |
float | ofLerp (float start, float stop, float amt) |
Linearly interpolate a value within a range. | |
float | ofWrap (float value, float from, float to) |
Find a value within a given range, wrapping the value if it overflows. | |
float | ofWrapRadians (float angle, float from, float to) |
float | ofWrapDegrees (float angle, float from, float to) |
float | ofLerpDegrees (float currentAngle, float targetAngle, float pct) |
Linearly interpolate a value between two angles in degrees. | |
float | ofLerpRadians (float currentAngle, float targetAngle, float pct) |
Linearly interpolate a value between two angles in radians. | |
float | ofNoise (float x) |
Calculates a one dimensional Perlin noise value between 0.0...1.0. | |
float | ofNoise (float x, float y) |
Calculates a two dimensional Perlin noise value between 0.0...1.0. | |
float | ofNoise (const glm::vec2 &p) |
Calculates a two dimensional Perlin noise value between 0.0...1.0. | |
float | ofNoise (float x, float y, float z) |
Calculates a three dimensional Perlin noise value between 0.0...1.0. | |
float | ofNoise (const glm::vec3 &p) |
Calculates a three dimensional Perlin noise value between 0.0...1.0. | |
float | ofNoise (float x, float y, float z, float w) |
Calculates a four dimensional Perlin noise value between 0.0...1.0. | |
float | ofNoise (const glm::vec4 &p) |
Calculates a four dimensional Perlin noise value between 0.0...1.0. | |
float | ofSignedNoise (float x) |
Calculates a one dimensional Perlin noise value between -1.0...1.0. | |
float | ofSignedNoise (float x, float y) |
Calculates a two dimensional Perlin noise value between -1.0...1.0. | |
float | ofSignedNoise (const glm::vec2 &p) |
Calculates a two dimensional Perlin noise value between -1.0...1.0. | |
float | ofSignedNoise (float x, float y, float z) |
Calculates a three dimensional Perlin noise value between -1.0...1.0. | |
float | ofSignedNoise (const glm::vec3 &p) |
Calculates a three dimensional Perlin noise value between -1.0...1.0. | |
float | ofSignedNoise (float x, float y, float z, float w) |
Calculates a four dimensional Perlin noise value between -1.0...1.0. | |
float | ofSignedNoise (const glm::vec4 &p) |
Calculates a four dimensional Perlin noise value between -1.0...1.0. | |
float | ofAngleDifferenceDegrees (float currentAngle, float targetAngle) |
Calculates the difference between two angles in degrees. | |
float | ofAngleDifferenceRadians (float currentAngle, float targetAngle) |
Calculates the difference between two angles in radians. | |
Function Documentation
◆ ofAngleDifferenceDegrees()
float ofAngleDifferenceDegrees | ( | float | currentAngle, |
float | targetAngle | ||
) |
Calculates the difference between two angles in degrees.
This will calculate the actual difference, taking into account multiple revolutions. For example:
- Parameters
-
currentAngle The current angle in degrees. targetAngle the angle to be compared to in degrees.
- Returns
- The difference between two angles in degrees.
◆ ofAngleDifferenceRadians()
float ofAngleDifferenceRadians | ( | float | currentAngle, |
float | targetAngle | ||
) |
Calculates the difference between two angles in radians.
This will calculate the actual difference, taking into account multiple revolutions. For example:
- Parameters
-
currentAngle The current angle in radians. targetAngle the angle to be compared to in radians.
- Returns
- The difference between two angles in radians.
◆ ofClamp()
float ofClamp | ( | float | value, |
float | min, | ||
float | max | ||
) |
Clamp a value between min and max.
Restricts a value to be within a specified range defined by values min and max. If the value is min <= value <= max, returns value. If the value is greater than max, return max; if the value is less than min, return min. Otherwise, return the value unchanged.
- Parameters
-
value The number to be clamped. min The lower bound of the range. max The upper bound of the range.
- Returns
- a floating point number in the range [min, max].
◆ ofDegToRad()
float ofDegToRad | ( | float | degrees | ) |
Convert degrees to radians.
Example:
- Parameters
-
degrees An angle in degrees.
- Returns
- the angle in radians.
◆ ofDist() [1/2]
float ofDist | ( | float | x1, |
float | y1, | ||
float | x2, | ||
float | y2 | ||
) |
Calculates the 2D distance between two points.
Uses the Pythagorean theorem.
- Parameters
-
x1 X position of first point. y1 Y position of first point. x2 X position of second point. y2 Y position of second point.
- Returns
- float Distance between points.
◆ ofDist() [2/2]
float ofDist | ( | float | x1, |
float | y1, | ||
float | z1, | ||
float | x2, | ||
float | y2, | ||
float | z2 | ||
) |
Calculates the 3D distance between two points.
Uses the Pythagorean theorem.
- Parameters
-
x1 X position of first point. y1 Y position of first point. z1 Z position of first point. x2 X position of second point. y2 Y position of second point. z2 Z position of second point.
- Returns
- float Distance between points.
◆ ofDistSquared() [1/2]
float ofDistSquared | ( | float | x1, |
float | y1, | ||
float | x2, | ||
float | y2 | ||
) |
Calculates the squared 2D distance between two points.
Same as ofDist() but doesn't take the square root sqrt() of the result, which is a faster operation if you need to calculate and compare multiple distances.
- Parameters
-
x1 X position of first point. y1 Y position of first point. x2 X position of second point. y2 Y position of second point.
- Returns
- distance-squared between two points.
◆ ofDistSquared() [2/2]
float ofDistSquared | ( | float | x1, |
float | y1, | ||
float | z1, | ||
float | x2, | ||
float | y2, | ||
float | z2 | ||
) |
Calculates the squared 3D distance between two points.
Same as ofDist() but doesn't take the square root sqrt() of the result, which is a faster operation if you need to calculate and compare multiple distances.
- Parameters
-
x1 X position of first point. y1 Y position of first point. z1 Z position of first point. x2 X position of second point. y2 Y position of second point. z2 Z position of second point.
- Returns
- distance-squared between two points.
◆ ofInRange()
bool ofInRange | ( | float | t, |
float | min, | ||
float | max | ||
) |
Determine if a number is inside of a giv(float)(en range.
- Parameters
-
t The value to test. min The lower bound of the range. max The upper bound of the range.
- Returns
- true if the number t is the range of [min, max].
◆ ofLerp()
float ofLerp | ( | float | start, |
float | stop, | ||
float | amt | ||
) |
Linearly interpolate a value within a range.
Calculates a number between two numbers [start, stop] at a specific increment (amt). If we want the new number to be between start and stop numbers, amt needs to be a number between 0 and 1, inclusive. ofLerp() does not clamp the values.
- See also
- float ofClamp(float value, float min, float max)
- Parameters
-
start The lower bound of the range. stop The upper bound of the range. amt The normalized [0, 1] value within the range to return.
- Returns
- A float between start and stop.
◆ ofLerpDegrees()
float ofLerpDegrees | ( | float | currentAngle, |
float | targetAngle, | ||
float | pct | ||
) |
Linearly interpolate a value between two angles in degrees.
Calculates a number between two numbers [start, stop) at a specific increment (amt). This does constrain the result into a single rotation, but does not clamp the values
- Parameters
-
currentAngle The lower bound of the range in degrees. targetAngle The upper bound of the range in degrees. pct An amount between [0.0, 1.0] within the range to return.
- Returns
- An angle in degrees between currentAngle and targetAngle.
◆ ofLerpRadians()
float ofLerpRadians | ( | float | currentAngle, |
float | targetAngle, | ||
float | pct | ||
) |
Linearly interpolate a value between two angles in radians.
Calculates a number between two numbers (start, stop) at a specific increment (amt). This does constrain the result into a single rotation, but does not clamp the values
- Parameters
-
currentAngle The lower bound of the range in radians. targetAngle The upper bound of the range in radians. pct An amount between [0.0, 1.0] within the range to return.
- Returns
- An angle in radians between currentAngle and targetAngle.
◆ ofMap()
float ofMap | ( | float | value, |
float | inputMin, | ||
float | inputMax, | ||
float | outputMin, | ||
float | outputMax, | ||
bool | clamp = false |
||
) |
Given a value and an input range, map the value to an output range.
ofMap linearly maps the given value to a new value given an input and output range. Thus if value is 50% of the way between inputMin and inputMax, the output value will be 50% of the way between outpuMin and outputMax. For an input value outside of the intputMin and inputMax range, negative percentages and percentages greater than 100% will be used. For example, if the input value is 150 and the input range is 0 - 100 and the output range 0 - 1000, the output value will be 1500 or 150% of the total range. The user can avoid mapping outside of the input range by clamping the output value. Clamping is disabled by default and ensures that the output value always stays in the range [outputMin, outputMax).
Example:
- Parameters
-
value The number to be mapped. inputMin The lower bound of the input range. inputMax The upper bound of the input range. outputMin The lower bound of the output range. outputMax The upper bound of the output range. clamp True if the value should be clamped to [outputMin, outputMax).
- Note
- If the absolute difference between inputMin and inputMax is less than std::numeric_limits<float>::epsilon(), outputMin will be returned to prevent divide by zero errors.
- Returns
- a mapped floating point number.
◆ ofNextPow2()
int ofNextPow2 | ( | int | a | ) |
Calculates the next larger power of 2.
If the input is already a power of 2, it will return itself.
Example:
- Parameters
-
a The starting point for finding the next power of 2.
- Returns
- value^2.
◆ ofNoise() [1/7]
float ofNoise | ( | const glm::vec2 & | p | ) |
Calculates a two dimensional Perlin noise value between 0.0...1.0.
◆ ofNoise() [2/7]
float ofNoise | ( | const glm::vec3 & | p | ) |
Calculates a three dimensional Perlin noise value between 0.0...1.0.
◆ ofNoise() [3/7]
float ofNoise | ( | const glm::vec4 & | p | ) |
Calculates a four dimensional Perlin noise value between 0.0...1.0.
◆ ofNoise() [4/7]
float ofNoise | ( | float | x | ) |
Calculates a one dimensional Perlin noise value between 0.0...1.0.
◆ ofNoise() [5/7]
float ofNoise | ( | float | x, |
float | y | ||
) |
Calculates a two dimensional Perlin noise value between 0.0...1.0.
◆ ofNoise() [6/7]
float ofNoise | ( | float | x, |
float | y, | ||
float | z | ||
) |
Calculates a three dimensional Perlin noise value between 0.0...1.0.
◆ ofNoise() [7/7]
float ofNoise | ( | float | x, |
float | y, | ||
float | z, | ||
float | w | ||
) |
Calculates a four dimensional Perlin noise value between 0.0...1.0.
◆ ofNormalize()
float ofNormalize | ( | float | value, |
float | min, | ||
float | max | ||
) |
Given a value and an input range, map the value to be within 0 and 1.
Often, you'll need to work with percentages or other methods that expect a value between 0 and 1. This function will take a minimum and maximum and then finds where within that range a value sits. If the value is outside the range, it will be mapped to 0 or 1.
- Parameters
-
value The number to be normalized. min The lower bound of the range. max The upper bound of the range.
- Returns
- A float between 0 and 1.
◆ ofRadToDeg()
float ofRadToDeg | ( | float | radians | ) |
Convert radians to degrees.
Example:
- Parameters
-
radians An angle in radians.
- Returns
- the angle in degrees.
◆ ofRandom() [1/2]
float ofRandom | ( | float | max | ) |
Get a random floating point number between 0 and max.
A random number in the range [0, max) will be returned.
Example:
- Warning
- ofRandom wraps C++'s
rand()
which is not reentrant or thread safe.
- Parameters
-
max The maximum value of the random number.
◆ ofRandom() [2/2]
float ofRandom | ( | float | val0, |
float | val1 | ||
) |
Get a random number between two values.
A random number in the range [min, max) will be returned.
Example:
- Warning
- ofRandom wraps
rand()
which is not reentrant or thread safe.
- Parameters
-
val0 the minimum value of the random number. val1 The maximum value of the random number.
- Returns
- A random floating point number between val0 and val1.
◆ ofRandomf()
float ofRandomf | ( | ) |
Get a random floating point number.
- Warning
- ofRandom wraps
rand()
which is not reentrant or thread safe.
- Returns
- A random floating point number between -1 and 1.
◆ ofRandomuf()
float ofRandomuf | ( | ) |
Get a random unsigned floating point number.
- Warning
- ofRandom wraps
rand()
which is not reentrant or thread safe.
- Returns
- A random floating point number between 0 and 1.
◆ ofSeedRandom() [1/2]
void ofSeedRandom | ( | ) |
Seeds the random number generator with a unique value.
This seeds the old-school srand-based random number generator with an acceptably random value, generated from clock time and the PID.
◆ ofSeedRandom() [2/2]
void ofSeedRandom | ( | int | val | ) |
Seed the random number generator.
If the user would like to repeat the same random sequence, a known random seed can be used to initialize the random number generator during app setup. This can be useful for debugging and testing.
- Parameters
-
val The value with which to seed the generator.
◆ ofSetRandomSeed()
void ofSetRandomSeed | ( | unsigned long | new_seed | ) |
Seed the random number generator.
This passes a seed value to the random engine; see of::random::Engine for details
- Parameters
-
val The value with which to seed the generator.
◆ ofSign()
int ofSign | ( | float | n | ) |
Returns the sign of a number.
- Returns
- int -1 if n is negative, 1 if n is positive, and 0 is n == 0;
◆ ofSignedNoise() [1/7]
float ofSignedNoise | ( | const glm::vec2 & | p | ) |
Calculates a two dimensional Perlin noise value between -1.0...1.0.
◆ ofSignedNoise() [2/7]
float ofSignedNoise | ( | const glm::vec3 & | p | ) |
Calculates a three dimensional Perlin noise value between -1.0...1.0.
◆ ofSignedNoise() [3/7]
float ofSignedNoise | ( | const glm::vec4 & | p | ) |
Calculates a four dimensional Perlin noise value between -1.0...1.0.
◆ ofSignedNoise() [4/7]
float ofSignedNoise | ( | float | x | ) |
Calculates a one dimensional Perlin noise value between -1.0...1.0.
◆ ofSignedNoise() [5/7]
float ofSignedNoise | ( | float | x, |
float | y | ||
) |
Calculates a two dimensional Perlin noise value between -1.0...1.0.
◆ ofSignedNoise() [6/7]
float ofSignedNoise | ( | float | x, |
float | y, | ||
float | z | ||
) |
Calculates a three dimensional Perlin noise value between -1.0...1.0.
◆ ofSignedNoise() [7/7]
float ofSignedNoise | ( | float | x, |
float | y, | ||
float | z, | ||
float | w | ||
) |
Calculates a four dimensional Perlin noise value between -1.0...1.0.
◆ ofWrap()
float ofWrap | ( | float | value, |
float | from, | ||
float | to | ||
) |
Find a value within a given range, wrapping the value if it overflows.
If a value is between from and to, return that value. If a value is NOT within that range, wrap it.
Example:
- Parameters
-
value The value to map. from The lower bound of the range.
- Returns
- to The upper bound of the range.
◆ ofWrapDegrees()
float ofWrapDegrees | ( | float | angle, |
float | from, | ||
float | to | ||
) |
◆ ofWrapRadians()
float ofWrapRadians | ( | float | angle, |
float | from, | ||
float | to | ||
) |