C library of triangulation algorithms (for the problems of mobile robot positioning or resection)
ligas.c
Go to the documentation of this file.
1 /**
2  * @file ligas.c
3  * @date 02/10/2012
4  * @author Vincent Pierlot
5  *
6  * The algorithm was implemented after \cite Ligas2013Simple.
7 */
8 #include <math.h>
9 #include "const.h"
10 #include "ligas.h"
11 
12 tfloat triangulationLigas(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 cot_alpha = Cot( alpha2 - alpha1 ) ; /* alpha */
17  tfloat cot_beta = Cot( alpha3 - alpha2 ) ; /* beta */
18  cot_alpha = adjust_value_to_bounds( cot_alpha , COT_MAX ) ;
19  cot_beta = adjust_value_to_bounds( cot_beta , COT_MAX ) ;
20 
21  tfloat A1 = -x1 - x2 ;
22  tfloat A2 = -y1 - y2 ;
23  tfloat A3 = x1 * x2 + y1 * y2 ;
24  tfloat A4 = y1 - y2 ;
25  tfloat A5 = x2 - x1 ;
26  tfloat A6 = x1 * y2 - x2 * y1 ;
27 
28  tfloat B1 = -x2 - x3 ;
29  tfloat B2 = -y2 - y3 ;
30  tfloat B3 = x2 * x3 + y2 * y3 ;
31  tfloat B4 = y2 - y3 ;
32  tfloat B5 = x3 - x2 ;
33  tfloat B6 = x2 * y3 - x3 * y2 ;
34 
35  tfloat a = A1 - A4 * cot_alpha ;
36  tfloat b = A2 - A5 * cot_alpha ;
37  tfloat c = A3 - A6 * cot_alpha ;
38  tfloat d = B1 - B4 * cot_beta ;
39  tfloat e = B2 - B5 * cot_beta ;
40  tfloat f = B3 - B6 * cot_beta ;
41 
42  tfloat A = a - d ;
43  tfloat B = b - e ;
44  tfloat C = c - f ;
45 
46  tfloat AA = A*A ;
47  tfloat BB = B*B ;
48  tfloat AB = A*B ;
49 
50  tfloat D = AA + BB ;
51 
52  if ( A != 0.0 )
53  {
54  *y = ( ( -2*C*B - b*AA + a*AB ) / D ) - y2 ;
55  *x = ( -B*(*y) - C) / A ;
56  }
57  else
58  {
59  *x = ( ( -2*C*A - a*BB + b*AB ) / D ) - x2 ;
60  *y = ( -A*(*x) - C) / B ;
61  }
62 
63  return D ;
64 }
65 
double tfloat
Defines the type for float/double.
Definition: const.h:38