1
this 기사를 사용하여 삼각형 - 삼각형 탐지 알고리즘을 연구 중입니다. 이 코드를 작성했지만 불행히도 삼각형 사이에 교차가있을 때이 메서드는 false를 반환합니다.삼각형 - 삼각형 교차 감지
private boolean checkTriangleCollision(Triangle triangle1, Triangle triangle2) {
Vector3f n1 = getN(triangle1);
Vector3f n2 = getN(triangle2);
Vector3f v = null;
v = Vector3f.cross(n1, n2, v);
Vector3f p = new Vector3f();
float pxy = n1.z * triangle1.vertex1.position.z * n1.x * n1.y;
float px = n1.z * triangle1.vertex1.position.z * n1.x * n1.y * triangle1.vertex1.position.y;
float py = n1.z * triangle1.vertex1.position.z * n1.x * triangle1.vertex1.position.x * n1.y;
float p0 = n1.z * triangle1.vertex1.position.z * n1.x * triangle1.vertex1.position.x * n1.y * triangle1.vertex1.position.y;
p.x = (p0/(px/pxy))/pxy;
p.y = (p0/(py/pxy))/pxy;
Vector3f x = null;
x = Vector3f.add(p, v, x);
Vector3f xq1 = null;
xq1 = Vector3f.sub(x, triangle1.vertex1.position, xq1);
float i1 = Vector3f.dot(xq1, n1);
Vector3f xq2 = null;
xq2 = Vector3f.sub(x, triangle2.vertex1.position, xq2);
float i2 = Vector3f.dot(xq2, n2);
if (i1 == 0 && i2 == 0) {
return true;
}
return false;
}
private Vector3f getN(Triangle triangle) {
Vector3f vn1 = null;
vn1 = Vector3f.sub(triangle.vertex2.position, triangle.vertex1.position, vn1);
Vector3f vn2 = null;
vn2 = Vector3f.sub(triangle.vertex3.position, triangle.vertex1.position, vn2);
Vector3f n = null;
n = Vector3f.cross(vn1, vn2, n);
return n;
}
나는 이유를 정확하게 모르겠지만, 내가 문제가 p
를 계산에 있다고 생각한다. 그렇다면 어떻게하면이 방정식을 코드로 풀 수 있을까요?
N1·(P0-Q1) = 0
and
N2·(P0-R1) = 0
나를 위해 해결 방정식을 할 수있는 도서관이있다? – Qualphey