MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2004 Sandia Corporation and Argonne National 00005 Laboratory. Under the terms of Contract DE-AC04-94AL85000 00006 with Sandia Corporation, the U.S. Government retains certain 00007 rights in this software. 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 (lgpl.txt) along with this library; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00023 [email protected], [email protected], [email protected], 00024 [email protected], [email protected], [email protected] 00025 00026 ***************************************************************** */ 00027 #include "Vector3D.hpp" 00028 #include "MsqError.hpp" 00029 00030 #include "moab/Util.hpp" 00031 00032 #include <iostream> 00033 #include <cmath> 00034 00035 #ifdef MSQ_HAVE_IEEEFP_H 00036 #include <ieeefp.h> 00037 #endif 00038 00039 namespace MBMesquite 00040 { 00041 00042 std::ostream& operator<<( std::ostream& s, const MBMesquite::Vector3D& v ) 00043 { 00044 return s << v[0] << ' ' << v[1] << ' ' << v[2]; 00045 } 00046 00047 double Vector3D::interior_angle( const Vector3D& lhs, const Vector3D& rhs, MsqError& err ) 00048 { 00049 double len1 = lhs.length(); 00050 double len2 = rhs.length(); 00051 double angle_cos = ( lhs % rhs ) / ( len1 * len2 ); 00052 if( !moab::Util::is_finite( angle_cos ) ) 00053 { 00054 MSQ_SETERR( err )( MsqError::INTERNAL_ERROR ); 00055 return 0.0; 00056 } 00057 00058 // Adjust the cosine if slightly out of range 00059 if( ( angle_cos > 1.0 ) && ( angle_cos < 1.0001 ) ) 00060 { 00061 angle_cos = 1.0; 00062 } 00063 else if( angle_cos < -1.0 && angle_cos > -1.0001 ) 00064 { 00065 angle_cos = -1.0; 00066 } 00067 00068 return std::acos( angle_cos ); 00069 } 00070 00071 } // namespace MBMesquite