C library of triangulation algorithms (for the problems of mobile robot positioning or resection)
esteves.c
Go to the documentation of this file.
1 /**
2  * @file esteves.c
3  * @date 18/03/2011
4  * @author Vincent Pierlot
5  *
6  * The algorithm was implemented after \cite Esteves2006Position.
7 */
8 #include <math.h>
9 #include "const.h"
10 #include "esteves.h"
11 
12 tfloat triangulationEsteves(tfloat *x, tfloat *y,
13  tfloat alpha1, tfloat alpha2, tfloat alpha3,
14  tfloat x1, tfloat y1, tfloat x2, tfloat y2, tfloat x3, tfloat y3)
15 {
16  tfloat alpha12 = alpha2 - alpha1 ;
17  if( alpha1 > alpha2 ) alpha12 += TWOPI ;
18 
19  tfloat alpha31 = alpha1 - alpha3 ;
20  if( alpha3 > alpha1 ) alpha31 += TWOPI ;
21 
22  tfloat L12 = sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) ) ;
23  tfloat L31 = sqrt( (x3-x1)*(x3-x1) + (y3-y1)*(y3-y1) ) ;
24 
25  tfloat phi = atan2( (y1-y2) , (x1-x2) ) ; /* not given in the paper */
26  tfloat sigma = atan2( (x1-x3) , (y1-y3) ) + HALFPI + phi ; /* not given in the paper */
27 
28  tfloat gamma = sigma - alpha31 ;
29 
30  tfloat sin_alpha12 = Sin( alpha12 ) ;
31  tfloat sin_alpha31 = Sin( alpha31 ) ;
32 
33  tfloat tau = atan( (sin_alpha12*(L12*sin_alpha31 - L31*Sin(gamma))) / (L31*sin_alpha12*Cos(gamma) - L12*Cos(alpha12)*sin_alpha31) ) ;
34 
35  if( (alpha12 < PI) && (tau < 0.0) ) tau += PI ;
36  if( (alpha12 > PI) && (tau > 0.0) ) tau -= PI ;
37 
38  if(tau == 0.0)
39  if( ( (sigma > 0.0) && (alpha31 > PI) ) || ( (sigma < 0.0) && (alpha31 < PI) ) ) tau = PI ;
40 
41  tfloat L1;
42  if( fabs( sin_alpha12 ) > fabs( sin_alpha31 ) )
43  L1 = ( L12 * Sin( tau + alpha12 ) ) / sin_alpha12 ;
44  else
45  L1 = ( L31 * Sin( tau + sigma - alpha31 ) ) / sin_alpha31 ;
46 
47  *x = x1 - L1 * Cos( phi + tau ) ;
48  *y = y1 - L1 * Sin( phi + tau ) ;
49 
50  return tau;
51 }
52 
#define PI
The value of PI.
Definition: const.h:12
double tfloat
Defines the type for float/double.
Definition: const.h:38