Math
(→cos) |
|||
| Line 361: | Line 361: | ||
float E = 2.72; // create a variable 'E' and set it equal to 2.72 | 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> | float logBTen = log10(E); // create and set variable 'logBTen' to the base-10 log of 'E' (0.43)</syntaxhighlight> | ||
| + | |- | ||
| + | |} | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | == PI == | ||
| + | {| 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%;"| '''const float PI = 3.14159265358979323846264338327950288419716939937510''' | ||
| + | |- | ||
| + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|The constant π. | ||
| + | |||
| + | |||
| + | {| | ||
| + | |- | ||
| + | |<syntaxhighlight lang="ROBOTC"> | ||
| + | float y = 0.0; // create and set 'y' to 0.0 | ||
| + | float LCD_width = 100.0; // create and set 'LCD_width' to 100.0 (width of NXT LCD in pixels) | ||
| + | |||
| + | nxtDrawLine(0, 31, 99, 31); // draw a line across the center of the LCD | ||
| + | |||
| + | for(int x = 0; x < 100; x++) // loop from 0 to 99 | ||
| + | { | ||
| + | y = sin(x * (2.0 * PI) / LCD_width) * 25; // calculate y-coordinate of pixel to draw | ||
| + | nxtSetPixel(x, y + 31); // draw pixel at (x, y+31) | ||
| + | wait1Msec(100); // wait 100 milliseconds | ||
| + | } | ||
| + | </syntaxhighlight> | ||
|- | |- | ||
|} | |} | ||
Revision as of 13:21, 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'.
|
PI
| const float PI = 3.14159265358979323846264338327950288419716939937510 | |
| The constant π.
|
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'.
|