本文整理汇总了C++中vec3d::mag方法的典型用法代码示例。如果您正苦于以下问题:C++ vec3d::mag方法的具体用法?C++ vec3d::mag怎么用?C++ vec3d::mag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec3d
的用法示例。
在下文中一共展示了vec3d::mag方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slerp
// Spherical linear interpolation between direction vectors.
// Intermediate vectors follow great circle path with constant velocity.
vec3d slerp( const vec3d& a, const vec3d& b, const double &t )
{
vec3d an = a / a.mag();
vec3d bn = b / b.mag();
double dp = dot( an, bn );
double theta = 0.0;
if ( dp >= -1.0 && dp <= 1.0 )
{
theta = acos( dp );
}
// Initialize retvec as a-direction.
vec3d retvec = an;
// If vectors are not parallel, interpolate between them.
if ( std::abs( theta ) > 1.0e-6 )
{
// Drop division by sin(theta) because .normalize() will scale
double coeff1 = sin( ( 1.0 - t ) * theta ); // implied / sin(theta)
double coeff2 = sin( t * theta ); // implied / sin(theta)
retvec = coeff1 * an + coeff2 * bn;
retvec.normalize();
}
return retvec;
}
示例2: angle
//******* Angle Between Vectors ******//
double angle(const vec3d& a, const vec3d& b)
{
double angle = dot(a, b)/(a.mag()*b.mag());
if ( angle < -1.0 ) angle = -1.0;
else if ( angle > 1.0 ) angle = 1.0;
return(acos(angle));
}
示例3: cos_angle
//******* Cosine of Angle Between Vectors ******//
double cos_angle(const vec3d& a, const vec3d& b)
{
double angle = dot(a, b)/(a.mag()*b.mag());
if (angle < -1.0 )
return -1.0;
else if ( angle > 1.0)
return 1.0;
return angle;
}
示例4: angle
//******* Angle Between Vectors ******//
double angle( const vec3d& a, const vec3d& b )
{
double angle = dot( a, b ) / ( a.mag() * b.mag() );
if ( angle >= -1.0 && angle <= 1.0 )
{
return( acos( angle ) );
}
else
{
return( 0.0 );
}
}
示例5: proj
//to return projection vector
vec3d vec3d :: proj(const vec3d& vec) const
{
float m = vec.mag();
if(m == 0)
throw "invalid vector";
return vec.unit()*(operator*(vec)/m);
}
示例6: acos
//to return the angle between vectors in radians
double vec3d :: angle(const vec3d& vec) const
{
float this_mag = mag();
float vec_mag = vec.mag();
if(this_mag == 0 || vec_mag == 0)
throw "invalid vector";
return acos(operator*(vec)/(this_mag*vec_mag));
}