All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups

Detailed Description

Math routines.

Below is a code example that uses the trigonometry functions to calculate the coordinate at which the second hand of a watch ends, using the seconds from a PblTm time.

GPoint secondHand;
GPoint center;
PblTm t;
int32_t secondHandLength = ...;
...
int32_t second_angle = TRIG_MAX_ANGLE * t.tm_sec / 60;
secondHand.y = (-cos_lookup(second_angle) * secondHandLength / TRIG_MAX_RATIO) + center.y;
secondHand.x = (sin_lookup(second_angle) * secondHandLength / TRIG_MAX_RATIO) + center.x;

Function Documentation

int32_t atan2_lookup ( int16_t  y,
int16_t  x 
)

Look-up the arctangent of a given x, y pair The angle value is scaled linearly, such that a value of 0x10000 corresponds to 360 degrees or 2 PI radians.

int32_t cos_lookup ( int32_t  angle)

Look-up the cosine of the given angle from a pre-computed table. This is equivalent to calling sin_lookup(angle + MAX_ANGLE / 4).

Parameters
angleThe angle for which to compute the cosine. The angle value is scaled linearly, such that a value of 0x10000 corresponds to 360 degrees or 2 PI radians.
int32_t sin_lookup ( int32_t  angle)

Look-up the sine of the given angle from a pre-computed table.

Parameters
angleThe angle for which to compute the cosine. The angle value is scaled linearly, such that a value of 0x10000 corresponds to 360 degrees or 2 PI radians.

Macro Definition Documentation

#define TRIG_MAX_ANGLE   0x10000

Angle value that corresponds to 360 degrees or 2 PI radians.

See Also
sin_lookup
cos_lookup
#define TRIG_MAX_RATIO   0xffff

The largest value that can result from a call to sin_lookup or cos_lookup. For a code example, see the detailed description at the top of this chapter: Math.