global functions

- ofAngleDifferenceDegrees()
- ofAngleDifferenceRadians()
- ofBezierPoint()
- ofBezierTangent()
- ofClamp()
- ofCurvePoint()
- ofCurveTangent()
- ofDegToRad()
- ofDist()
- ofDistSquared()
- ofInRange()
- ofInterpolateCatmullRom()
- ofInterpolateCosine()
- ofInterpolateCubic()
- ofInterpolateHermite()
- ofIsFloatEqual()
- ofLerp()
- ofLerpDegrees()
- ofLerpRadians()
- ofLineSegmentIntersection()
- ofMap()
- ofNextPow2()
- ofNoise()
- ofNormalize()
- ofRadToDeg()
- ofRandom()
- ofRandomHeight()
- ofRandomWidth()
- ofRandomf()
- ofRandomuf()
- ofSeedRandom()
- ofSign()
- ofSignedNoise()
- ofWrap()
- ofWrapDegrees()
- ofWrapRadians()

# ofAngleDifferenceDegrees(...)

## float ofAngleDifferenceDegrees(float currentAngle, float targetAngle)

*Documentation from code comments*

*Documentation from code comments*

Calculates the difference between two angles in degrees.

This will calculate the actual difference, taking into account multiple revolutions. For example:

```
ofAngleDifferenceDegrees(0, 90); // Returns 90.
ofAngleDifferenceDegrees(0, 450); // Also returns 90.
```

**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)

*Documentation from code comments*

*Documentation from code comments*

Calculates the difference between two angles in radians.

This will calculate the actual difference, taking into account multiple revolutions. For example:

```
ofAngleDifferenceRadians(0, PI); // Returns -PI.
ofAngleDifferenceRadians(0, 3*PI); // Also returns -PI.
```

**Parameters:**

currentAngle The current angle in radians.

targetAngle the angle to be compared to in radians.

**Returns**: The difference between two angles in radians.

# ofBezierPoint(...)

## vectype ofBezierPoint(const vectype &a, const vectype &b, const vectype &c, const vectype &d, float t)

*Documentation from code comments*

*Documentation from code comments*

Given the four points that determine a bezier curve, return an interpolated point on the curve.

**Parameters:**

a The beginning point of the curve.

b The first control point.

c The second control point.

d The end point of the curve.

t an offset along the curve, normalized between 0 and 1.

**Returns**: A glm::vec3 on the curve.

# ofBezierTangent(...)

## vectype ofBezierTangent(const vectype &a, const vectype &b, const vectype &c, const vectype &d, float t)

*Documentation from code comments*

*Documentation from code comments*

Given the four points that determine a bezier curve and an offset along the curve, return an tangent vector to a point on the curve. Currently this is not a normalized point, and will need to be normalized.

**Parameters:**

a The beginning point of the curve.

b The first control point.

c The second control point.

d The end point of the curve.

t an offset along the curve, normalized between 0 and 1.

**Returns**: A glm::vec3 on the curve.

# ofClamp(...)

## float ofClamp(float value, float min, float max)

*Documentation from code comments*

*Documentation from code comments*

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.

```
float val = 10;
float newVal = 0;
newval = ofClamp(val, 30, 40); // newval = 30
newval = ofClamp(val, 0, 5); // newval = 5
newval = ofClamp(val, 0, 20); // newval = 10
```

**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].

# ofCurvePoint(...)

## vectype ofCurvePoint(const vectype &a, const vectype &b, const vectype &c, const vectype &d, float t)

*Documentation from code comments*

*Documentation from code comments*

Given the four points that determine a Catmull Rom curve, return an interpolated point on the curve.

**Parameters:**

a The first control point.

b The beginning point of the curve.

c The end point of the curve.

d The second control point.

t an offset along the curve, normalized between 0 and 1.

**Returns**: A glm::vec3 on the curve.

# ofCurveTangent(...)

## vectype ofCurveTangent(const vectype &a, const vectype &b, const vectype &c, const vectype &d, float t)

*Documentation from code comments*

*Documentation from code comments*

Return a tangent point for an offset along a Catmull Rom curve.

**Parameters:**

a The first control point.

b The beginning point of the curve.

c The end point of the curve.

d The second control point.

t an offset along the curve, normalized between 0 and 1.

**Returns**: A glm::vec3 on the curve.

# ofDegToRad(...)

## float ofDegToRad(float degrees)

*Documentation from code comments*

*Documentation from code comments*

Convert degrees to radians.

Example:

```
float result = ofDegToRad(90); // The result will be PI/2.
```

**Parameters:**

degrees An angle in degrees.

**Returns**: the angle in radians.

# ofDist(...)

## float ofDist(float x1, float y1, float x2, float y2)

*Documentation from code comments*

*Documentation from code comments*

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(...)

## float ofDist(float x1, float y1, float z1, float x2, float y2, float z2)

*Documentation from code comments*

*Documentation from code comments*

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(...)

## float ofDistSquared(float x1, float y1, float x2, float y2)

*Documentation from code comments*

*Documentation from code comments*

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(...)

## float ofDistSquared(float x1, float y1, float z1, float x2, float y2, float z2)

