2013-05-16 5 views
0

실시간 충돌 탐지 북은 다음 방정식을가집니다.ObjectiveC의 컴퓨팅 교차점

// Compute the t value for the directed line ab intersecting the plane 
Vector ab = b - a; 
t = (p.d - Dot(p.n, a))/Dot(p.n, ab); 

그래서 내가 가진 내가 float로서 t을 필요로 현재

GLKVector3 abD = GLKVector3Subtract(b, a); 

GLKVector3 planeD = GLKVector3Make(1.0f, 0.0f, 1.0f); 
GLKVector3 planeN = GLKVector3Make(0.0f, 1.0f, 0.0f); 

//t = (p.d - Dot(p.n, a))/Dot(p.n, ab); 

float dotPbA = GLKVector3DotProduct(planeN, a); 
float dotPbAbD = GLKVector3DotProduct(planeN, abD); 

GLKVector3 nominator = GLKVector3SubtractScalar(planeD, dotPbA); 

GLKVector3 t = GLKVector3DivideScalar(nom, dotPbAbD); 
// float t = nominator/dotPbA 

로 그. 나는 무엇을해야합니까? 나는 glm 또는 그와 같은 것이 작동 자만 사용한다는 것을 알고 있습니다.

GLKVector3의 길이가 내가 필요한 것을 줄 수 있습니까?

답변

1

p.d 원점으로부터 평면까지의 거리이므로 즉 float벡터하지만 스칼라 아닌 것으로 가정한다.

그럼 당신은 내가 생각하는 평면의 방정식으로 그것을했다 .. AH는 float로서 계획이었습니다

float planeD = ... 
GLKVector3 planeN = ... 

GLKVector3 abD = GLKVector3Subtract(b, a); 
float dotPbA = GLKVector3DotProduct(planeN, a); 
float dotPbAbD = GLKVector3DotProduct(planeN, abD); 

float t = (planeD - dotPbA)/dotPbAbD; 
+0

계산할 수 있습니다. – Andrew

+0

그 코드는 실행되지만, 0 일 때 1의 값을 얻지 못합니다. – Andrew

+0

@Andrew : 입력 데이터가 무엇입니까? 수식이 맞는 것 같습니다. –