コード例 #1
0
ファイル: geomlib-advanced.cpp プロジェクト: yxrkt/DigiPen
// 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;
}
コード例 #2
0
ファイル: geomlib-advanced.cpp プロジェクト: yxrkt/DigiPen
// 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() );
}