Ray.intersectPlane problem

AhmidouAhmidou Posts: 181 ✭✭

Hi, I think i found a small problem in the Ray.intersectPlane:

inline Scalar Ray.intersectPlane(in Vec3 planePoint, in Vec3 planeNormal) {
  Vec3 w;
  Scalar D, N;
  w = this.start - planePoint;
  D = planeNormal.dot(this.direction);
  N = - planeNormal.dot(w);

  if (abs(D) < DIVIDEPRECISION) {
    // segment is parallel to plane
    if (N == 0.0) 
      return -SCALAR_INFINITE; // segment lies in plane
    else
      return -SCALAR_INFINITE; // no intersection
  }
  // they are not parallel
  // compute intersect param
  Scalar sI = N / D;
  if (sI < -PRECISION) {
    return - 1; // no intersection  --->** SHOULD BE -SCALAR_INFINITE**
  }
  return sI;
}

Comments

  • mootzoidmootzoid Fabric Employee Posts: 185 Fabric Employee

    Hi Ahmidou,

    not sure if this is a problem.
    I think the idea behind the different return values is that one can differentiate between the cases "the ray doesn't hit the plane" and "the ray is parallel to the plane". Though I must admit that for the latter case I would return +INF for "ray lies on plane" and "-INF for "ray is parallel to plane but doesn't lie on it".

    Is the "-1" return value causing issues for you?

    Cheers,
    Eric

  • mootzoidmootzoid Fabric Employee Posts: 185 Fabric Employee

    Actually forget what I wrote, sorry.

    Yes, indeed, I think you are right: it should return -INF.
    I filed ticket FE-8848 to look into it.

    Thanks!
    Eric

  • AhmidouAhmidou Posts: 181 ✭✭

    Thanks @mootzoid ,
    on the same note I think it would be nice if we have the bidirectional option like the ray/triangle intersection:

    function Scalar Ray.intersectPlane(in Vec3 planePoint, in Vec3 planeNormal, Boolean bidirectional) {
      Vec3 w;
      Scalar D, N;
      w = this.start - planePoint;
      D = planeNormal.dot(this.direction);
      N = - planeNormal.dot(w);
    
      if (abs(D) < DIVIDEPRECISION) {
        // segment is parallel to plane
        if (N == 0.0) 
          return -SCALAR_INFINITE; // segment lies in plane
        else
          return -SCALAR_INFINITE; // no intersection
      }
      // they are not parallel
      // compute intersect param
      Scalar sI = N / D;
      if (sI < -PRECISION && !bidirectional) {
        return -SCALAR_INFINITE; // no intersection
      }
      return sI;
    
    }
    
    /// Overloaded inline returning the intersection point
    inline Vec3 Ray.intersectPlaneVec3(in Vec3 planePoint, in Vec3 planeNormal, Boolean bidirectional) {
      Scalar factor = this.intersectPlane(planePoint, planeNormal, bidirectional);
      if( factor == -SCALAR_INFINITE )
        return Vec3( -SCALAR_INFINITE );
      return this.pointFromFactor(factor);
    }
    
  • mootzoidmootzoid Fabric Employee Posts: 185 Fabric Employee

    @Ahmidou, yes, I agree, it would be good to have those, too.
    I updated the ticket FE-8848 accordingly!

  • AhmidouAhmidou Posts: 181 ✭✭

    Cool, thanks!!

Sign In or Register to comment.