当前位置: 首页>>代码示例>>C++>>正文


C++ Vector3s::dot方法代码示例

本文整理汇总了C++中Vector3s::dot方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector3s::dot方法的具体用法?C++ Vector3s::dot怎么用?C++ Vector3s::dot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector3s的用法示例。


在下文中一共展示了Vector3s::dot方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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
}
开发者ID:hmazhar,项目名称:scisim,代码行数:34,代码来源:FrictionUtilities.cpp

示例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;
}
开发者ID:hmazhar,项目名称:scisim,代码行数:14,代码来源:MathUtilities.cpp

示例3: computePlaneCollisionPointVelocity

Vector3s StaticPlaneSphereConstraint::computePlaneCollisionPointVelocity( const VectorXs& q ) const
{
  const Vector3s n{ m_plane.n() };

  // Compute the collision point on the plane relative to x
  const Vector3s plane_point{ ( q.segment<3>( 3 * m_sphere_idx ) - m_plane.x() ) - n.dot( q.segment<3>( 3 * m_sphere_idx ) - m_plane.x() ) * n };

  return m_plane.v() + m_plane.omega().cross( plane_point );
}
开发者ID:breannansmith,项目名称:scisim,代码行数:9,代码来源:StaticPlaneSphereConstraint.cpp

示例4: 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();
}
开发者ID:hmazhar,项目名称:scisim,代码行数:12,代码来源:FrictionUtilities.cpp

示例5: computeStapleHalfPlaneActiveSet

void StapleStapleUtilities::computeStapleHalfPlaneActiveSet( const Vector3s& cm, const Matrix33sr& R, const RigidBodyStaple& staple,
                                                             const Vector3s& x0, const Vector3s& n, std::vector<int>& points )
{
  // For each vertex of the staple
  for( int i = 0; i < 4; ++i )
  {
    const Vector3s v{ R * staple.points()[ i ] + cm };
    // Compute the distance from the vertex to the halfplane
    const scalar d{ n.dot( v - x0 ) - staple.r() };
    // If the distance is not positive, we have a collision!
    if( d <= 0.0 )
    {
      points.emplace_back( i );
    }
  }
}
开发者ID:alecjacobson,项目名称:scisim,代码行数:16,代码来源:StapleStapleUtilities.cpp

示例6: closestPointPointSegment

scalar CollisionUtilities::closestPointPointSegment( const Vector3s& c, const Vector3s& a, const Vector3s& b, scalar& t )
{
  const Vector3s ab{ b - a };
  // Project c onto ab, computing parameterized position d(t) = a + t*(b – a)
  t = (c - a).dot( ab ) / ab.dot( ab );
  // If outside segment, clamp t (and therefore d) to the closest endpoint
  if( t < 0.0 )
  {
    t = 0.0;
  }
  if( t > 1.0 )
  {
    t = 1.0;
  }
  // Compute projected position from the clamped t
  const Vector3s& d{ a + t * ab };
  
  return ( c - d ).squaredNorm();
}
开发者ID:hmazhar,项目名称:scisim,代码行数:19,代码来源:CollisionUtilities.cpp

示例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;
}
开发者ID:breannansmith,项目名称:scisim,代码行数:5,代码来源:StaticPlaneSphereConstraint.cpp

示例8: 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 );
}
开发者ID:hmazhar,项目名称:scisim,代码行数:7,代码来源:FrictionUtilities.cpp

示例9: closestPointSegmentSegment

scalar CollisionUtilities::closestPointSegmentSegment( const Vector3s& p1, const Vector3s& q1, const Vector3s& p2, const Vector3s& q2, scalar& s, scalar& t, Vector3s& c1, Vector3s& c2 )
{
  const scalar DIST_EPS{ 1.0e-8 };

  const Vector3s d1{ q1 - p1 }; // Direction vector of segment S1
  const Vector3s d2{ q2 - p2}; // Direction vector of segment S2
  const Vector3s r{ p1 - p2 };
  const scalar a{ d1.dot( d1 ) }; // Squared length of segment S1, always nonnegative
  const scalar e{ d2.dot( d2 ) }; // Squared length of segment S2, always nonnegative
  const scalar f{ d2.dot( r ) };

  // Check if either or both segments degenerate into points
  if( a <= DIST_EPS && e <= DIST_EPS )
  {
    // Both segments degenerate into points
    s = t = 0.0;
    c1 = p1;
    c2 = p2;
    return ( c1 - c2 ).dot( c1 - c2 );
  }
  if( a <= DIST_EPS )
  {
    // First segment degenerates into a point
    s = 0.0;
    t = f / e; // s = 0 => t = (b*s + f) / e = f / e
    t = clamp( t, 0.0, 1.0 );
  }
  else
  {
    const scalar c{ d1.dot( r ) };
    if( e <= DIST_EPS )
    {
      // Second segment degenerates into a point
      t = 0.0;
      s = clamp( -c / a, 0.0, 1.0 ); // t = 0 => s = (b*t - c) / a = -c / a
    }
    else
    {
      // The general nondegenerate case starts here
      const scalar b{ d1.dot( d2 ) };
      const scalar denom{ a * e - b * b }; // Always nonnegative

      // If segments not parallel, compute closest point on L1 to L2, and
      // clamp to segment S1. Else pick arbitrary s (here 0)
      if( denom != 0.0 )
      {
        s = clamp( ( b * f - c * e ) / denom, 0.0, 1.0 );
      }
      else
      {
        s = 0.0;
      }

      // Compute point on L2 closest to S1(s) using
      // t = Dot((P1+D1*s)-P2,D2) / Dot(D2,D2) = (b*s + f) / e
      t = ( b * s + f ) / e;

      // If t in [0,1] done. Else clamp t, recompute s for the new value
      // of t using s = Dot((P2+D2*t)-P1,D1) / Dot(D1,D1)= (t*b - c) / a
      // and clamp s to [0, 1]
      if( t < 0.0 )
      {
        t = 0.0;
        s = clamp( -c / a, 0.0, 1.0 );
      }
      else if( t > 1.0 )
      {
        t = 1.0;
        s = clamp( (b - c) / a, 0.0, 1.0 );
      }
    }
  }

  c1 = p1 + d1 * s;
  c2 = p2 + d2 * t;
  return ( c1 - c2 ).dot( c1 - c2 );
}
开发者ID:hmazhar,项目名称:scisim,代码行数:77,代码来源:CollisionUtilities.cpp


注:本文中的Vector3s::dot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。