本文整理汇总了C++中Vector3s::cross方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector3s::cross方法的具体用法?C++ Vector3s::cross怎么用?C++ Vector3s::cross使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector3s
的用法示例。
在下文中一共展示了Vector3s::cross方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: evalH
void StaticPlaneSphereConstraint::evalH( const VectorXs& q, const MatrixXXsc& basis, MatrixXXsc& H0, MatrixXXsc& H1 ) const
{
assert( H0.rows() == 3 );
assert( H0.cols() == 6 );
assert( H1.rows() == 3 );
assert( H1.cols() == 6 );
// Grab the contact normal
const Vector3s n{ basis.col( 0 ) };
// Grab the tangent basis
const Vector3s s{ basis.col( 1 ) };
const Vector3s t{ basis.col( 2 ) };
assert( MathUtilities::isRightHandedOrthoNormal( n, s, t, 1.0e-6 ) );
// Compute the displacement from the center of mass to the point of contact
assert( m_r >= 0.0 );
const Vector3s r_world{ - m_r * n };
H0.block<1,3>(0,0) = n;
H0.block<1,3>(0,3).setZero();
H0.block<1,3>(1,0) = s;
H0.block<1,3>(1,3) = r_world.cross( s );
H0.block<1,3>(2,0) = t;
H0.block<1,3>(2,3) = r_world.cross( t );
}
示例3: 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 );
}
}
示例4: computeGeneralizedFrictionGivenTangentSample
void StaticPlaneSphereConstraint::computeGeneralizedFrictionGivenTangentSample( const VectorXs& q, const VectorXs& t, const unsigned column, SparseMatrixsc& D ) const
{
assert( t.size() == 3 );
assert( column < unsigned( D.cols() ) );
assert( q.size() % 12 == 0 );
assert( fabs( t.norm() - 1.0 ) <= 1.0e-6 );
assert( fabs( m_plane.n().dot( t ) ) <= 1.0e-6 );
// Effect on center of mass
D.insert( 3 * m_sphere_idx + 0, column ) = t.x();
D.insert( 3 * m_sphere_idx + 1, column ) = t.y();
D.insert( 3 * m_sphere_idx + 2, column ) = t.z();
// Effect on orientation
{
const unsigned nbodies{ static_cast<unsigned>( q.size() / 12 ) };
// Compute the displacement from the center of mass to the point of contact
assert( fabs( m_plane.n().norm() - 1.0 ) <= 1.0e-10 );
assert( m_r >= 0.0 );
const Vector3s r_world{ - m_r * m_plane.n() };
const Vector3s ntilde{ r_world.cross( Eigen::Map<const Vector3s>( t.data() ) ) };
D.insert( 3 * ( nbodies + m_sphere_idx ) + 0, column ) = ntilde.x();
D.insert( 3 * ( nbodies + m_sphere_idx ) + 1, column ) = ntilde.y();
D.insert( 3 * ( nbodies + m_sphere_idx ) + 2, column ) = ntilde.z();
}
}
示例5: generateOrthogonalVectors
void FrictionUtilities::generateOrthogonalVectors( const Vector3s& n, std::vector<Vector3s>& vectors, const Vector3s& suggested_tangent )
{
if( vectors.empty() )
{
return;
}
assert( ( suggested_tangent.cross( n ) ).squaredNorm() != 0.0 );
// Make sure the first vector is orthogonal to n and unit length
vectors[0] = ( suggested_tangent - n.dot( suggested_tangent ) * n ).normalized();
assert( fabs( vectors[0].norm() - 1.0 ) <= 1.0e-10 );
assert( fabs( n.dot( vectors[0] ) ) <= 1.0e-10 );
// Generate the remaining vectors by rotating the first vector about n
const scalar dtheta{ 2.0 * MathDefines::PI<scalar>() / scalar( vectors.size() ) };
for( std::vector<Vector3s>::size_type i = 1; i < vectors.size(); ++i )
{
vectors[i] = Eigen::AngleAxis<scalar>{ i * dtheta, n } * vectors[0];
assert( fabs( vectors[i].norm() - 1.0 ) <= 1.0e-10 );
assert( fabs( n.dot( vectors[i] ) ) <= 1.0e-10 );
}
#ifndef NDEBUG
if( vectors.size() == 1 )
{
return;
}
// Check that the angle between each vector is the one we expect
for( std::vector<Vector3s>::size_type i = 0; i < vectors.size(); ++i )
{
assert( fabs( angleBetweenVectors( vectors[i], vectors[( i + 1 ) % vectors.size()] ) - dtheta ) < 1.0e-6 );
}
#endif
}
示例6: 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;
}
示例7: angleBetweenVectors
// Unsigned angle
scalar angleBetweenVectors( const Vector3s& v0, const Vector3s& v1 )
{
const scalar s = v0.cross( v1 ).norm();
const scalar c = v0.dot( v1 );
return atan2( s, c );
}