Back to index

extremetuxracer  0.5beta
plane.cpp
Go to the documentation of this file.
00001 /* 
00002  * Copyright (C) 2004-2005 Volker Stroebel <mmv1@planetpenguin.de>
00003  * 
00004  * Copyright (C) 1999-2001 Jasmin F. Patry
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  * 
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019  */
00020 
00021 #include "plane.h"
00022 
00023 #include "gaus.h"
00024 
00025 
00026 
00027 #include <math.h>
00028 
00029 namespace pp{
00030 
00031 Plane::Plane( const double x, const double y, const double z, const double d ){
00032        nml.x=x;
00033        nml.y=y;
00034        nml.z=z;
00035        this->d=d;
00036 }
00037 
00038 double
00039 Plane::distance(const Vec3d& point) const
00040 {
00041        return        nml.x * point.x +
00042                      nml.y * point.y +
00043                      nml.z * point.z +
00044                      d;     
00045 }
00046 
00047 
00048 bool
00049 Plane::intersect( const Plane& s1, const Plane& s2, const Plane& s3, Vec3d *p )
00050 {
00051        double A[3][4];
00052     double x[3];
00053     double retval;
00054 
00055     A[0][0] =  s1.nml.x;
00056     A[0][1] =  s1.nml.y;
00057     A[0][2] =  s1.nml.z;
00058     A[0][3] = -s1.d;
00059 
00060     A[1][0] =  s2.nml.x;
00061     A[1][1] =  s2.nml.y;
00062     A[1][2] =  s2.nml.z;
00063     A[1][3] = -s2.d;
00064 
00065     A[2][0] =  s3.nml.x;
00066     A[2][1] =  s3.nml.y;
00067     A[2][2] =  s3.nml.z;
00068     A[2][3] = -s3.d;
00069 
00070     retval = gauss( (double*) A, 3, x);
00071 
00072     if ( retval != 0 ) {
00073        /* Matrix is singular */
00074        return false;
00075     } else {
00076        /* Solution found */
00077        p->x = x[0];
00078        p->y = x[1];
00079        p->z = x[2];
00080        return true;
00081     }
00082 }
00083 
00084 
00085 
00086 } //namespace pp