ФлеймФорумПрограммирование

проверка точки в OBB.

#0
(Правка: 13:16) 13:00, 2 ноя 2025

нашел такой пример .
как я понял Vector d = p - b.c; поворачивают , чтобы перевести его в локальные координаты OBB.
и это выйдет как проверка точки в ААВВох.

struct OBB { //15 floats
Point c; // OBB center point
Vector u[3]; // Local x-, y-, and z-axes. this rot matrix3x3
float e[3]; // Positive halfwidth extents of OBB along each axis
};

void ClosestPtPointOBB(Point p, OBB b, Point &q) {
Vector d = p - b.c;
// Start result at center of box; make steps from there
q = b.c;
// For each OBB axis...
for (int i = 0; i < 3; i++) {
// ...project d onto that axis to get the distance
// along the axis of d from the box center
float dist = Dot(d, b.u[i]);
// If distance farther than the box extents, clamp to the box
if (dist > b.e[i]) dist = b.e[i];
if (dist < -b.e[i]) dist = -b.e[i];
// Step that distance along the axis to get world coordinate
q += dist * b.u[i]; } 
}

я так понимаю можно переписать if так и без q += dist * b.u;

if (dist < b.e[i] && dist > -b.e[i]) return true;
return false;

чтобы знать точка в oriented bounding boxe или нет.

#1
16:25, 2 ноя 2025
bool IsPointInOBB(const Point& p, const OBB& b) {
    Vector d = p - b.c;
    for (int i = 0; i < 3; i++) 
    {
        if (fabsf(Dot(d, b.u[i])) > b.e[i]) { return false;}
    }
    return true;
}

ФлеймФорумПрограммирование