geometria.h
00001 00002 /*****************************************************************************/ 00003 /* */ 00004 /* Fichero: geometria.h */ 00005 /* Autor: Javier C. Osuna Sanz */ 00006 /* Creado: 17/10/2002 */ 00007 /* Modificado: 11/07/2003 */ 00008 /* */ 00009 /*****************************************************************************/ 00010 /* 00011 * This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License as published by 00013 * the Free Software Foundation; either version 2 of the License, or 00014 * (at your option) any later version. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00024 * 00025 */ 00026 #ifndef geometria_h 00027 #define geometria_h 00028 00029 #include <math.h> 00030 #include "nd.h" 00031 00032 /* ------------------------------------------------------------------------- */ 00033 /* Declaraci�n de constantes y macros. */ 00034 /* ------------------------------------------------------------------------- */ 00035 00036 // Declaraci�n de la constante PI. 00037 00038 #ifdef PI 00039 #undef PI 00040 #endif 00041 00042 #define PI 3.1415926535F 00043 #ifndef M_PI 00044 #define M_PI PI 00045 #endif 00046 00047 // Declaraci�n de operaciones b�sicas. 00048 00049 #define CUADRADO(x) (float)((x)*(x)) 00050 #define RAIZ(x) (float)sqrt(x) 00051 00052 #define ARCOTANGENTE(x,y) (float)atan2(y,x) 00053 #define ARCOCOSENO(x,r) (float)acos((x)/(r)) 00054 #define ARCOSENO(y,r) (float)asin((y)/(r)) 00055 00056 #define MINIMO(a,b) ( (a)<=(b) ? (a) : (b) ) 00057 #define MAXIMO(a,b) ( (a)>=(b) ? (a) : (b) ) 00058 00059 /* ------------------------------------------------------------------------- */ 00060 /* Cotas. */ 00061 /* ------------------------------------------------------------------------- */ 00062 00063 extern void AplicarCotas(float *n,float i,float s); 00064 00065 /* ------------------------------------------------------------------------- */ 00066 /* Declaraci�n de tipos y macros relacionadas. */ 00067 /* ------------------------------------------------------------------------- */ 00068 00069 // Coordenadas cartesianas. Espacio real (y pantalla). 00070 00071 #define DISTANCIA_CUADRADO2(p,q) (((p).x-(q).x)*((p).x-(q).x)+((p).y-(q).y)*((p).y-(q).y)) 00072 00073 // Coordenadas polares. Espacio real. 00074 00075 typedef struct { 00076 float r; // Radio. 00077 float a; // �ngulo. 00078 } TCoordenadasPolares; 00079 00080 /* ------------------------------------------------------------------------- */ 00081 /* Construcci�n de coordenadas. */ 00082 /* ------------------------------------------------------------------------- */ 00083 00084 extern void ConstruirCoordenadasCP(TCoordenadas *p,TCoordenadasPolares q); 00085 extern void ConstruirCoordenadasCxy(TCoordenadas *p,float x,float y); 00086 extern void ConstruirCoordenadasCra(TCoordenadas *p,float r,float a); 00087 00088 extern void ConstruirCoordenadasPC(TCoordenadasPolares *p,TCoordenadas q); 00089 extern void ConstruirCoordenadasPxy(TCoordenadasPolares *p,float x,float y); 00090 extern void ConstruirCoordenadasPra(TCoordenadasPolares *p,float r,float a); 00091 00092 // Paso de cartesianas a polares, pero con el m�dulo al cuadrado. 00093 extern void ConstruirCoordenadasPcC(TCoordenadasPolares *p,TCoordenadas q); 00094 00095 /* ------------------------------------------------------------------------- */ 00096 /* Suma y resta de coordenadas. */ 00097 /* ------------------------------------------------------------------------- */ 00098 00099 extern void SumarCoordenadasCxy(TCoordenadas *p,float x,float y); 00100 extern void SumarCoordenadasCxyC(TCoordenadas p,float x,float y,TCoordenadas *q); 00101 extern void SumarCoordenadasCra(TCoordenadas *p,float r,float a); 00102 extern void SumarCoordenadasCraC(TCoordenadas p,float r,float a,TCoordenadas *q); 00103 00104 /* ------------------------------------------------------------------------- */ 00105 /* Transformaciones entre sistemas de coordenadas. */ 00106 /* ------------------------------------------------------------------------- */ 00107 00108 // Transformaciones directas. 00109 00110 extern void TransformacionDirecta(TSR *SR,TCoordenadas *p); 00111 00112 #define TRANSFORMACION01(SR1,p) TransformacionDirecta(SR1,p); 00113 #define TRANSFORMACION12(SR2,p) TransformacionDirecta(SR2,p); 00114 #define TRANSFORMACION23(SR3,p) TransformacionDirecta(SR3,p); 00115 00116 #define TRANSFORMACION02(SR1,SR2,p) \ 00117 { \ 00118 TRANSFORMACION01(SR1,p) \ 00119 TRANSFORMACION12(SR2,p) \ 00120 } 00121 00122 // Transformaciones inversas. 00123 00124 extern void TransformacionInversa(TSR *SR,TCoordenadas *p); 00125 00126 #define TRANSFORMACION32(SR3,p) TransformacionInversa(SR3,p); 00127 #define TRANSFORMACION21(SR2,p) TransformacionInversa(SR2,p); 00128 #define TRANSFORMACION10(SR1,p) TransformacionInversa(SR1,p); 00129 00130 #define TRANSFORMACION20(SR2,SR1,p) \ 00131 { \ 00132 TRANSFORMACION21(SR2,p) \ 00133 TRANSFORMACION10(SR1,p) \ 00134 } 00135 00136 // Transformaciones mixtas. 00137 00138 #define TRANSFORMACION101(SR1a,SR1b,p) \ 00139 { \ 00140 TRANSFORMACION10(SR1a,p) \ 00141 TRANSFORMACION01(SR1b,p) \ 00142 } 00143 00144 /* ------------------------------------------------------------------------- */ 00145 /* �ngulos e intervalos de �ngulos. */ 00146 /* ------------------------------------------------------------------------- */ 00147 00148 extern float AnguloNormalizado(float angulo); 00149 00150 extern int AnguloPerteneceIntervaloOrientadoCerrado(float angulo,float limite1,float limite2); 00151 // Esta funci�n devuelve 1 si el �ngulo est� entre los l�mites; 0 en caso contrario. 00152 // Todos los par�metros deben pertenecer al intervalo (-PI,PI]. 00153 00154 extern float BisectrizAnguloOrientado(float limite1,float limite2); 00155 // Devuelve la bisectriz del �ngulo de "limite1" a "limite2" en sentido contrario a las agujas del reloj. 00156 00157 extern float BisectrizAnguloNoOrientado(float limite1,float limite2); 00158 // Devuelve la bisectriz del menor �ngulo formado por "limite1" y "limite2", ya sea en el sentido de las agujas del reloj o en el opuesto. 00159 00160 extern float AmplitudAnguloOrientado(float limite1,float limite2); 00161 // Devuelve la amplitud del �ngulo de "limite1" a "limite2" en sentido contrario a las agujas del reloj. 00162 00163 extern float AmplitudAnguloNoOrientado(float limite1,float limite2); 00164 // Devuelve la amplitud del menor �ngulo formado por "limite1" y "limite2", ya sea en el sentido de las agujas del reloj o en el opuesto. 00165 00166 /* ------------------------------------------------------------------------- */ 00167 /* Cortes entre dos segmentos, uno de los cuales tiene como uno de sus */ 00168 /* extremos el origen. */ 00169 /* ------------------------------------------------------------------------- */ 00170 00171 void MinimaDistanciaCuadradoCorte(TCoordenadasPolares pp1,TCoordenadasPolares pp2,float angulo,float *distancia); 00172 // Mediante su aplicaci�n reiterada obtenemos el m�s pr�ximo de entre los puntos de corte de un 00173 // grupo de segmentos con una direcci�n determinada. 00174 // "p1" y "p2" son los extremos de un segmento. 00175 // "angulo" es la direcci�n de corte (desde el origen). 00176 // "distancia" es la menor distancia obtenida hasta el momento. 00177 00178 #endif //geometria_h