简体   繁体   中英

java line segment-triangle intersection 3d

i have been working on this for a long time now and think im close to a solution. it is what i least wanted but it has come to this. so what i need to do is take 2 points and see if the line they make intersect a triangle and also get the point where they intersect that triangle. i gave up on the math and thought j3d might help me. heres what i have with j3d

    @SuppressWarnings({ "deprecation"})
public static boolean intersectTrianglePoint(Vector3f p, Vector3f q, Vector3f a, Vector3f b, Vector3f c) {
    boolean isinside = false;
    //try {
    tri[0] = new Point3d(a.x, a.y, a.z);
    tri[1] = new Point3d(b.x, b.y, b.z);
    tri[2] = new Point3d(c.x, c.y, c.z);

    Point3d p1 = new Point3d(p.x, p.y, p.z);
    Point3d q1 = new Point3d(q.x, q.y, q.z);

    PickSegment line = new PickSegment(p1, q1);

    double[] dist = null;
    dist[0] = 1;

    isinside = Intersect.segmentAndTriangle(line, tri, 0, dist);

    System.out.println(dist[0]);
    //} catch (Exception e) {}

    return isinside;
}

but i am getting this error

Exception in thread "main" java.lang.NullPointerException
at com.gopro2027.lwjgl.Triangles.intersectTrianglePoint(Triangles.java:187)
at com.gopro2027.lwjgl.Camera.updateVector(Camera.java:96)
at com.gopro2027.lwjgl.Camera.update(Camera.java:48)
at com.gopro2027.lwjgl.Game.update(Game.java:97)
at com.gopro2027.lwjgl.Game.main(Game.java:60)

and line 187 is tri[0] = new Point3d(ax, ay, az); but if someone can give me a mathod that can get the intersection and test for it without j3d i would love them. i have tried many things i found online and no luck. please help. thanks

Are you sure that all your parameters are !null?

As for the math, you want ray-plane intersection. http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM