ofMath

ofMath functions

ofSeedRandom()

void ofSeedRandom()

Seeds the random number generator to the clock time, so that random numbers will always be different.

ofSeedRandom(...)

void ofSeedRandom(int val)

Seeds the random number generator to a value passed in (val) so that random numbers will always be the same.

ofRandom(...)

float ofRandom(float val0, float val1)

For example, ofRandom(-30,20) will return a random number between -30 and 20.

ofRandomf()

float ofRandomf()

ofRandomuf()

float ofRandomuf()

ofNextPow2(...)

int ofNextPow2(int input)

eg: for an input of 50 ofNextPow2 will return 64 and for an input of 401 it will return 512.

ofNormalize(...)

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

Normalizes a number from a given range (min,max) into a value between 0 and 1. note: we are getting a clamp number between 0 and 1 of "value-min/max-min"

ofMap(...)

float ofMap(float value, float inputMin, float inputMax, float outputMin, float outputMax)

Re-maps a number from one range to another. We convert the number value where inputMin < value < inputMax into a number beetween outputMin and outputMax. e.g:

float x, newx;
x=5;
// 0 < x < 10
newx = ofMap(x, 0, 10, 21, 22) //newx = 21.5 a value between 21 and 22

ofClamp(...)

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

Restricts a value to be within a specified range defined by values min and max. e.g:

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

ofLerp(...)

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

Calculates a number between two numbers (start,stop) at a specific increment (amt). If we want the new number to be between start,stop numbers amp needs to be a number between 0 and 1. e.g:

float init,end,increment,result;
increment=0.2;
init = 1;
end =2;
result=ofLerp(init, end, increment); //result = 1.2
//We are doing init+increment*(end-init)

ofDist(...)

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

Calculates the distance between two points, (x1, y1) and (x2, y2). Uses http://en.wikipedia.org/wiki/Pythagorean_theorem

ofDistSquared(...)

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

Calculates the distances between two points, as in ofDist() but doesn't take the sqrt() of the result, which is a faster operation if you need to calculate and compare multiple distances.

ofSign(...)

int ofSign(float n )

ofInRange(...)

bool ofInRange(float t, float min, float max)

Returns true if the number t is the range of [min - max], false if it's not.

ofRadToDeg(...)

float ofRadToDeg(float radians)

Convert an angle value expressed in Radians into an angle in Degrees. For example if we call this function for radians=PI/2 we obtain 90.

ofDegToRad(...)

float ofDegToRad(float degrees)

Convert an angle value expressed in Degrees into an angle in Radians. For example if we call this function for degrees=90 we obtain PI/2.

ofRandomWidth()

float ofRandomWidth()

Picks a random number between 0 and the width of the screen.

ofRandom(...)

float ofRandom(float max)

Picks a random number between 0 and max.

ofMap(...)

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

ofMap remaps the value passed in "value", calculating it's linear distance between inputMin and inputMax, and remapping it based on that percentage to outputMin and outputMax. You can choose to clamp the results. Results are not clamped by dafult. For example: float color = ofMap(mouseX, 0, ofGetWidth(), 0, 255, true); ofBackground(color, color, color);

ofDist(...)

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

ofDistSquared(...)

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

ofSign(...)

int ofSign(float n)

ofLerpDegrees(...)

float ofLerpDegrees(float currentAngle, float targetAngle, float pct)

ofLerpRadians(...)

float ofLerpRadians(float currentAngle, float targetAngle, float pct)

ofAngleDifferenceDegrees(...)

float ofAngleDifferenceDegrees(float currentAngle, float targetAngle)

ofAngleDifferenceRadians(...)

float ofAngleDifferenceRadians(float currentAngle, float targetAngle)

ofAngleSumRadians(...)

float ofAngleSumRadians(float currentAngle, float targetAngle)

ofWrapRadians(...)

float ofWrapRadians(float angle, float from=-PI, float to=+PI)

ofWrapDegrees(...)

float ofWrapDegrees(float angle, float from=-180, float to=+180)

ofRandomHeight()

float ofRandomHeight()

ofNoise(...)

float ofNoise(float x)

ofNoise(...)

float ofNoise(float x, float y)

ofNoise(...)

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

ofNoise(...)

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

ofSignedNoise(...)

float ofSignedNoise(float x)

ofSignedNoise(...)

float ofSignedNoise(float x, float y)

ofSignedNoise(...)

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

ofSignedNoise(...)

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

ofInsidePoly(...)

bool ofInsidePoly(float x, float y, const vector< ofPoint > &poly)

ofInsidePoly(...)

bool ofInsidePoly(const ofPoint &p, const vector< ofPoint > &poly)

ofLineSegmentIntersection(...)

bool ofLineSegmentIntersection(ofPoint line1Start, ofPoint line1End, ofPoint line2Start, ofPoint line2End, ofPoint &intersection)

ofBezierPoint(...)

ofPoint ofBezierPoint(ofPoint a, ofPoint b, ofPoint c, ofPoint d, float t)

ofCurvePoint(...)

ofPoint ofCurvePoint(ofPoint a, ofPoint b, ofPoint c, ofPoint d, float t)