如何检查该点是否在3d三角形内?

时间:2019-05-25 14:14:52

标签: java

我碰到一块布和一个被分成三角形的立方体碰撞

第一个首先测试点是否在平面内,然后测试是否在三角形内,然后应用动能定律计算新速度,然后将其发送到该点,并返回到原来的位置

void resolvePtoTriCollision(PVectorTriangle traingle, Particle p) {
    PVector N = calcTriangleNormal(traingle.a, traingle.b, traingle.c).normalize();
    PVector AP = p.position.copy().sub(traingle.a);

    float d = AP.dot(N);
    if (abs(d) <= 5 ) { // point is on the tri's plane
      if ( isPointInsideTri(traingle.a, traingle.b, traingle.c, p.position) ) {

    PVector Vtriangle1 = new PVector(); 
        PVector Vtriangle2 = p.speed.copy(); 

        float M2 = mass;
        float M1 = 1.7;
        p.resolveCollision(newV);
      }
    }
  }

boolean isPointInsideTri(PVector a, PVector b, PVector c, PVector p) {
    float abcArea = triArea(a, b, c);
      float pabArea = triArea(p, a, b);
      float pbcArea = triArea(p, b, c);
      float pacArea = triArea(p, a, c);
      return abs(abcArea - (pabArea + pbcArea + pacArea)) <= 0.5 ? true : false;
  }

我的问题是,如果abs(abcArea-(pabArea + pbcArea + pacArea))<= 0.5等于4000,则关系遵循isPointInsideTri。关系变为正确且小于跨过错误的界限。谁能告诉我为什么,这是真的吗?

0 个答案:

没有答案