WB_GeometryOp3D.getIntersection3D(WB_Ray, WB_Plane) not robust if ray's direction and plane's normal are orthogonal #54

Closed
peteroupc opened this Issue Feb 12, 2017 · 3 comments

Projects

None yet

2 participants

@peteroupc
peteroupc commented Feb 12, 2017 edited

The getIntersection3D method can return a non-finite "t" value (infinity or NaN) if the input ray's direction and the plane's normal are orthogonal to each other. This is because the dot product that results will cause a division by 0. This is illustrated in the following code:

public static void main(String[] args){
    WB_Ray r;
    WB_Plane p;
    WB_Coord ab;
    double t;
    // A ray that starts at (1,0,0) and points toward the positive Y axis
    r=new WB_Ray(1,0,0,0,1,0);
    // A plane that contains (0,0,0) and whose normal points toward the positive X axis
    p=new WB_Plane(0,0,0,1,0,0);
    ab = r.getDirection();
    t = (p.d() - p.getNormal().dot(r.getOrigin())) / p.getNormal().dot(ab);
    System.out.println("t is "+t); // -Infinity
    r=new WB_Ray(-1,0,0,0,1,0);
    // A plane that contains (0,0,0) and whose normal toward the positive Y axis
    p=new WB_Plane(0,0,0,1,0,0);
    ab = r.getDirection();
    t = (p.d() - p.getNormal().dot(r.getOrigin())) / p.getNormal().dot(ab);
    System.out.println("t is "+t); // Infinity
    r=new WB_Ray(0,0,0,0,1,0);
    // A plane that contains (0,0,0) and whose normal toward the positive Y axis
    p=new WB_Plane(0,0,0,1,0,0);
    ab = r.getDirection();
    t = (p.d() - p.getNormal().dot(r.getOrigin())) / p.getNormal().dot(ab);
    System.out.println("t is "+t); // NaN
}

The fix is easy if the ray's origin does not lie on the plane: simply return no intersection if the denominator is 0. However, I don't know whether the method should register an intersection if the ray's origin does lie on the plane (for example, if the origins of both the ray and the plane are the same). If it should, that should be handled specially so that the method returns a t of 0.

@peteroupc peteroupc changed the title from WB_GeometryOp3D.getIntersection3D(WB_Ray, WB_Plane) not robust if ray's direction and plane's normal are orthogonal. to WB_GeometryOp3D.getIntersection3D(WB_Ray, WB_Plane) not robust if ray's direction and plane's normal are orthogonal Feb 12, 2017
@wblut
Owner
wblut commented Feb 12, 2017

Indeed...
Intersection code has generally not been extensively tested. This helps.

Thank you,

Frederik

@wblut wblut closed this Feb 12, 2017
@peteroupc

I see that based on your revised code, you have decided that rays that lie on the plane don't intersect that plane, is that correct? This is just to clarify.

@wblut
Owner
wblut commented Feb 12, 2017

Yes, this was already the case for the line-plane intersection. I extended this to rays and segments.
I know that for certain concave meshes this could in pathological cases lead to miss-identification of inside-outside tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment