C library of triangulation algorithms (for the problems of mobile robot positioning or resection)
collins.c
Go to the documentation of this file.
1 /**
2  * @file collins.c
3  * @date 02/10/2012
4  * @author Vincent Pierlot
5  *
6  * The algorithm was implemented after \cite Burtch2005ThreePoint.
7 */
8 #include <math.h>
9 #include "const.h"
10 #include "collins.h"
11 
12 /* ./triangulation -t1 -m20 -1"1000" -2"5300" -3"3100" -4"5000" -5"2200" -6"6300" -a"109.3045" -b"-115.0520" -c"0.0" */
13 tfloat triangulationCollins(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 alpha = alpha1 - alpha3 ;
18  tfloat beta = alpha3 - alpha2 ;
19 
20  tfloat dAB = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) ;
21 
22  tfloat AzAB = atan2( (x2-x1) , (y2-y1) ) ;
23  tfloat AzAH = AzAB + PI - beta ;
24 
25  tfloat AHB = beta + alpha - PI ;
26 
27  tfloat dAH = dAB * Sin( PI - alpha ) / Sin( AHB ) ;
28 
29  tfloat xH = x1 + dAH * Sin( AzAH ) ;
30  tfloat yH = y1 + dAH * Cos( AzAH ) ;
31 
32  tfloat AzCH = atan2( (xH-x3) , (yH-y3) ) ; AzCH = (AzCH<0) ? AzCH+TWOPI : AzCH ;
33  tfloat AzCA = atan2( (x1-x3) , (y1-y3) ) ; AzCA = (AzCA<0) ? AzCA+TWOPI : AzCA ;
34 
35  tfloat ACP = AzCA - AzCH ;
36 
37  tfloat phi = PI - alpha - ACP ;
38 
39  tfloat AzAP = AzCA - PI + phi ;
40  tfloat dAC = sqrt( (x3-x1)*(x3-x1) + (y3-y1)*(y3-y1) ) ;
41  tfloat dAP = dAC * Sin( ACP ) / Sin( alpha ) ;
42 
43  *x = x1 + dAP * Sin( AzAP ) ;
44  *y = y1 + dAP * Cos( AzAP ) ;
45 
46  return phi ;
47 }
48 
#define PI
The value of PI.
Definition: const.h:12
double tfloat
Defines the type for float/double.
Definition: const.h:38