00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <freecloth/geom/geVector.h>
00020 #include <freecloth/geom/gePoint.h>
00021
00022
00023
00024
00025 FREECLOTH_NAMESPACE_START
00026
00027
00028
00029
00030 const GeVector GeVector::ZERO( 0, 0, 0 );
00031 const GeVector GeVector::X( 1, 0, 0 );
00032 const GeVector GeVector::Y( 0, 1, 0 );
00033 const GeVector GeVector::Z( 0, 0, 1 );
00034
00035
00036
00037 GeVector::GeVector( const GePoint& p1, const GePoint& p2 )
00038 : _x( p2._x - p1._x ), _y( p2._y - p1._y), _z( p2._z - p1._z )
00039 {}
00040
00041
00042
00043 Float GeVector::getAngle( const GeVector& rhs ) const
00044 {
00045
00046 #if 0
00047 const GeVector lunit( getUnit() );
00048 const GeVector runit( rhs.getUnit() );
00049 Float costheta = lunit.dot( runit );
00050 Float sintheta = lunit.cross( runit );
00051 return BaMath::arctan2( sintheta, costheta );
00052 #endif
00053 Float th1 = BaMath::arctan2( _y, _x );
00054 Float th2 = BaMath::arctan2( rhs._y, rhs._x );
00055 Float result = th2 - th1;
00056 while ( BaMath::isLess( result, 0 ) ) result += 2 * M_PI;
00057 while ( BaMath::isGreater( result, 2 * M_PI ) ) result -= 2 * M_PI;
00058 return result;
00059 }
00060
00061
00062
00063
00064
00065
00066
00067
00068 std::ostream& operator<<( std::ostream& os, const GeVector& v )
00069 {
00070 os << "v(" << v._x << "," << v._y << "," << v._z << ")";
00071 return os;
00072 }
00073
00074 FREECLOTH_NAMESPACE_END