C library of triangulation algorithms (for the problems of mobile robot positioning or resection)
kaestner.c
Go to the documentation of this file.
1 /**
2  * @file kaestner.c
3  * @date 02/10/2012
4  * @author Vincent Pierlot
5  *
6  * The algorithm was implemented after \cite Burtch2005ThreePoint.
7 */
8 #include <stdio.h>
9 #include <math.h>
10 #include "const.h"
11 #include "kaestner.h"
12 
13 /* ./triangulation -t1 -m20 -1"1000" -2"5300" -3"3100" -4"5000" -5"2200" -6"6300" -a"109.3045" -b"-115.0520" -c"0.0" */
14 /* TODO: handle special cases */
15 tfloat triangulationKaestner(tfloat *x, tfloat *y,
16  tfloat alpha1, tfloat alpha2, tfloat alpha3,
17  tfloat x1, tfloat y1, tfloat x2, tfloat y2, tfloat x3, tfloat y3)
18 {
19  tfloat alpha = alpha1 - alpha3 ; /*printf("alpha = %10.4f\n",alpha*RAD2DEG);*/
20  tfloat beta = alpha3 - alpha2 ; /*printf("beta = %10.4f\n",beta*RAD2DEG);*/
21 
22  tfloat sin_alpha = Sin( alpha ) ;
23  tfloat sin_beta = Sin( beta ) ;
24 
25  tfloat a = sqrt( (x3-x1)*(x3-x1) + (y3-y1)*(y3-y1) ) ;
26  tfloat b = sqrt( (x3-x2)*(x3-x2) + (y3-y2)*(y3-y2) ) ;
27 
28  tfloat AzAC = atan2( (x3-x1) , (y3-y1) ) ; /*printf("AzAC = %10.4f\n",AzAC*RAD2DEG);*/
29  tfloat AzBC = atan2( (x3-x2) , (y3-y2) ) + TWOPI ; /*printf("AzBC = %10.4f\n",AzBC*RAD2DEG);*/
30 
31  tfloat gamma = AzAC - AzBC + TWOPI ; /*printf("gamma = %10.4f\n",gamma*RAD2DEG);*/
32 
33  tfloat delta1 = PI - ( alpha + beta + gamma ) / 2 ; /*printf("delta1 = %10.4f\n",delta1*RAD2DEG);*/
34 
35  tfloat lambda = atan ( a * sin_beta / ( b * sin_alpha ) ) ; /* +/- PI */ /*printf("lambda = %10.4f\n",lambda*RAD2DEG);*/
36 
37  tfloat delta2 = atan( Tan( delta1 * Cot( QUARTPI + lambda ) ) ) ; /* +/- PI */ /*printf("delta2 = %10.4f\n",delta2*RAD2DEG);*/
38 
39  tfloat phi = delta1 + delta2 ; /*printf("phi = %10.4f\n",phi*RAD2DEG);*/
40 
41  tfloat c1 = a * Sin( alpha + phi ) / sin_alpha ;
42 
43  tfloat AzAP = AzAC + phi ;
44 
45  *x = x1 + c1 * Sin( AzAP ) ;
46  *y = y1 + c1 * Cos( AzAP ) ;
47 
48  return lambda ;
49 }
50 
#define PI
The value of PI.
Definition: const.h:12
double tfloat
Defines the type for float/double.
Definition: const.h:38