bf3a3fa297
- aggiunta libreria vroni 7.6.
82 lines
2.5 KiB
C
82 lines
2.5 KiB
C
/* */
|
|
/* Copyright (C) 1999-2023 M. Held */
|
|
/* */
|
|
/* This code is not in the public domain. All rights reserved! Please make */
|
|
/* sure to read the full copyright statement contained in "README.txt" or in */
|
|
/* the "main" file of this code, such as "main.cc". */
|
|
/* */
|
|
/*****************************************************************************/
|
|
/* */
|
|
/* Written by: Martin Held */
|
|
/* */
|
|
/* E-Mail: held@cs.sbg.ac.at */
|
|
/* Fax Mail: (+43 662) 8044-611 */
|
|
/* Voice Mail: (+43 662) 8044-6304 */
|
|
/* Snail Mail: Martin Held */
|
|
/* FB Informatik */
|
|
/* Universitaet Salzburg */
|
|
/* A-5020 Salzburg, Austria */
|
|
/* */
|
|
/*****************************************************************************/
|
|
|
|
#ifndef VRONI_CORE_ATAN2_H
|
|
#define VRONI_CPRE_ATAN2_H
|
|
|
|
|
|
inline double atan2local(const double &y, const double &x)
|
|
{
|
|
if( fabs(x) >= fabs(y) )
|
|
{
|
|
// Sector to the right
|
|
if( x > 0 )
|
|
{
|
|
const double phi = y/x;
|
|
return atan(phi);
|
|
}
|
|
// Sector to the left
|
|
else if( x < 0 )
|
|
{
|
|
const double phi = y/x;
|
|
if( y >= 0) {
|
|
return atan(phi) + M_PI;
|
|
} else {
|
|
return atan(phi) - M_PI;
|
|
}
|
|
}
|
|
// Hence, x and y are zero
|
|
else
|
|
{
|
|
return 0.0;
|
|
}
|
|
}
|
|
else if( fabs(y) >= fabs(x) )
|
|
{
|
|
// Sector to the top
|
|
if( y > 0 )
|
|
{
|
|
const double phi = x/y;
|
|
return M_PI_2 - atan(phi);
|
|
}
|
|
// Sector to the bottom
|
|
if( y < 0 )
|
|
{
|
|
const double phi = x/y;
|
|
return - M_PI_2 - atan(phi);
|
|
}
|
|
// Actually, the impossible case, x=y=0. Should be catched above.
|
|
else
|
|
{
|
|
assert(false);
|
|
return 0.0;
|
|
}
|
|
|
|
}
|
|
// This can only happen, if x or y is NaN.
|
|
else
|
|
{
|
|
return 0.0;
|
|
}
|
|
}
|
|
|
|
#endif
|