*Documentation from code comments*

*Documentation from code comments*

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)

*Documentation from code comments*

*Documentation from code comments*

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].

# ofInterpolateCatmullRom(...)

## Type ofInterpolateCatmullRom(const Type &y0, const Type &y1, const Type &y2, const Type &y3, float pct)

# ofInterpolateCosine(...)

## Type ofInterpolateCosine(const Type &y1, const Type &y2, float pct)

*Documentation from code comments*

*Documentation from code comments*

}

# ofInterpolateCubic(...)

## Type ofInterpolateCubic(const Type &y0, const Type &y1, const Type &y2, const Type &y3, float pct)

# ofInterpolateHermite(...)

## Type ofInterpolateHermite(const Type &y0, const Type &y1, const Type &y2, const Type &y3, float pct)

# ofInterpolateHermite(...)

## Type ofInterpolateHermite(const Type &y0, const Type &y1, const Type &y2, const Type &y3, float pct, float tension, float bias)

# ofIsFloatEqual(...)

## typename enable_if::value, bool >::type ofIsFloatEqual(const Type &a, const Type &b)

*Documentation from code comments*

*Documentation from code comments*

Compare two floating point types for equality.

From C++ FAQ:

Floating point arithmetic is different from real number arithmetic.
Never use `==`

to compare two floating point numbers.

This solution is not completely symmetric, meaning it is possible for
`ofIsFloatEqual(x, y) != ofIsFloatEqual(y, x)`

. From a practical
standpoint, this does not usually occur when the magnitudes of x and y are
significantly larger than epsilon, but your mileage may vary.

**See also**: https://isocpp.org/wiki/faq/newbie#floating-point-arith

**See also**: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
\tparam The floating point data type.

**Parameters:**

a The first floating point type variable to compare.

b The second floating point type variable to compare.

**Returns**: True if `std::abs(x - y) <= std::numeric_limits<Type>::epsilon() * std::abs(x)`

.

# ofLerp(...)

## float ofLerp(float start, float stop, float amt)

*Documentation from code comments*

*Documentation from code comments*

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.

```
float init = 1;
float end = 2;
float increment = 0.2;
float result = ofLerp(init, end, increment); // result = 1.2
// Values outside 0...1 work as well.
increment = 2;
result = ofLerp(init, end, increment); // result = 3
```

**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)

*Documentation from code comments*

*Documentation from code comments*

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)

*Documentation from code comments*

*Documentation from code comments*

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.

# ofLineSegmentIntersection(...)

## bool ofLineSegmentIntersection(const vectype &line1Start, const vectype &line1End, const vectype &line2Start, const vectype &line2End, vectype &intersection)

*Documentation from code comments*

*Documentation from code comments*

Determine the intersection between two lines.

**Parameters:**

line1Start Starting point for first line.

line1End End point for first line.

line2Start Starting point for second line.

line2End End point for second line.

intersection glm::vec3 reference in which to store the computed intersection point.

**Returns**: True if the lines intersect.

# ofMap(...)

## float ofMap(float value, float inputMin, float inputMax, float outputMin, float outputMax, bool clamp=false)

*Documentation from code comments*

*Documentation from code comments*

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:

```
float x = 5;
float newx = 0;
// 0 <= x < 10
newx = ofMap(x, 0, 10, 21, 22); // newx = 21.5 a value [21, 22).
```

**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 FLT_EPSILON, outputMin will be returned to prevent divide by zero errors.

**Returns**: a mapped floating point number.

# ofNextPow2(...)

## int ofNextPow2(int a)

*Documentation from code comments*

*Documentation from code comments*

Calculates the next larger power of 2.

If the input is already a power of 2, it will return itself.

Example:

```
ofNextPow2(50); // returns 64
ofNextPow2(64); // returns 64
ofNextPow2(401); // returns 512
```

**Parameters:**

a The starting point for finding the next power of 2.

**Returns**: value^2.

# ofNoise(...)

## float ofNoise(const glm::vec2 &p)

*Documentation from code comments*

*Documentation from code comments*

Calculates a two dimensional Perlin noise value between 0.0...1.0.

# ofNoise(...)

## float ofNoise(const glm::vec3 &p)

*Documentation from code comments*

*Documentation from code comments*

Calculates a three dimensional Perlin noise value between 0.0...1.0.

# ofNoise(...)

## float ofNoise(const glm::vec4 &p)

*Documentation from code comments*

*Documentation from code comments*

Calculates a four dimensional Perlin noise value between 0.0...1.0.

# ofNoise(...)

## float ofNoise(float x)

*Documentation from code comments*

*Documentation from code comments*

Calculates a one dimensional Perlin noise value between 0.0...1.0.

# ofNoise(...)

## float ofNoise(float x, float y)

*Documentation from code comments*

*Documentation from code comments*

Calculates a two dimensional Perlin noise value between 0.0...1.0.

# ofNoise(...)

## float ofNoise(float x, float y, float z)

*Documentation from code comments*

*Documentation from code comments*

Calculates a three dimensional Perlin noise value between 0.0...1.0.

# ofNoise(...)

