Posted By

weilawei on 05/07/12


Tagged

box axis aligned bounding


Versions (?)

Axis-Aligned Bounding Box


 / Published in: Clojure
 

make-aabb [a-point b-point] [a-point b-point]: Creates a 3D Axis-Aligned Bounding Box (AABB).

aabb-contains? [a-box a-point]: Returns true if a 3D AABB contains a given point.

  1. (ns aabb)
  2.  
  3. (defn ^{
  4. :doc "Creates a 3D Axis-Aligned Bounding Box (AABB)."
  5. } make-aabb [a-point b-point] [a-point b-point])
  6.  
  7. (defn ^{
  8. :doc "Returns true if a 3D AABB contains a given point.
  9.  
  10. > A point U belongs to the axis-aligned bounding box, if U[i] >= A[i] and
  11. > U[u] <= B[i], assuming A[i] < B[i], for i is an element of {x, y, z}.
  12.  
  13. - Vlastimil Havran, Heuristic Ray Shooting Algorithms (Revision 1.1, 8 May 2001), page 3"
  14. } aabb-contains? [a-box a-point]
  15. (let [[a b] a-box
  16. axes (eval `(map vector ~a ~b ~a-point))]
  17. (loop [[an-axe & more] axes]
  18. (let [[a-coord b-coord a-point-coord] an-axe]
  19. (if (or (< a-point-coord a-coord) (> a-point-coord b-coord))
  20. false
  21. (if (empty? more)
  22. true
  23. (recur more)))))))

Report this snippet  

You need to login to post a comment.