本文整理汇总了C++中Vector3s::norm方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector3s::norm方法的具体用法?C++ Vector3s::norm怎么用?C++ Vector3s::norm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector3s
的用法示例。
在下文中一共展示了Vector3s::norm方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: computeGeneralizedFrictionDisk
// This method and the smooth version share the second half of code. Abstract that out.
void StaticPlaneSphereConstraint::computeGeneralizedFrictionDisk( const VectorXs& q, const VectorXs& v, const int start_column, const int num_samples, SparseMatrixsc& D, VectorXs& drel ) const
{
assert( start_column >= 0 );
assert( start_column < D.cols() );
assert( num_samples > 0 );
assert( start_column + num_samples - 1 < D.cols() );
assert( q.size() % 12 == 0 );
assert( q.size() == 2 * v.size() );
const Vector3s n{ m_plane.n() };
assert( fabs( n.norm() - 1.0 ) <= 1.0e-6 );
std::vector<Vector3s> friction_disk( static_cast<std::vector<Vector3s>::size_type>( num_samples ) );
assert( friction_disk.size() == std::vector<Vector3s>::size_type( num_samples ) );
{
// Compute the relative velocity
Vector3s tangent_suggestion{ computeRelativeVelocity( q, v ) };
if( tangent_suggestion.cross( n ).squaredNorm() < 1.0e-9 )
{
tangent_suggestion = FrictionUtilities::orthogonalVector( n );
}
tangent_suggestion *= -1.0;
// Sample the friction disk
FrictionUtilities::generateOrthogonalVectors( n, friction_disk, tangent_suggestion );
}
assert( unsigned( num_samples ) == friction_disk.size() );
// Compute the displacement from the center of mass to the point of contact
assert( fabs( n.norm() - 1.0 ) <= 1.0e-10 ); assert( m_r >= 0.0 );
const Vector3s r_world{ - m_r * n };
// Cache the velocity of the collision point on the plane
const Vector3s plane_collision_point_vel{ computePlaneCollisionPointVelocity( q ) };
// For each sample of the friction disk
const unsigned nbodies{ static_cast<unsigned>( q.size() / 12 ) };
for( unsigned friction_sample = 0; friction_sample < unsigned( num_samples ); ++friction_sample )
{
const unsigned cur_col{ start_column + friction_sample };
assert( cur_col < unsigned( D.cols() ) );
// Effect on center of mass
D.insert( 3 * m_sphere_idx + 0, cur_col ) = friction_disk[friction_sample].x();
D.insert( 3 * m_sphere_idx + 1, cur_col ) = friction_disk[friction_sample].y();
D.insert( 3 * m_sphere_idx + 2, cur_col ) = friction_disk[friction_sample].z();
// Effect on orientation
{
const Vector3s ntilde{ r_world.cross( friction_disk[friction_sample] ) };
D.insert( 3 * ( nbodies + m_sphere_idx ) + 0, cur_col ) = ntilde.x();
D.insert( 3 * ( nbodies + m_sphere_idx ) + 1, cur_col ) = ntilde.y();
D.insert( 3 * ( nbodies + m_sphere_idx ) + 2, cur_col ) = ntilde.z();
}
// Relative velocity contribution from kinematic scripting
assert( cur_col < drel.size() );
drel( cur_col ) = - friction_disk[friction_sample].dot( plane_collision_point_vel );
}
}
示例2: isRightHandedOrthoNormal
bool MathUtilities::isRightHandedOrthoNormal( const Vector3s& a, const Vector3s& b, const Vector3s& c, const scalar& tol )
{
// All basis vectors should be unit
if( fabs( a.norm() - 1.0 ) > tol ) { return false; }
if( fabs( b.norm() - 1.0 ) > tol ) { return false; }
if( fabs( c.norm() - 1.0 ) > tol ) { return false; }
// All basis vectors should be mutually orthogonal
if( fabs( a.dot( b ) ) > tol ) { return false; }
if( fabs( a.dot( c ) ) > tol ) { return false; }
if( fabs( b.dot( c ) ) > tol ) { return false; }
// Coordinate system should be right handed
if( ( a.cross( b ) - c ).lpNorm<Eigen::Infinity>() > tol ) { return false; }
return true;
}
示例3: addGradEToTotal
void VortexForce::addGradEToTotal( const VectorXs& x, const VectorXs& v, const VectorXs& m, VectorXs& gradE )
{
assert( x.size() == v.size() );
assert( x.size() == m.size() );
assert( x.size() == gradE.size() );
assert( x.size()%3 == 0 );
assert( m_particles.first >= 0 ); assert( m_particles.first < x.size()/3 );
assert( m_particles.second >= 0 ); assert( m_particles.second < x.size()/3 );
Vector3s rhat = x.segment<3>(3*m_particles.second)-x.segment<3>(3*m_particles.first);
scalar r = rhat.norm();
assert( r != 0.0 );
rhat /= r;
rhat *= m_kbs;
// Rotate rhat 90 degrees clockwise
scalar temp = rhat.x();
rhat.x() = -rhat.y();
rhat.y() = temp;
rhat -= v.segment<3>(3*m_particles.second)-v.segment<3>(3*m_particles.first);
rhat /= r*r;
rhat *= m_kvc;
gradE.segment<3>(3*m_particles.first) -= -rhat;
gradE.segment<3>(3*m_particles.second) += -rhat;
}
示例4: computeContactBasis
void StaticPlaneSphereConstraint::computeContactBasis( const VectorXs& q, const VectorXs& v, MatrixXXsc& basis ) const
{
const Vector3s n{ m_plane.n() };
assert( fabs( n.norm() - 1.0 ) <= 1.0e-6 );
// Compute the relative velocity to use as a direction for the tangent sample
Vector3s s{ computeRelativeVelocity( q, v ) };
// If the relative velocity is zero, any vector will do
if( n.cross( s ).squaredNorm() < 1.0e-9 )
{
s = FrictionUtilities::orthogonalVector( n );
}
// Otherwise project out the component along the normal and normalize the relative velocity
else
{
s = ( s - s.dot( n ) * n ).normalized();
}
// Invert the tangent vector in order to oppose
s *= -1.0;
// Create a second orthogonal sample in the tangent plane
const Vector3s t{ n.cross( s ).normalized() }; // Don't need to normalize but it won't hurt
assert( MathUtilities::isRightHandedOrthoNormal( n, s, t, 1.0e-6 ) );
basis.resize( 3, 3 );
basis.col( 0 ) = n;
basis.col( 1 ) = s;
basis.col( 2 ) = t;
}
示例5: orthogonalVector
// TODO: This doesn't handle <0,0,0>
Vector3s FrictionUtilities::orthogonalVector( const Vector3s& n )
{
assert( fabs( n.norm() - 1.0 ) <= 1.0e-6 ); // TODO: Remove this
// Chose the most orthogonal direction among x, y, z
Vector3s orthog{ fabs(n.x()) <= fabs(n.y()) && fabs(n.x()) <= fabs(n.z()) ? Vector3s::UnitX() : fabs(n.y()) <= fabs(n.z()) ? Vector3s::UnitY() : Vector3s::UnitZ() };
assert( orthog.cross(n).squaredNorm() != 0.0 ); // New vector shouldn't be parallel to the input
// Project out any non-orthogonal component
orthog -= n.dot( orthog ) * n;
assert( orthog.norm() != 0.0 );
return orthog.normalized();
}
示例6: evalgradg
void StaticPlaneSphereConstraint::evalgradg( const VectorXs& q, const int col, SparseMatrixsc& G, const FlowableSystem& fsys ) const
{
assert( col >= 0 );
assert( col < G.cols() );
assert( 3 * m_sphere_idx + 2 < unsigned( G.rows() ) );
const Vector3s n{ m_plane.n() };
assert( fabs( n.norm() - 1.0 ) <= 1.0e-6 );
// MUST BE ADDED GOING DOWN THE COLUMN. DO NOT TOUCH ANOTHER COLUMN.
G.insert( 3 * m_sphere_idx + 0, col ) = n.x();
G.insert( 3 * m_sphere_idx + 1, col ) = n.y();
G.insert( 3 * m_sphere_idx + 2, col ) = n.z();
}
示例7: isActive
bool StaticPlaneSphereConstraint::isActive( const Vector3s& x_plane, const Vector3s& n_plane, const Vector3s& x_sphere, const scalar& r )
{
assert( fabs( n_plane.norm() - 1.0 ) <= 1.0e-6 );
return n_plane.dot( x_sphere - x_plane ) <= r;
}