## float ofNoise(float x, float y, float z, float w)

*Documentation from code comments*

*Documentation from code comments*

Calculates a four dimensional Perlin noise value between 0.0...1.0.

# ofNormalize(...)

## float ofNormalize(float value, float min, float max)

*Documentation from code comments*

*Documentation from code comments*

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)

*Documentation from code comments*

*Documentation from code comments*

Convert radians to degrees.

Example:

```
float result = ofRadToDeg(PI/2); // The result will be 90.
```

**Parameters:**

radians An angle in radians.

**Returns**: the angle in degrees.

# ofRandom(...)

## float ofRandom(float max)

*Documentation from code comments*

*Documentation from code comments*

Get a random floating point number between 0 and max.

A random number in the range [0, max) will be returned.

Example: ~~~~~{.cpp} // Return a random floating point number between 0 and 20. float randomNumber = ofRandom(20); ~~~~~

**Warning**: ofRandom wraps C++'s `rand()`

which is not reentrant or thread safe.

**Parameters:**

max The maximum value of the random number.

# ofRandom(...)

## float ofRandom(float val0, float val1)

*Documentation from code comments*

*Documentation from code comments*

Get a random number between two values.

A random number in the range [min, max) will be returned.

Example: ~~~~~{.cpp} // Return a random floating point number between -30 and 20. float randomNumber = ofRandom(-30, 20); ~~~~~

**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.

# ofRandomHeight()

## float ofRandomHeight()

*Documentation from code comments*

*Documentation from code comments*

Get a random floating point number between 0 and the screen height.

A random number in the range [0, ofGetHeight()) will be returned.

**Warning**: ofRandom wraps `rand()`

which is not reentrant or thread safe.

**Returns**: a random number between 0 and ofGetHeight().

# ofRandomWidth()

## float ofRandomWidth()

*Documentation from code comments*

*Documentation from code comments*

Get a random floating point number between 0 and the screen width.

A random number in the range [0, ofGetWidth()) will be returned.

**Warning**: ofRandom wraps `rand()`

which is not reentrant or thread safe.

**Returns**: a random number between 0 and ofGetWidth().

# ofRandomf()

## float ofRandomf()

*Documentation from code comments*

*Documentation from code comments*

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()

*Documentation from code comments*

*Documentation from code comments*

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()

## void ofSeedRandom()

*Documentation from code comments*

*Documentation from code comments*

Seed the seeds the random number generator with a unique value.

This seeds the random number generator with an acceptably random value, generated from clock time and the PID.

# ofSeedRandom(...)

## void ofSeedRandom(int val)

*Documentation from code comments*

*Documentation from code comments*

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.

# ofSign(...)

## int ofSign(float n)

*Documentation from code comments*

*Documentation from code comments*

Returns the sign of a number.

**Returns**: int -1 if n is negative, 1 if n is positive, and 0 is n == 0;

# ofSignedNoise(...)

## float ofSignedNoise(const glm::vec2 &p)

*Documentation from code comments*

*Documentation from code comments*

Calculates a two dimensional Perlin noise value between -1.0...1.0.

# ofSignedNoise(...)

## float ofSignedNoise(const glm::vec3 &p)

*Documentation from code comments*

*Documentation from code comments*

Calculates a three dimensional Perlin noise value between -1.0...1.0.

# ofSignedNoise(...)

## float ofSignedNoise(const glm::vec4 &p)

*Documentation from code comments*

*Documentation from code comments*

Calculates a four dimensional Perlin noise value between -1.0...1.0.

# ofSignedNoise(...)

## float ofSignedNoise(float x)

*Documentation from code comments*

*Documentation from code comments*

Calculates a one dimensional Perlin noise value between -1.0...1.0.

# ofSignedNoise(...)

## float ofSignedNoise(float x, float y)

*Documentation from code comments*

*Documentation from code comments*

Calculates a two dimensional Perlin noise value between -1.0...1.0.

# ofSignedNoise(...)

## float ofSignedNoise(float x, float y, float z)

*Documentation from code comments*

*Documentation from code comments*

Calculates a three dimensional Perlin noise value between -1.0...1.0.

# ofSignedNoise(...)

## float ofSignedNoise(float x, float y, float z, float w)

*Documentation from code comments*

*Documentation from code comments*

Calculates a four dimensional Perlin noise value between -1.0...1.0.

# ofWrap(...)

## float ofWrap(float value, float from, float to)

*Documentation from code comments*

*Documentation from code comments*

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:

```
ofWrap(5, 0, 10); // Returns 5.
ofWrap(15, 0, 10); // Also returns 5.
ofWrap(-5, 0, 10); // Also returns 5.
```

**Parameters:**

value The value to map.

from The lower bound of the range.

**Returns**: to The upper bound of the range.

Last updated Wednesday, 24 March 2021 22:21:18 UTC - 3584230cdd16cdb7de5ec8a7f713af37f38ca6dd

Hosting for openFrameworks is generously provided by Rackspace

If you have any doubt about the usage of this module you can ask in the forum.

If you want to contribute better documentation or start documenting this section you can do so here

If you find anything wrong with this docs you can report any error by opening an issue