java线段 - 三角形交叉点3d

时间:2014-10-15 01:26:07

标签: java geometry line intersection

我已经在这方面工作了很长时间,并认为我接近解决方案。这是我最不想要的,但它已经到了这个地步。所以我需要做的是取2个点,看看它们所做的线是否与三角形相交,并得到它们与该三角形相交的点。我放弃了数学,并认为j3d可能会帮助我。继承人我对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;
}

但我收到此错误

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)

和第187行是     tri [0] = new Point3d(a.x,a.y,a.z); 但是如果有人可以给我一个可以得到交集的方法并且在没有j3d的情况下测试它我会喜欢它们。我尝试过很多在网上找到的东西而且没有运气。请帮忙。感谢

1 个答案:

答案 0 :(得分:0)