| To: | yyyyyyyyyyyyyyy@xxxxxxxxxxxxx |
|---|---|
| Subject: | Defect in XSH atan2 |
| From: | yyyyyyyy@xxxxxxx |
| Date: | Tue, 22 Jul 2003 10:47:53 +0100 (BST) |
Defect report from : Loic Domaigne , personal interest
(Please direct followup comments direct to yyyyyyyyyyyyyy@xxxxxxxxxxxxx)
@ page 0 line 0 section atan2 comment {atan2}
Problem:
Edition of Specification (Year): 2003
Defect code : 2. Omission
Missing example.
Action:
Converting Cartesian to Polar coordinates system
The function below uses atan2() to convert a 2d vector expressed in
cartesian coordinates to the polar coordinates.
#include <math.h>
typedef struct
{
double x;
double y;
} cartesian2d_t ;
typedef struct
{
double rho;
double theta;
} polar_t;
polar_t
cartesian_to_polar(const cartesian2d_t v /* vector in cartesian */
)
{
polar_t polar_v; /* v in polar */
polar_v.rho = sqrt (v.x*v.x + v.y*v.y);
polar_v.theta = atan2 (v.y, v.x);
return polar_v;
}
Note1: There are alternative ways to compute the angle theta, using
e.g. asin(), acos() or atan(). However, atan2() presents here two
advantages:
- the angle's quadrant is automatically determined.
- the singular case v.x==0 is taken into account.
Note2: similar examples might be derived using atan2f(), atan2l().
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Defect in XSH pthread_attr_getguardsize, loic-dev |
|---|---|
| Next by Date: | Re: Defect in XSH atan2, Fred J. Tydeman |
| Previous by Thread: | Defect in XSH pthread_attr_getguardsize, loic-dev |
| Next by Thread: | Re: Defect in XSH atan2, Fred J. Tydeman |
| Indexes: | [Date] [Thread] [All Lists] |