C library of triangulation algorithms (for the problems of mobile robot positioning or resection)
cassini.c
Go to the documentation of this file.
1 /**
2  * @file cassini.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 "cassini.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 triangulationCassini(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 cot_alpha = Cot( alpha ) ;
21  cot_alpha = adjust_value_to_bounds( cot_alpha , COT_MAX ) ;
22  tfloat cot_beta = Cot( beta ) ;
23  cot_beta = adjust_value_to_bounds( cot_beta , COT_MAX ) ;
24 
25  tfloat xH1 = x1 + ( y3 - y1 ) * cot_alpha ;
26  tfloat yH1 = y1 + ( x1 - x3 ) * cot_alpha ;
27 
28  tfloat xH2 = x2 + ( y2 - y3 ) * cot_beta ;
29  tfloat yH2 = y2 + ( x3 - x2 ) * cot_beta ;
30 
31  tfloat AzH1H2 = atan2( (xH2-xH1) , (yH2-yH1) ) ;
32 
33  tfloat n = Tan( AzH1H2 ) ;
34  tfloat inv_n = 1 / n ;
35  tfloat N = n + inv_n ;
36 
37  *x = ( n * x3 + inv_n * xH1 + y3 - yH1 ) / N ;
38  *y = ( n * yH1 + inv_n * y3 + x3 - xH1 ) / N ;
39 
40  return N ;
41 }
42 
double tfloat
Defines the type for float/double.
Definition: const.h:38