Objective c ObjectiveC中求交的方法

Objective c ObjectiveC中求交的方法,objective-c,opengl-es,glkit,Objective C,Opengl Es,Glkit,实时碰撞检测手册具有以下等式 // 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.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的长度不能满足我的需要吗?

我假设
p.d
是平面到原点的距离,因此它不是一个向量,而是一个标量,即
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到1之间的T值should@Andrew:您的输入数据是什么?这个公式似乎是正确的。我应该提交一个新问题吗?@Andrew:这要看情况了。如果你认为我已经回答了你的问题,而你有一个不同的问题,那么发布一个新的问题如果你认为我的答案可能有问题,那么我们可以在这里尝试解决。