C library of triangulation algorithms (for the problems of mobile robot positioning or resection)
tienstra.c
Go to the documentation of this file.
1 /**
2  * @file tienstra.c
3  * @date 02/10/2012
4  * @author Vincent Pierlot
5  *
6  * The algorithm was implemented after \cite Porta2009Concise.
7 */
8 #include <math.h>
9 #include "const.h"
10 #include "tienstra.h"
11 
12 tfloat triangulationTienstra(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  tfloat alpha23 = alpha3 - alpha2 ;
18  tfloat alpha31 = alpha1 - alpha3 ;
19 
20  tfloat L12_2 = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) ;
21  tfloat L23_2 = (x3-x2)*(x3-x2) + (y3-y2)*(y3-y2) ;
22  tfloat L13_2 = (x3-x1)*(x3-x1) + (y3-y1)*(y3-y1) ;
23  tfloat L12 = sqrt( L12_2 ) ;
24  tfloat L23 = sqrt( L23_2 ) ;
25  tfloat L13 = sqrt( L13_2 ) ;
26 
27  tfloat A123 = acos( ( L12_2 + L23_2 - L13_2 ) / ( 2 * L12 * L23 ) ) ;
28  tfloat A213 = acos( ( L12_2 + L13_2 - L23_2 ) / ( 2 * L12 * L13 ) ) ;
29  tfloat A132 = acos( ( L13_2 + L23_2 - L12_2 ) / ( 2 * L13 * L23 ) ) ;
30 
31  tfloat cotA123 = Cot( A123 ) ;
32  tfloat cotA213 = Cot( A213 ) ;
33  tfloat cotA132 = Cot( A132 ) ;
34 
35  tfloat cot_alpha12 = Cot( alpha12 ) ;
36  tfloat cot_alpha23 = Cot( alpha23 ) ;
37  tfloat cot_alpha31 = Cot( alpha31 ) ;
38 
39  tfloat f1 = 1 / ( cotA213 - cot_alpha23 ) ;
40  tfloat f2 = 1 / ( cotA123 - cot_alpha31 ) ;
41  tfloat f3 = 1 / ( cotA132 - cot_alpha12 ) ;
42  tfloat F = f1 + f2 + f3 ;
43 
44  *x = ( f1 * x1 + f2 * x2 + f3 * x3 ) / F ;
45  *y = ( f1 * y1 + f2 * y2 + f3 * y3 ) / F ;
46 
47  return F ;
48 }
49 
double tfloat
Defines the type for float/double.
Definition: const.h:38