C library of triangulation algorithms (for the problems of mobile robot positioning or resection)
lukic.c
Go to the documentation of this file.
1 /**
2  * @file lukic.c
3  * @date 04/09/2012
4  * @author Vincent Pierlot
5  *
6  * The algorithm was implemented after \cite Lukic2011AnAutonomous.
7  * This algorithm is not general like the other ones; they are constraints on the beacon locations:
8  * x1 = 0, y1 = 0, x3 > 0, x2 = -x3, y2 = y3.
9 */
10 #include <math.h>
11 #include "const.h"
12 #include "lukic.h"
13 
14 tfloat triangulationLukicOriginal(tfloat *x, tfloat *y,
15  tfloat alpha1, tfloat alpha2, tfloat alpha3,
16  tfloat x1, tfloat y1, tfloat x2, tfloat y2, tfloat x3, tfloat y3)
17 {
18  tfloat cot_phi1 = adjust_value_to_bounds( 1 / tan( alpha3 - alpha1 ) , COT_MAX ) ;
19  tfloat cot_phi2 = adjust_value_to_bounds( 1 / tan( alpha1 - alpha2 ) , COT_MAX ) ;
20 
21  tfloat L1 = x3 - x2 ;
22  tfloat L2 = y2 ;
23 
24  tfloat cx1 = L1/4 - L2*cot_phi1/2 ;
25  tfloat cy1 = L2/2 + L1*cot_phi1/4 ;
26 
27  tfloat cx2 = -L1/4 + L2*cot_phi2/2 ;
28  tfloat cy2 = L2/2 + L1*cot_phi2/4 ;
29 
30  tfloat N = cx1 * cy2 - cx2 * cy1 ;
31  tfloat D = (cy2 - cy1)*(cy2 - cy1) + (cx2 - cx1)*(cx2 - cx1) ;
32 
33  tfloat K = 2 * N / D ;
34 
35  *x = K * ( cy2 - cy1 ) ;
36  *y = K * ( cx1 - cx2 ) ;
37 
38  return D;
39 }
40 
41 tfloat triangulationLukic(tfloat *x, tfloat *y,
42  tfloat alpha1, tfloat alpha2, tfloat alpha3,
43  tfloat x1, tfloat y1, tfloat x2, tfloat y2, tfloat x3, tfloat y3)
44 {
45  tfloat cot_phi1 = adjust_value_to_bounds( 1 / tan( alpha3 - alpha1 ) , COT_MAX ) ;
46  tfloat cot_phi2 = adjust_value_to_bounds( 1 / tan( alpha1 - alpha2 ) , COT_MAX ) ;
47 
48  tfloat L1 = ( x3 - x2 ) / 2 ;
49  tfloat L2 = y2 ;
50 
51  tfloat cx1 = L1 - L2*cot_phi1 ;
52  tfloat cy1 = L2 + L1*cot_phi1 ;
53 
54  tfloat cx2 = -L1 + L2*cot_phi2 ;
55  tfloat cy2 = L2 + L1*cot_phi2 ;
56 
57  tfloat N = cx1 * cy2 - cx2 * cy1 ;
58  tfloat D = (cy2 - cy1)*(cy2 - cy1) + (cx2 - cx1)*(cx2 - cx1) ;
59 
60  tfloat K = N / D ;
61 
62  *x = K * ( cy2 - cy1 ) ;
63  *y = K * ( cx1 - cx2 ) ;
64 
65  return D;
66 }
67 
double tfloat
Defines the type for float/double.
Definition: const.h:38