Created
November 7, 2012 22:57
-
-
Save th0ma5w/4035151 to your computer and use it in GitHub Desktop.
Bezier Curve Subdivision Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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