public boolean isInTwoVectors(Vector3 pos1, Vector3 pos2, Vector3 check) {
int minX = Math.min(pos1.x, pos2.x);
int maxX = Math.max(pos1.x, pos2.x);
int minY = Math.min(pos1.y, pos2.y);
int maxY = Math.max(pos1.y, pos2.y);
int minZ = Math.min(pos1.z, pos2.z);
int maxZ = Math.max(pos1.z, pos2.z);
return check.x >= minX && check.x <= maxX && check.y >= minY && check.y <= maxY
&& check.z >= minZ && check.z <= maxZ;
}
简单地说,检查所有 x、y 和 z 边界,看向量是否在其中。作为记录,在您的示例中,给定向量将不在范围内,因为它的 z 值超出范围(在 [43,100] 之外)。在这种情况下(不关心 z 值),您只需检查 x 和 y 值,如下所示:
public boolean isInTwoVectorsXY(Vector3 pos1, Vector3 pos2, Vector3 check) {
int minX = Math.min(pos1.x, pos2.x);
int maxX = Math.max(pos1.x, pos2.x);
int minY = Math.min(pos1.y, pos2.y);
int maxY = Math.max(pos1.y, pos2.y);
return check.x >= minX && check.x <= maxX && check.y >= minY && check.y <= maxY;
}
或者,也许您实际上是指这样或这样的东西?