Skip to content

Instantly share code, notes, and snippets.

@th0ma5w

th0ma5w/curve.clj

Created Nov 7, 2012
Embed
What would you like to do?
Bezier Curve Subdivision Functions
(defn edges [listing]
(loop [accum (list (take 2 listing))
queue (rest listing)]
(if (> (count queue) 1)
(recur
(concat accum
(list (take 2 queue)))
(rest queue))
accum)))
(defn at_step [n0 n1 steps t]
(let [step_size (/ (- n1 n0) steps)]
(+ n0 (* step_size t) )))
(defn n_step [items steps t]
(loop [reduction items]
(if (> (count reduction) 2)
(let [lines (edges reduction)]
(recur (map
(fn [[p1 p2]]
(at_step p1 p2 steps t))
lines)))
(let [[p1 p2] reduction]
(at_step p1 p2 steps t))
)))
(defn n_2d [coords steps t]
(let [dimen #(n_step (map % coords)
steps t)
xx (dimen first)
yy (dimen second)]
(list xx yy)))
(defn n_to [coords steps]
(map
#(n_2d coords steps %)
(range steps)))
(defn n_to_including [coords steps]
(map
#(n_2d coords steps %)
(range (+ steps 1))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment