calcul.c
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
27 /***************************************************/
28 /* Last Revised:
29 $Id: calcul.c 8465 2009-12-16 00:44:13Z gbiggs $
30 */
31 /***************************************************/
32 /*
33  * This program is free software; you can redistribute it and/or modify
34  * it under the terms of the GNU General Public License as published by
35  * the Free Software Foundation; either version 2 of the License, or
36  * (at your option) any later version.
37  *
38  * This program is distributed in the hope that it will be useful,
39  * but WITHOUT ANY WARRANTY; without even the implied warranty of
40  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41  * GNU General Public License for more details.
42  *
43  * You should have received a copy of the GNU General Public License
44  * along with this program; if not, write to the Free Software
45  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
46  *
47  */
48 
54 #include "calcul.h"
55 
56 
57 
58 void transfor_directa_p(float x, float y,
59  Tsc *sistema, Tpf *sol){
60 
61  /* Esta funcion transforma el punto x,y en el sistema de coordenadas mas global*/
62  /* Es decir las coordenadas x y son vistas desde el sistema de coordenadas sistema*/
63  /* Y se las quiere transformar en el sistema de ref desde el que se sistema*/
64  /* Es la transformacion directa */
65 
66  float SinT,CosT;
67 
68  SinT=(float)sin(sistema->tita);
69  CosT=(float)cos(sistema->tita);
70 
71  sol->x=x*CosT-y*SinT+sistema->x;
72  sol->y=x*SinT+y*CosT+sistema->y;
73 
74  //fprintf(stderr,"input:<%f,%f> sis:<%f %f %f> sol:<%f %f>\n",x,y,sistema->x, sistema->y, sistema->tita,sol->x, sol->y);
75 
76 }
77 
78 void transfor_directa_pt0(float x, float y,
79  Tsc *sistema, Tpf *sol){
80 
81  /* Esta funcion transforma el punto x,y en el sistema de coordenadas mas global*/
82  /* Es decir las coordenadas x y son vistas desde el sistema de coordenadas sistema*/
83  /* Y se las quiere transformar en el sistema de ref desde el que se sistema*/
84  /* Es la transformacion directa */
85 
86  sol->x=x+sistema->x;
87  sol->y=y+sistema->y;
88 
89 }
90 
91 
92 void transfor_inversa_p(float x,float y,
93  Tsc *sistema, Tpf *sol){
94 
95  /* Esta funcion transforma el punto x,y en el sistema de coordenadas que entra*/
96  /* Las coordenadas x y se ven desde el sistema de coordenadas desde el que se tienen las */
97  /* las coordenadas de sistema */
98  /* Es la transformacion directa */
99 
100  float a13, a23;
101  float SinT,CosT;
102 
103  SinT=(float)sin(sistema->tita);
104  CosT=(float)cos(sistema->tita);
105 
106 
107  a13=-sistema->y*SinT-sistema->x*CosT;
108  a23=-sistema->y*CosT+sistema->x*SinT;
109 
110  sol->x=x*CosT+y*SinT+a13;
111  sol->y=-x*SinT+y*CosT+a23;
112 }
113 
114 float NormalizarPI(float ang){
115 
116  return (float)(ang+(2*M_PI)*floor((M_PI-ang)/(2*M_PI)));
117 }
118 
119 void inversion_sis(Tsc *sisIn, Tsc *sisOut){
120 
121  float c,s;
122 
123  c=(float)cos(sisIn->tita);
124  s=(float)sin(sisIn->tita);
125  sisOut->x =-c*sisIn->x-s*sisIn->y;
126  sisOut->y = s*sisIn->x-c*sisIn->y;
127  sisOut->tita = NormalizarPI(-sisIn->tita);
128 }
129 
130 void composicion_sis(Tsc *sis1,Tsc *sis2,Tsc *sisOut){
131 
132  Tpf sol;
133 
134  transfor_directa_p(sis2->x, sis2->y,
135  sis1, &sol);
136  sisOut->x=sol.x;
137  sisOut->y=sol.y;
138  sisOut->tita = NormalizarPI(sis1->tita+sis2->tita);
139 
140 }
141 
142 void car2pol(Tpf *in, Tpfp *out){
143 
144  out->r=(float)sqrt(in->x*in->x+in->y*in->y);
145  out->t=(float)atan2(in->y,in->x);
146 }
147 
148 void pol2car(Tpfp *in, Tpf *out){
149 
150  out->x=in->r*(float)cos(in->t);
151  out->y=in->r*(float)sin(in->t);
152 }
153 
154 
155 
156 
157 int corte_segmentos(float x1,float y1,float x2,float y2,
158  float x3,float y3,float x4,float y4,
159  Tpf *sol){
160 /* corte de segmentos */
161 /* TE DEVUELVE EL PUNTO DE CORTE EN EL SISTEMA QUE ESTEN LOS SEGMENTOS */
162 
163  float a1,a2,b1,b2,c1,c2,xm,ym,denominador,max1_x,max1_y,min1_x,min1_y;
164  float xerr,yerr;
165  int si1;
166  float error_redondeo;
167 
168  error_redondeo=(float)0.00001F;
169 
170  /* primera recta */
171  a1=y2-y1;
172  b1=x1-x2;
173  c1=y1*(-b1)-x1*a1;
174 
175  /* segunda recta */
176  a2=y4-y3;
177  b2=x3-x4;
178  c2=y3*(-b2)-x3*a2;
179 
180 
181  denominador=a1*b2-a2*b1;
182  if (denominador==0)
183  return 0;
184  else{
185  xm=(b1*c2-b2*c1)/denominador;
186  ym=(c1*a2-c2*a1)/denominador;
187 
188  xerr=xm+error_redondeo;
189  yerr=ym+error_redondeo;
190 
191  /* Comprobamos que cae entre los segmantos */
192  if (x1>x2){
193  max1_x=x1; min1_x=x2;
194  }
195  else{
196  max1_x=x2; min1_x=x1;
197  }
198  if (y1>y2){
199  max1_y=y1; min1_y=y2;
200  }
201  else{
202  max1_y=y2; min1_y=y1;
203  }
204  si1=0;
205  if (max1_x+error_redondeo>=xm && xerr>=min1_x && max1_y+error_redondeo>=ym && yerr>=min1_y)
206  si1=1;
207 
208 
209  if (si1){
210 
211  if (x3>x4){
212  max1_x=x3; min1_x=x4;
213  }
214  else{
215  max1_x=x4; min1_x=x3;
216  }
217  if (y3>y4){
218  max1_y=y3; min1_y=y4;
219  }
220  else{
221  max1_y=y4; min1_y=y3;
222  }
223 
224  if (max1_x+error_redondeo>=xm && xerr>=min1_x && max1_y+error_redondeo>=ym && yerr>=min1_y){
225  sol->x=xm;
226  sol->y=ym;
227  return 1;
228  }
229  }
230  return 0;
231  }
232 }
233 
void transfor_directa_p(float x, float y, Tsc *sistema, Tpf *sol)
Definition: calcul.c:58
float NormalizarPI(float ang)
Definition: calcul.c:114
float t
Definition: TData.h:76
float tita
Definition: TData.h:87
Definition: TData.h:68
Auxiliary function declaration for the MbICP module.
float y
Definition: TData.h:70
void car2pol(Tpf *in, Tpfp *out)
Definition: calcul.c:142
float r
Definition: TData.h:75
#define M_PI
Definition: TData.h:61
void transfor_inversa_p(float x, float y, Tsc *sistema, Tpf *sol)
Definition: calcul.c:92
Definition: TData.h:84
float y
Definition: TData.h:86
float x
Definition: TData.h:85
void transfor_directa_pt0(float x, float y, Tsc *sistema, Tpf *sol)
Definition: calcul.c:78
void pol2car(Tpfp *in, Tpf *out)
Definition: calcul.c:148
void composicion_sis(Tsc *sis1, Tsc *sis2, Tsc *sisOut)
Definition: calcul.c:130
int corte_segmentos(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, Tpf *sol)
Definition: calcul.c:157
float x
Definition: TData.h:69
Definition: TData.h:74
void inversion_sis(Tsc *sisIn, Tsc *sisOut)
Definition: calcul.c:119


lidar_egomotion
Author(s): Jorge Almeida
autogenerated on Mon Mar 2 2015 01:32:10