global functions

- ofAngleDifferenceDegrees()
- ofAngleDifferenceRadians()
- ofBezierPoint()
- ofBezierTangent()
- ofClamp()
- ofCurvePoint()
- ofCurveTangent()
- ofDegToRad()
- ofDist()
- ofDistSquared()
- ofInRange()
- ofInsidePoly()
- ofInterpolateCatmullRom()
- ofInterpolateCosine()
- ofInterpolateCubic()
- ofInterpolateHermite()
- 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(...)

## ofPoint ofBezierPoint(const ofPoint &a, const ofPoint &b, const ofPoint &c, const ofPoint &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 ofPoint on the curve.

# ofBezierTangent(...)

## ofPoint ofBezierTangent(const ofPoint &a, const ofPoint &b, const ofPoint &c, const ofPoint &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 ofPoint 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(...)

## ofPoint ofCurvePoint(const ofPoint &a, const ofPoint &b, const ofPoint &c, const ofPoint &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 ofPoint on the curve.

# ofCurveTangent(...)

## ofPoint ofCurveTangent(const ofPoint &a, const ofPoint &b, const ofPoint &c, const ofPoint &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 ofPoint 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 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.

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

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

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

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

# ofInsidePoly(...)

## bool ofInsidePoly(float x, float y, const vector &poly)

*Documentation from code comments*

*Documentation from code comments*

Determine if an (x,y) coordinate is within the polygon defined by a vector of ofPoints.

Parameters: x The x dimension of the coordinate. y The y dimension of the coordinate. poly a vector of ofPoints defining a polygon.

Returns: True if the point defined by the coordinates is enclosed, false otherwise.

# ofInsidePoly(...)

## bool ofInsidePoly(const ofPoint &p, const vector &poly)

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

# 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 ofPoint &line1Start, const ofPoint &line1End, const ofPoint &line2Start, const ofPoint &line2End, ofPoint &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 ofPoint 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(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.

# ofNoise(...)

## float ofNoise(const ofVec2f &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 ofVec3f &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 ofVec4f &p)

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

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

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

# ofSignedNoise(...)

## float ofSignedNoise(const ofVec2f &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 ofVec3f &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 ofVec4f &p)

*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 토요일, 20 5월 2017 08:56:13 UTC - de18754756090fcea8a84a678e44da5723ce61d2

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