GNU Astronomy Utilities

Next: , Previous: , Up: Arithmetic operators   [Contents][Index]

6.2.2.2 Trigonometric and hyperbolic operators

All the trigonometric and hyperbolic functions are described here. One good thing with these operators is that they take inputs and outputs in degrees (which we usually need as input or output), not radians (like most other programs/libraries).

sin
cos
tan

Basic trigonometric functions. They take one operand, in units of degrees.

asin
acos
atan

Inverse trigonometric functions. They take one operand and the returned values are in units of degrees.

atan2

Inverse tangent (output in units of degrees) that uses the signs of the input coordinates to distinguish between the quadrants. This operator therefore needs two operands: the first popped operand is assumed to be the X axis position of the point, and the second popped operand is its Y axis coordinate.

For example see the commands below. To be more clear, we are using Table’s Column arithmetic which uses exactly the same internal library function as the Arithmetic program for images. We are showing the results for four points in the four quadrants of the 2D space (if you want to try running them, you don’t need to type/copy the parts after #). The first point (2,2) is in the first quadrant, therefore the returned angle is 45 degrees. But the second, third and fourth points are in the quadrants of the same order, and the returned angles reflect the quadrant.

\$ echo " 2  2" | asttable -c'arith \$2 \$1 atan2'   # -->   45
\$ echo " 2 -2" | asttable -c'arith \$2 \$1 atan2'   # -->  -45
\$ echo "-2 -2" | asttable -c'arith \$2 \$1 atan2'   # --> -135
\$ echo "-2  2" | asttable -c'arith \$2 \$1 atan2'   # -->  135

However, if you simply use the classic arc-tangent operator (atan) for the same points, the result will only be in two quadrants as you see below:

\$ echo " 2  2" | asttable -c'arith \$2 \$1 / atan'  # -->   45
\$ echo " 2 -2" | asttable -c'arith \$2 \$1 / atan'  # -->  -45
\$ echo "-2 -2" | asttable -c'arith \$2 \$1 / atan'  # -->   45
\$ echo "-2  2" | asttable -c'arith \$2 \$1 / atan'  # -->  -45
sinh
cosh
tanh

Hyperbolic sine, cosine, and tangent. These operators take a single operand.

asinh
acosh
atanh

Inverse Hyperbolic sine, cosine, and tangent. These operators take a single operand.

Next: Unit conversion operators, Previous: Basic mathematical operators, Up: Arithmetic operators   [Contents][Index]