Exemple #1
0
optional<Vector3> Plane::intersectLine( const Line3& line, Vector3& target ) {

  auto direction = line.delta();
  auto denominator = normal.dot( direction );

  if ( denominator == 0 ) {
    // line is coplanar, return origin
    if( distanceToPoint( line.start ) == 0 ) {

      target.copy( line.start );
      return target;

    }

    // Unsure if this is the correct method to handle this case.
    return nullptr;

  }

  auto t = - ( line.start.dot( normal ) + constant ) / denominator;

  if( t < 0 || t > 1 ) {

    return nullptr;

  }

  return target.copy( direction ).multiplyScalar( t ).add( line.start );
}
Exemple #2
0
bool Plane::intersectLine(const Line3& line, Vector3* result) const
{
    const Vector3 direction = line.delta();

    float denominator = normal().dot( direction );

    if ( denominator == 0 ) {
        // line is coplanar, return origin
        if ( distanceToPoint( line.start() ) == 0 ) {
            if (result) {
                result->copy( line.start() );
            }
            return true;
        }

        // Unsure if this is the correct method to handle this case.
        return false;
    }

    float t = - ( line.start().dot( normal() ) + constant() ) / denominator;

    if( (t < 0 || t > 1) ) {
        return false;
    }

    if (result)
        result->copy( direction ).multiplyScalar( t ).add( line.start() );

    return true;
}