matrix_point.cpp
Upload User: ysz425
Upload Date: 2008-03-14
Package Size: 675k
Code Size: 6k
Development Platform:

Unix_Linux

  1. /*=============================================================================
  2.         File: matrix.cpp
  3.      Purpose:       
  4.     Revision: $Id: matrix_point.cpp,v 1.2 2002/05/13 21:07:45 philosophil Exp $
  5.   Created by: Philippe Lavoie          (3 Oct, 1996)
  6.  Modified by: 
  7.  Copyright notice:
  8.           Copyright (C) 1996-1998 Philippe Lavoie
  9.  
  10.   This library is free software; you can redistribute it and/or
  11.   modify it under the terms of the GNU Library General Public
  12.   License as published by the Free Software Foundation; either
  13.   version 2 of the License, or (at your option) any later version.
  14.  
  15.   This library is distributed in the hope that it will be useful,
  16.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18.   Library General Public License for more details.
  19.  
  20.   You should have received a copy of the GNU Library General Public
  21.   License along with this library; if not, write to the Free
  22.   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. =============================================================================*/
  24. #include "matrix.cpp"
  25. namespace PLib {
  26.   double
  27.     Matrix<Point3Df>::norm(void) {
  28.     int i,j ;
  29.     double sumX, sumY, sumZ, maxsum;
  30.     int init=0 ;
  31.     Point3Df *ptr ;
  32.     ptr = m-1 ;
  33.     maxsum = -1 ; // shuts up the warning messages 
  34.     for(i=0;i<rows();++i){
  35.       sumX = 0.0 ;
  36.       sumY = 0.0 ;
  37.       sumZ = 0.0 ;
  38.       for ( j = 0; j < cols(); ++j) {
  39. sumX += (*ptr).x() * (*ptr).x() ;
  40. sumY += (*ptr).y() * (*ptr).y() ;
  41. sumZ += (*ptr).z() * (*ptr).z() ;
  42.       }
  43.       if(init)
  44. maxsum = (maxsum>(sumX+sumY+sumZ)) ? maxsum : (sumX+sumY+sumZ);
  45.       else{
  46. maxsum = (sumX+sumY+sumZ) ;
  47. init = 1;
  48.       }
  49.       ++ptr ;
  50.     }
  51.     return sqrt(maxsum);
  52.   }
  53.   
  54.   double
  55.     Matrix<Point3Dd>::norm(void) {
  56.     int i,j ;
  57.     double sumX, sumY, sumZ, maxsum;
  58.     int init=0 ;
  59.     Point3Dd *ptr ;
  60.     ptr = m-1 ;
  61.     maxsum = -1 ; // shuts up the warning messages 
  62.     for(i=0;i<rows();++i){
  63.       sumX = 0.0 ;
  64.       sumY = 0.0 ;
  65.       sumZ = 0.0 ;
  66.       for ( j = 0; j < cols(); ++j) {
  67. sumX += (*ptr).x() * (*ptr).x() ;
  68. sumY += (*ptr).y() * (*ptr).y() ;
  69. sumZ += (*ptr).z() * (*ptr).z() ;
  70.       }
  71.       if(init)
  72. maxsum = (maxsum>(sumX+sumY+sumZ)) ? maxsum : (sumX+sumY+sumZ);
  73.       else{
  74. maxsum = (sumX+sumY+sumZ) ;
  75. init = 1;
  76.       }
  77.       ++ptr ;
  78.     }
  79.     return sqrt(maxsum);
  80.   }
  81.   
  82.   double
  83.     Matrix<Point2Df>::norm(void) {
  84.     int i,j ;
  85.     double sumX, sumY, sumZ, maxsum;
  86.     int init=0 ;
  87.     Point2Df *ptr ;
  88.     ptr = m-1 ;
  89.     maxsum = -1 ; // shuts up the warning messages 
  90.     for(i=0;i<rows();++i){
  91.       sumX = 0.0 ;
  92.       sumY = 0.0 ;
  93.       sumZ = 0.0 ;
  94.       for ( j = 0; j < cols(); ++j) {
  95. sumX += (*ptr).x() * (*ptr).x() ;
  96. sumY += (*ptr).y() * (*ptr).y() ;
  97. sumZ += (*ptr).z() * (*ptr).z() ;
  98.       }
  99.       if(init)
  100. maxsum = (maxsum>(sumX+sumY+sumZ)) ? maxsum : (sumX+sumY+sumZ);
  101.       else{
  102. maxsum = (sumX+sumY+sumZ) ;
  103. init = 1;
  104.       }
  105.       ++ptr ;
  106.     }
  107.     return sqrt(maxsum);
  108.   }
  109.   double
  110.     Matrix<Point2Dd>::norm(void) {
  111.     int i,j ;
  112.     double sumX, sumY, sumZ, maxsum;
  113.     int init=0 ;
  114.     Point2Dd *ptr ;
  115.     ptr = m-1 ;
  116.     maxsum = -1 ; // shuts up the warning messages 
  117.     for(i=0;i<rows();++i){
  118.       sumX = 0.0 ;
  119.       sumY = 0.0 ;
  120.       sumZ = 0.0 ;
  121.       for ( j = 0; j < cols(); ++j) {
  122. sumX += (*ptr).x() * (*ptr).x() ;
  123. sumY += (*ptr).y() * (*ptr).y() ;
  124. sumZ += (*ptr).z() * (*ptr).z() ;
  125.       }
  126.       if(init)
  127. maxsum = (maxsum>(sumX+sumY+sumZ)) ? maxsum : (sumX+sumY+sumZ);
  128.       else{
  129. maxsum = (sumX+sumY+sumZ) ;
  130. init = 1;
  131.       }
  132.       ++ptr ;
  133.     }
  134.     return sqrt(maxsum);
  135.   }
  136.   
  137. #ifdef NO_IMPLICIT_TEMPLATES
  138.   // Point3D instantiation
  139.   
  140.   template class Matrix<Point3Df> ;
  141.   
  142.   template Matrix<Point3Df> operator+(const Matrix<Point3Df>&,const Matrix<Point3Df>&);
  143.   template Matrix<Point3Df> operator-(const Matrix<Point3Df>&,const Matrix<Point3Df>&);
  144.   template Matrix<Point3Df> operator*(const Matrix<Point3Df>&,const Matrix<Point3Df>&);
  145.   template Matrix<Point3Df> operator*(const double,const Matrix<Point3Df>&);
  146.   template int operator==(const Matrix<Point3Df>&,const Matrix<Point3Df>&);
  147.   // template int operator!=(const Matrix<Point3Df>&,const Matrix<Point3Df>&);
  148.   template Matrix<Point3Df> comm(const Matrix<Point3Df>&,const Matrix<Point3Df>&);
  149.   
  150.   
  151.   template class Matrix<Point3Dd> ;
  152.   
  153.   template Matrix<Point3Dd> operator+(const Matrix<Point3Dd>&,const Matrix<Point3Dd>&);
  154.   template Matrix<Point3Dd> operator-(const Matrix<Point3Dd>&,const Matrix<Point3Dd>&);
  155.   template Matrix<Point3Dd> operator*(const Matrix<Point3Dd>&,const Matrix<Point3Dd>&);
  156.   template Matrix<Point3Dd> operator*(const double,const Matrix<Point3Dd>&);
  157.   template int operator==(const Matrix<Point3Dd>&,const Matrix<Point3Dd>&);
  158.   //template int operator!=(const Matrix<Point3Dd>&,const Matrix<Point3Dd>&);
  159.   template Matrix<Point3Dd> comm(const Matrix<Point3Dd>&,const Matrix<Point3Dd>&);
  160.   
  161.   // Point2D instantiation
  162.   
  163.   template class Matrix<Point2Df> ;
  164.   
  165.   template Matrix<Point2Df> operator+(const Matrix<Point2Df>&,const Matrix<Point2Df>&);
  166.   template Matrix<Point2Df> operator-(const Matrix<Point2Df>&,const Matrix<Point2Df>&);
  167.   template Matrix<Point2Df> operator*(const Matrix<Point2Df>&,const Matrix<Point2Df>&);
  168.   template Matrix<Point2Df> operator*(const double,const Matrix<Point2Df>&);
  169.   template int operator==(const Matrix<Point2Df>&,const Matrix<Point2Df>&);
  170.   //template int operator!=(const Matrix<Point2Df>&,const Matrix<Point2Df>&);
  171.   template Matrix<Point2Df> comm(const Matrix<Point2Df>&,const Matrix<Point2Df>&);
  172.   
  173.   template class Matrix<Point2Dd> ;
  174.   
  175.   template Matrix<Point2Dd> operator+(const Matrix<Point2Dd>&,const Matrix<Point2Dd>&);
  176.   template Matrix<Point2Dd> operator-(const Matrix<Point2Dd>&,const Matrix<Point2Dd>&);
  177.   template Matrix<Point2Dd> operator*(const Matrix<Point2Dd>&,const Matrix<Point2Dd>&);
  178.   template Matrix<Point2Dd> operator*(const double,const Matrix<Point2Dd>&);
  179.   template int operator==(const Matrix<Point2Dd>&,const Matrix<Point2Dd>&);
  180.   //template int operator!=(const Matrix<Point2Dd>&,const Matrix<Point2Dd>&);
  181.   template Matrix<Point2Dd> comm(const Matrix<Point2Dd>&,const Matrix<Point2Dd>&);
  182. #endif
  183. }