calculating distance between a point and a rectangular box (nearest point)

前端 未结 9 1749
广开言路
广开言路 2020-12-13 06:25

is there a easy formula to calculate this? i\'ve been working on some math but i can only find a way to calculate the distance directed to the center of the box, not direct

9条回答
  •  旧时难觅i
    2020-12-13 07:04

    For AABBs:

    Maybe not the best performing, but certainly the simplest method:

    p = your point

    c = centre of the cube

    s = half size of the cube

    r = the point we are looking for

    v = p - c;
    m = max_abs(v);
    r = c + ( v / m * s );
    

提交回复
热议问题