NXC  Version 1.2.1 r5
 All Data Structures Files Functions Variables Groups Pages
ex_atan2d.nxc

This is an example of how to use the atan2d function.

// ex_atan2d.nxc
// Display values of the atan2d API call.
// This program runs indefinitely -- press gray button to exit.
// Reguires enhanced firmware 1.28 or later.
// The following two arrays comprise the x and y coordinates of the corners and
// the mid-points of the sides of a square centered at the origin and having
// sides two units long.
const float y_coord[] = {-1.0, -1.0, -1.0, 0.0, 1.0, 1.0, 1.0, 0.0};
const float x_coord[] = {-1.0, 0.0, 1.0, 1.0, 1.0, 0.0, -1.0, -1.0};
// Display the angles made by lines from the origin to the points on the square
// as specified above.
task main()
{
const int pts = ArrayLen(y_coord);
for (int i = 0; i < pts; ++i)
{
float angle = atan2d(y_coord[i], x_coord[i]);
TextOut(0, 56 - 8 * i, FormatNum("%7.2f DEG", angle));
}
while (true);
}