Math
(Created page with "{| style="font-family:Verdana, Genega, sans-sarif; font-size:80%;color:gray;" width="100%" cellpadding="0%" cellspacing="0" border="0" |- | ''Main >> [[NXT_Main...") |
|||
| Line 6: | Line 6: | ||
|} | |} | ||
| − | + | ROBOTC has a powerful collection of useful math functions for the NXT, TETRIX, and VEX CORTEX platforms. '''The RCX and VEX PIC platforms do not have enough memory to store these more advanced math functions.''' | |
| Line 12: | Line 12: | ||
| − | == | + | == abs == |
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
|- | |- | ||
| − | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| ''' | + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float abs(const float input)''' |
|- | |- | ||
| − | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"| | + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the absolute value of a number. |
| Line 24: | Line 24: | ||
! Explanation | ! Explanation | ||
|- | |- | ||
| − | | style="border-style: solid; border-width: 0px 0px 0px 0px"|'' | + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''input'' |
| − | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The | + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the absolute value of (can be: int, long, short, float). |
|- | |- | ||
| − | | style="border-style: solid; border-width: 0px 0px 0px 0px"|'' | + | |} |
| − | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The | + | |
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float G = -9.81; // create a variable 'G' and set it equal to -9.81 | ||
| + | float downForce = abs(G); // create and set variable 'downForce' to the absolute value of 'G' (9.81)</syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == acos == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float acos(const float Cosine)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the arc-cosine of a number in radians. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''Cosine'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the arc-cosine of (in radians). | ||
|- | |- | ||
|} | |} | ||
| Line 36: | Line 62: | ||
|- | |- | ||
|<syntaxhighlight lang="ROBOTC"> | |<syntaxhighlight lang="ROBOTC"> | ||
| − | + | float param = 0.5; // create and set floating point variable 'param' to 0.5 | |
| − | + | float result = acos(param) * 180.0 / PI; // create floating point variable 'result' and | |
| + | // set it equal to the arc-cosine of 'param' in degrees (60) | ||
| + | </syntaxhighlight> | ||
|- | |- | ||
|} | |} | ||
|- | |- | ||
|} | |} | ||
| + | |||
| + | |||
| + | == asin == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float asin(const float Sine)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the arc-sine of a number in radians. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''Sine'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the arc-sine of (in radians). | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float param = 0.5; // create and set floating point variable 'param' to 0.5 | ||
| + | float result = asin(param) * 180.0 / PI; // create floating point variable 'result' and | ||
| + | // set it equal to the arc-sine of 'param' in degrees (30) | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == atan == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float atan(const float Tangent)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the arc-tangent of a number in radians. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''Tangent'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the arc-tangent of (in radians). | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float param = 0.5; // create and set floating point variable 'param' to 0.5 | ||
| + | float result = asin(param) * 180.0 / PI; // create floating point variable 'result' and | ||
| + | // set it equal to the arc-sine of 'param' in degrees (26.565) | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == ceil == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float ceil(const float input)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the '''smallest integer''' value that is greater than or equal to 'input'. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''input'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The floating point number to take the ceiling value of. | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float E = 2.72; // create a variable 'E' and set it equal to 2.72 | ||
| + | float ceiling = ceil(E); // create and set variable 'ceiling' to the ceiling value of 'E' (3)</syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == cos == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float cos(const float fRadians)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the cosine of a number of radians. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''fRadians'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the cosine of (in radians). | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float result = cos(PI); // create a floating point variable 'result' and set it equal to the cosine of PI (-1) | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == cosDegrees == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float cosDegrees(const float fDegrees)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the cosine of a number of degrees. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''fDegrees'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the cosine of (in degrees). | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float result = cosDegrees(180); // create a floating point variable 'result' and set it equal to the cosine of 180 degrees (-1) | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == degreesToRadians == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float degreesToRadians(const float fDegrees)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the radian equivalent of 'fDegrees'. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''fDegrees'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number of degrees to convert into radians. | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float radiansPerDegree = degreesToRadians(1.0); // create a floating point variable 'radiansPerDegree ' | ||
| + | // and set it equal to the amount of radians in 1.0 degrees (0.017) | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == exp == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float exp(const float input)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the number 'e' rasied to the power of 'input'. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''input'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The floating point number to raise the constant 'e' to. | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float result = exp(4); // create floating point variable 'result' and set it equal to e raised to the 4th power (e^4 = 54.598) | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == floor == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float floor(const float input)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the '''largest integer''' value that is less than or equal to 'input'. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''input'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The floating point number to take the floor value of. | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float E = 2.72; // create a variable 'E' and set it equal to 2.72 | ||
| + | float floorValue = ceil(E); // create and set variable 'floorValue' to the ceiling value of 'E' (2)</syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == log == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float log(const float input)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the natural logarithm ''(ln)'' of 'input'. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''input'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The floating point number to take the natural logarithm of. | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float E = 2.72; // create a variable 'E' and set it equal to 2.72 | ||
| + | float ln = log(E); // create and set variable 'ln' to the natural log of 'E' (1.00)</syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == log10 == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float log10(const float input)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the base-10 logarithm of 'input'. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''input'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The floating point number to take the base-10 logarithm of. | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float E = 2.72; // create a variable 'E' and set it equal to 2.72 | ||
| + | float logBTen = log10(E); // create and set variable 'logBTen' to the base-10 log of 'E' (0.43)</syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == pow == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float pow(const float base, const float exponent)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns 'base' to the power of 'exponent'. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''base'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The floating point base to raise to the power of 'power'. | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''exponent'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The floating point exponent to raise 'base' to. | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float kilobyte = pow(10, 3); // create floating point variable 'kilobyte' and | ||
| + | // set it equal to 10^3 or 1000 | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == radiansToDegrees == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''short radiansToDegrees(const float fRadians)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the degree equivalent of 'fRadians'. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''fRadians'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number of radians to convert into degrees. | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float degrees = radiansToDegrees(PI); // create a floating point variable 'degrees' | ||
| + | // and set it equal to the amount of degrees in PI (180) | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == sgn == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''short sgn(const float input)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns a value less than 0 if 'input' is negative, and a value greater than 0 if 'input is positive. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''input'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to test the sign of | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | int res1 = sgn(-9.81); // returns -1 to 'res1' | ||
| + | int res2 = sgn(3.14); // returns 1 to 'res2' | ||
| + | int res3 = sgn(0); // returns 0 to 'res3' | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == sin == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float sin(const float fRadians)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the sine of a number of radians. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''fRadians'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the sine of (in radians). | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float result = sin(PI); // create a floating point variable 'result' and set it equal to the cosine of PI (0) | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == sinDegrees == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float sinDegrees(const float fDegrees)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the sine of a number of degrees. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''fDegrees'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the sine of (in degrees). | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float result = sinDegrees(180); // create a floating point variable 'result' and set it equal to the sine of 180 degrees (0) | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == sqrt == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float sqrt(const float input)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the square-root of 'input'. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''input'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the square-root of. | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float result = sqrt(1764); // create a floating point variable 'result' and set it equal to the square-root of 1764 (42) | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | <!-- == tan == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float tan(const float fRadians)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the tangent of a number of radians. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''fRadians'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the tangent of (in radians). | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float result = tan(PI); // create a floating point variable 'result' and set it equal to the tangent of PI (0) | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == tanDegrees == | ||
| + | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | |- | ||
| + | | style="font-family:Courier New; color:black; background-color:#B3CDFF; text-align:left; font-size:100%;"| '''float tanDegrees(const float fDegrees)''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|Returns the tangent of a number of degrees. | ||
| + | |||
| + | |||
| + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#F2F2F2; text-align:left; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 0px; border-style: solid; border-color: #000;" cellpadding="5%" | ||
| + | ! style="border-style: solid; border-width: 0px 0px 0px 0px"|Parameter | ||
| + | ! Explanation | ||
| + | |- | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''fDegrees'' | ||
| + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|The number to take the tangent of (in degrees). | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float result = tanDegrees(180); // create a floating point variable 'result' and set it equal to the tangent of 180 degrees (0) | ||
| + | </syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} --> | ||
Revision as of 10:03, 4 January 2012
ROBOTC has a powerful collection of useful math functions for the NXT, TETRIX, and VEX CORTEX platforms. The RCX and VEX PIC platforms do not have enough memory to store these more advanced math functions.
Contents |
abs
| float abs(const float input) | |||||
| Returns the absolute value of a number.
|
acos
| float acos(const float Cosine) | |||||
| Returns the arc-cosine of a number in radians.
|
asin
| float asin(const float Sine) | |||||
| Returns the arc-sine of a number in radians.
|
atan
| float atan(const float Tangent) | |||||
| Returns the arc-tangent of a number in radians.
|
ceil
| float ceil(const float input) | |||||
| Returns the smallest integer value that is greater than or equal to 'input'.
|
cos
| float cos(const float fRadians) | |||||
| Returns the cosine of a number of radians.
|
cosDegrees
| float cosDegrees(const float fDegrees) | |||||
| Returns the cosine of a number of degrees.
|
degreesToRadians
| float degreesToRadians(const float fDegrees) | |||||
| Returns the radian equivalent of 'fDegrees'.
|
exp
| float exp(const float input) | |||||
| Returns the number 'e' rasied to the power of 'input'.
|
floor
| float floor(const float input) | |||||
| Returns the largest integer value that is less than or equal to 'input'.
|
log
| float log(const float input) | |||||
| Returns the natural logarithm (ln) of 'input'.
|
log10
| float log10(const float input) | |||||
| Returns the base-10 logarithm of 'input'.
|
pow
| float pow(const float base, const float exponent) | |||||||
| Returns 'base' to the power of 'exponent'.
|
radiansToDegrees
| short radiansToDegrees(const float fRadians) | |||||
| Returns the degree equivalent of 'fRadians'.
|
sgn
| short sgn(const float input) | |||||
| Returns a value less than 0 if 'input' is negative, and a value greater than 0 if 'input is positive.
|
sin
| float sin(const float fRadians) | |||||
| Returns the sine of a number of radians.
|
sinDegrees
| float sinDegrees(const float fDegrees) | |||||
| Returns the sine of a number of degrees.
|
sqrt
| float sqrt(const float input) | |||||
| Returns the square-root of 'input'.
|