home *** CD-ROM | disk | FTP | other *** search
/ vis-ftp.cs.umass.edu / vis-ftp.cs.umass.edu.tar / vis-ftp.cs.umass.edu / pub / Software / ASCENDER / ascendMar8.tar / UMass / BuildingFinder / Staging / math.c < prev    next >
C/C++ Source or Header  |  1995-04-12  |  2KB  |  94 lines

  1. /*----------------------------------------------------------------------------
  2.  
  3.         math.c
  4.  
  5.         A couple of vector/matrix operators.
  6.  
  7.         Author:  Christopher Jaynes
  8.         Date  :  Jan. 28, 1995
  9.         
  10.         RADIUS Project.
  11.  
  12. -----------------------------------------------------------------------------*/
  13.         
  14.  
  15. #include "../polygons.h"
  16. #include "rcde_types.h"
  17.  
  18. extern c_handle make_image();
  19. extern c_handle push_image();
  20. extern c_handle_1_int_3* pick_a_pane();
  21.  
  22. struct c_handle_1_int_3* pane_choice;
  23. struct c_handle_1_int_2* image_choice;
  24.  
  25.  
  26.  
  27. void vector_matrix_multiply(Point *p, RotMatrix m);
  28. void matrix_multiply(RotMatrix m1, RotMatrix m2, RotMatrix result);
  29.  
  30.  
  31.  
  32. void vector_matrix_multiply(Point *p, RotMatrix m)
  33. {
  34.  
  35.     Point temp;
  36.     
  37.     temp.x =  (m[0][0] * p->x +
  38.                 m[1][0] * p->y +
  39.                 m[2][0] * p->z +
  40.             m[3][0] * p->r);
  41.  
  42.     temp.y =  (m[0][1] * p->x +
  43.                 m[1][1] * p->y +
  44.                 m[2][1] * p->z +
  45.             m[3][1] * p->r);
  46.  
  47.     temp.z =  (m[0][2] * p->x +
  48.                 m[1][2] * p->y +
  49.                    m[2][2] * p->z +
  50.             m[3][2] * p->r);
  51.  
  52.     temp.r =  (m[0][3] * p->x +
  53.             m[1][3] * p->y +
  54.             m[2][3] * p->z +
  55.             m[3][3] * p->r);
  56.     p->x = temp.x;
  57.     p->y = temp.y;
  58.     p->z = temp.z;
  59.     p->r = temp.r;
  60.  
  61. }
  62.  
  63.  
  64. void matrix_multiply(RotMatrix m1, RotMatrix m2, RotMatrix result)
  65. {
  66.  
  67.     int i;
  68.     Point vec;
  69.  
  70.     for (i=0; i < 4; i++) {
  71.         vec.x = m1[i][0];
  72.         vec.y = m1[i][1];
  73.         vec.z = m1[i][2];
  74.         vec.r = m1[i][3];
  75.  
  76.         vector_matrix_multiply(&vec,m2);
  77.         
  78.         result[i][0] = vec.x;
  79.         result[i][1] = vec.y;
  80.         result[i][2] = vec.z;
  81.         result[i][3] = vec.r;
  82.     }
  83. }
  84.  
  85. double
  86. distance(double x1, double y1, double x2, double y2)
  87. {
  88.         double result;
  89.         double sqrt();
  90.  
  91.         result =  sqrt( (double) (SQ(x1-x2) + SQ(y1-y2) ));
  92.         return( result );
  93. }
  94.