I'm not sure what to do here, my program hangs at the following
defmethod.  all my brackets seem to be balanced and I'm not receiving
any errors about undefined symbols.  This sample prints 2 but never
gets to 3, (my poor man's debugging).  This code is for the collision
detection is a physics engine in clojure, I imagine it might be hard
to understand(I'm hoping somebody could simply give some reasons why a
program would just hang like this) , but shape is a concave polygon,
plane is a plane(really just a line in my implementation), and :points
is a counter-clockwise list of points.  The search function basically
searches for the one or two points on the shape which create the
extremes of the projection interval.  The result is a structure that
consists of the edges of the interval and the points on those edges.
I've also redefined the math functions to work with vectors and
matrices.

(defstruct projection-struct :start :stop :start-points :stop-points)
(println 1)
(defmulti projection #(:type (meta %)))
(println 2)
(defmethod projection :polygon [shape plane]
           (let [search (fn [condition]
                          (loop [accum 0 step (inc (int  (/ (count
(:points shape)) 2))) from -1]
                            (condp condition (dot plane (accum
(:points shape)))

                              (dot plane ((mod (+ accum step) (count
(:points shape))) (:points shape)))
                              (if (= from (+ accum step))
                                [(dot plane ((mod (+ accum step)
(count (:points shape))) (:points shape)))
                                 [(from (:points shape)) (accum
(:points shape))]]
                                (recur (mod (+ accum step) (count
(:points shape))) (inc (int (/ step 2))) accum))

                              (dot plane ((mod (- accum step) (count
(:points shape))) (:points shape)))
                              (if (= from (- accum step))
                                [(dot plane ((mod (- accum step)
(count (:points shape))) (:points shape)))
                                 [(from (:points shape)) (accum
(:points shape))]]
                                (recur (mod (- accum step) (count
(:points shape))) (inc (int (/ step 2))) accum))

                              [(dot plane (accum (:points shape)))
                               [(accum (:points shape))]])))
                 front (search <=)
                 back (search >=)]
             (struct projection-struct (first front) (first back)
(second front) (second back))))
(println 3)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to