C library of triangulation algorithms (for the problems of mobile robot positioning or resection)
hmam.c
Go to the documentation of this file.
1 /**
2  * @file hmam.c
3  * @date 05/09/2012
4  * @author Vincent Pierlot
5  *
6  * The algorithm was implemented after \cite Hmam2007Mobile.
7  * !!! FOR NOW IT DOES NOT WORK FOR ALL CASES !!!
8 */
9 #include <math.h>
10 #include "const.h"
11 #include "hmam.h"
12 
13 tfloat triangulationHmam(tfloat *x, tfloat *y,
14  tfloat alpha1, tfloat alpha2, tfloat alpha3,
15  tfloat x1, tfloat y1, tfloat x2, tfloat y2, tfloat x3, tfloat y3)
16 {
17  tfloat d12 = sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) ) ;
18  tfloat d23 = sqrt( (x3-x2)*(x3-x2) + (y3-y2)*(y3-y2) ) ;
19 
20  tfloat lambda12 = alpha2 - alpha1 ;
21  tfloat lambda23 = alpha3 - alpha2 ;
22 
23  tfloat mu = Sin( lambda12 ) / d12 ;
24  tfloat eta = Sin( lambda23 ) / d23 ;
25 
26  tfloat phi = atan2( (y1-y2) , (x1-x2) ) ;
27 
28  tfloat beta = phi - atan2( (y3-y2) , (x3-x2) ) ;
29 
30  tfloat r2 = fabs( Sin( beta + lambda12 + lambda23 ) ) / sqrt( mu*mu + eta*eta + 2*mu*eta*Cos( beta + lambda12 + lambda23 ) ) ;
31 
32  tfloat theta12 = asin( mu*r2 ) ;
33 
34  tfloat beta12 = PI - lambda12 - theta12 ;
35 
36  *x = x2 + r2 * Cos( phi - beta12 ) ;
37  *y = y2 + r2 * Sin( phi - beta12 ) ;
38 
39  return beta;
40 }
41 
#define PI
The value of PI.
Definition: const.h:12
double tfloat
Defines the type for float/double.
Definition: const.h:38