util.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <math.h>
00003 #include "util.h"
00004 
00005 void get_rot( double a, double b , double c, double trans[3][4] )
00006 {
00007     double  sina, sinb, sinc, cosa, cosb, cosc;
00008 
00009     sina = sin(a); cosa = cos(a);
00010     sinb = sin(b); cosb = cos(b);
00011     sinc = sin(c); cosc = cos(c);
00012     trans[0][0] = cosa*cosa*cosb*cosc+sina*sina*cosc+sina*cosa*cosb*sinc-sina*cosa*sinc;
00013     trans[0][1] = -cosa*cosa*cosb*sinc-sina*sina*sinc+sina*cosa*cosb*cosc-sina*cosa*cosc;
00014     trans[0][2] = cosa*sinb;
00015     trans[1][0] = sina*cosa*cosb*cosc-sina*cosa*cosc+sina*sina*cosb*sinc+cosa*cosa*sinc;
00016     trans[1][1] = -sina*cosa*cosb*sinc+sina*cosa*sinc+sina*sina*cosb*cosc+cosa*cosa*cosc;
00017     trans[1][2] = sina*sinb;
00018     trans[2][0] = -cosa*sinb*cosc-sina*sinb*sinc;
00019     trans[2][1] = cosa*sinb*sinc-sina*sinb*cosc;
00020     trans[2][2] = cosb;
00021 
00022     return;
00023 }
00024 
00025 int get_angle( double trans[3][4], double *wa, double *wb, double *wc )
00026 {
00027     double      a, b, c;
00028     double      sina, cosa, sinb, cosb, sinc, cosc;
00029 
00030     if( trans[2][2] > 1.0 ) {
00031         printf("cos(beta) = %f\n", trans[2][2]);
00032         trans[2][2] = -1.0;
00033     }
00034     else if( trans[2][2] < -1.0 ) {
00035         printf("cos(beta) = %f\n", trans[2][2]);
00036         trans[2][2] = -1.0;
00037     }
00038     cosb = trans[2][2];
00039     b = acos( cosb );
00040     sinb = sin( b );
00041     if( b >= 0.000001 || b <= -0.000001) {
00042         cosa = trans[0][2] / sinb;
00043         sina = trans[1][2] / sinb;
00044         if( cosa > 1.0 ) {
00045             printf("cos(alph) = %f\n", cosa);
00046             cosa = 1.0;
00047             sina = 0.0;
00048         }
00049         if( cosa < -1.0 ) {
00050             printf("cos(alph) = %f\n", cosa);
00051             cosa = -1.0;
00052             sina =  0.0;
00053         }
00054         if( sina > 1.0 ) {
00055             printf("sin(alph) = %f\n", sina);
00056             sina = 1.0;
00057             cosa = 0.0;
00058         }
00059         if( sina < -1.0 ) {
00060             printf("sin(alph) = %f\n", sina);
00061             sina = -1.0;
00062             cosa =  0.0;
00063         }
00064         a = acos( cosa );
00065         if( sina < 0 ) a = -a;
00066 
00067         sinc =  (trans[2][1]*trans[0][2]-trans[2][0]*trans[1][2])
00068               / (trans[0][2]*trans[0][2]+trans[1][2]*trans[1][2]);
00069         cosc =  -(trans[0][2]*trans[2][0]+trans[1][2]*trans[2][1])
00070                / (trans[0][2]*trans[0][2]+trans[1][2]*trans[1][2]);
00071         if( cosc > 1.0 ) {
00072             printf("cos(r) = %f\n", cosc);
00073             cosc = 1.0;
00074             sinc = 0.0;
00075         }
00076         if( cosc < -1.0 ) {
00077             printf("cos(r) = %f\n", cosc);
00078             cosc = -1.0;
00079             sinc =  0.0;
00080         }
00081         if( sinc > 1.0 ) {
00082             printf("sin(r) = %f\n", sinc);
00083             sinc = 1.0;
00084             cosc = 0.0;
00085         }
00086         if( sinc < -1.0 ) {
00087             printf("sin(r) = %f\n", sinc);
00088             sinc = -1.0;
00089             cosc =  0.0;
00090         }
00091         c = acos( cosc );
00092         if( sinc < 0 ) c = -c;
00093     }
00094     else {
00095         a = b = 0.0;
00096         cosa = cosb = 1.0;
00097         sina = sinb = 0.0;
00098         cosc = trans[0][0];
00099         sinc = trans[1][0];
00100         if( cosc > 1.0 ) {
00101             printf("cos(r) = %f\n", cosc);
00102             cosc = 1.0;
00103             sinc = 0.0;
00104         }
00105         if( cosc < -1.0 ) {
00106             printf("cos(r) = %f\n", cosc);
00107             cosc = -1.0;
00108             sinc =  0.0;
00109         }
00110         if( sinc > 1.0 ) {
00111             printf("sin(r) = %f\n", sinc);
00112             sinc = 1.0;
00113             cosc = 0.0;
00114         }
00115         if( sinc < -1.0 ) {
00116             printf("sin(r) = %f\n", sinc);
00117             sinc = -1.0;
00118             cosc =  0.0;
00119         }
00120         c = acos( cosc );
00121         if( sinc < 0 ) c = -c;
00122     }
00123 
00124     *wa = a;
00125     *wb = b;
00126     *wc = c;
00127 
00128     return(0);
00129 }
00130 
00131 double get_height( double px, double py, double trans[3][4], double boundary[3][2] )
00132 {
00133     double x, x0, x1, x2;
00134     double y, y0, y1, y2;
00135     double d, m00, m01, m10, m11;
00136     double rx, ry;
00137 
00138     x = boundary[0][0];
00139     y = boundary[1][0];
00140     x0 = trans[0][0]*x + trans[0][1]*y + trans[0][3];
00141     y0 = trans[1][0]*x + trans[1][1]*y + trans[1][3];
00142     x = boundary[0][1];
00143     y = boundary[1][0];
00144     x1 = trans[0][0]*x + trans[0][1]*y + trans[0][3];
00145     y1 = trans[1][0]*x + trans[1][1]*y + trans[1][3];
00146     x = boundary[0][0];
00147     y = boundary[1][1];
00148     x2 = trans[0][0]*x + trans[0][1]*y + trans[0][3];
00149     y2 = trans[1][0]*x + trans[1][1]*y + trans[1][3];
00150 
00151     x1 -= x0; y1 -= y0;
00152     x2 -= x0; y2 -= y0;
00153     x0 = px - x0;
00154     y0 = py - y0;
00155 
00156     d = x1*y2 - x2*y1;
00157     if( d == 0.0 ) return 0.0;
00158     m00 =  y2 / d;
00159     m01 = -x2 / d;
00160     m10 = -y1 / d;
00161     m11 =  x1 / d;
00162 
00163     rx = m00*x0 + m01*y0;
00164     ry = m10*x0 + m11*y0;
00165 
00166     if( rx >= 0.0 && rx <= 1.0 && ry >= 0.0 && ry <= 1.0 ) {
00167         return trans[2][3] + boundary[2][1];
00168     }
00169 
00170     return 0.0;
00171 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


ar_recog
Author(s): Graylin Trevor Jay and Christopher Crick
autogenerated on Fri Jan 25 2013 12:15:00