utilities3D.cpp

00001 
00016 #include <sstream>
00017 #include <dlrCommon/exception.h>
00018 #include <dlrCommon/types.h>
00019 #include <dlrGeometry/utilities3D.h>
00020 #include <dlrLinearAlgebra/linearAlgebra.h>
00021 #include <dlrNumeric/array2D.h>
00022 
00023 namespace dlr {
00024 
00025   namespace geometry {
00026 
00027 
00028     Vector3D
00029     findIntersect(const Ray3D& ray, const Plane3D& plane, double& distance)
00030     {
00031       Float64 bufferA[9];
00032       Float64 bufferB[3];
00033       
00034       Array2D<double> AMatrix(3, 3, bufferA);
00035       Array1D<double> bVector(3, bufferB);
00036 
00037       AMatrix[0] = ray.getDirectionVector().x();
00038       AMatrix[3] = ray.getDirectionVector().y();
00039       AMatrix[6] = ray.getDirectionVector().z();
00040       AMatrix[1] = plane.getDirectionVector0().x();
00041       AMatrix[4] = plane.getDirectionVector0().y();
00042       AMatrix[7] = plane.getDirectionVector0().z();
00043       AMatrix[2] = plane.getDirectionVector1().x();
00044       AMatrix[5] = plane.getDirectionVector1().y();
00045       AMatrix[8] = plane.getDirectionVector1().z();
00046 
00047       bVector[0] = plane.getOrigin().x() - ray.getOrigin().x();
00048       bVector[1] = plane.getOrigin().y() - ray.getOrigin().y();
00049       bVector[2] = plane.getOrigin().z() - ray.getOrigin().z();
00050 
00051       try {
00052         linearSolveInPlace(AMatrix, bVector);
00053       } catch(const ValueException&) {
00054         std::ostringstream message;
00055         message << "Unable to find intersection of " << ray << " with "
00056                 << plane << ".  Perhaps the ray is parallel to the plane.";
00057         DLR_THROW(ValueException, "findIntersect()", message.str().c_str());
00058       }
00059       
00060       distance = bVector[0];
00061       return ray.getOrigin() + distance * ray.getDirectionVector();
00062     }
00063      
00064       
00065     
00066   } // namespace utilities
00067     
00068 } // namespace dlr

Generated on Mon Jul 9 20:34:03 2007 for dlrLibs Utility Libraries by  doxygen 1.5.2