0

リアルタイム衝突検出の本には、次の式があります。

// 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);

だから私は現在それを持っています

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

フロートとして t が必要です。私は何をしますか?私は glm などで、演算子を使用するだけであることを知っています。

GLKVector3 t の長さで必要なものが得られますか?

4

1 に答える 1

1

p.dは原点から平面までの距離であり、したがってベクトルではなく、スカラー、つまり a であると仮定し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;
于 2013-05-16T13:14:12.790 に答える