我有一个由8个顶点组成的框,可以在任何方向上缩放或旋转,因此每次变换时我都将变换矩阵应用于顶点,我在中心处具有X,Y和Z的中心,大小和方向,我检查盒子内是否有3D点?
答案 0 :(得分:3)
如果您有:
vec3 center; // Center of the box.
vec3 dx, dy, dz; // X,Y, and Z directions, normalized.
vec3 half; // Box size in each dimension, divided by 2.
vec3 point; // Point to test.
然后测试很简单:
vec3 d = point - center;
bool inside = abs(dot(d, dx)) <= half.x &&
abs(dot(d, dy)) <= half.y &&
abs(dot(d, dz)) <= half.z;
点积的主要属性是
X⋅Y == |X|⋅|Y|⋅cos(angle_formed_by_X_and_Y)
。
如果对Y
进行了归一化,则X⋅Y
本质上将为您提供X
到Y
上的投影长度(如果{{1 }}和X
是钝的)。有了投影长度后,您只需要将其绝对值与框的相应半延伸范围进行比较即可。