Exemplo n.º 1
0
// line (or segment) in 3D vs plane
bool vsLine3D(const Line3D& line, const Plane3D& plane, Point3D *rpoint = NULL, bool check = true)
{
  // check if line is parallel with plane
  if ( abs( line.vector * plane.normal() ) < epsilon )
    return false;

  Point3D p  = line.point, q = line.point + line.vector;
  float normalLen = plane.normal().length();

  // get dist (and side) from plane for each point
  float distP = plane.Evaluate( p ) / normalLen;
  float distQ = plane.Evaluate( q ) / normalLen;

  // find t
  float t;

  if ( ( distP < 0.f && distQ < 0.f ) || ( distP > 0.f && distQ > 0.f ) )
  {
    if ( check ) return false;

    t = abs( distP ) < abs( distQ )
        ? -abs( distP / ( distP - distQ ) )
        : abs( ( distP + distQ ) / ( distP - distQ ) );
  }

  else
  {
    t = abs( distP ) / ( abs( distP ) + abs( distQ ) );
  }

  if ( rpoint ) *rpoint = p + t * line.vector;

  return true;
}
Exemplo n.º 2
0
// Compute angle between two geometric entities (in radians;  use acos)
float AngleBetween(const Line3D& line, const Plane3D& plane)
{
  Vector3D u = line.vector ^ plane.normal();
  Vector3D v = plane.normal() ^ u;

  float angle = acos( v * line.vector );

  return ( ( angle < 0.f ) ? ( angle + 2.f * M_PI ) : angle );
}
Exemplo n.º 3
0
// Determine if two geometric entities are perpendicular.
bool Perpendicular(const Plane3D& plane1, const Plane3D& plane2)
{
  return ( plane1.normal() * plane2.normal() <= epsilon );
}
Exemplo n.º 4
0
// Determine if two geometric entities are perpendicular.
bool Perpendicular(const Line3D& line, const Plane3D& plane)
{
  return ( abs( line.vector * plane.normal() - 
                line.vector.length() * plane.normal().length() ) <= epsilon );
}
Exemplo n.º 5
0
// Determine if two geometric entities are parallel.
bool Parallel(const Plane3D& plane1, const Plane3D& plane2)
{
  return ( abs( plane1.normal() * plane2.normal() - 
                plane1.normal().length() * plane2.normal().length() ) <= epsilon );
}
Exemplo n.º 6
0
// Determine if two geometric entities are parallel.
bool Parallel(const Line3D& line, const Plane3D& plane)
{
  return ( abs( line.vector * plane.normal() ) <= epsilon );
}
Exemplo n.º 7
0
// Compute angle between two geometric entities (in radians;  use acos)
float AngleBetween(const Plane3D& plane1, const Plane3D& plane2)
{
  return acos( ( plane1.normal() * plane2.normal() ) / 
               ( plane1.normal().length() * plane2.normal().length() ) );
}
Exemplo n.º 8
0
// Return the distance from a point to a plane.
float Distance(const Point3D& point, const Plane3D& plane)
{
  return abs( plane.Evaluate( point ) / plane.normal().length() );
}