Skip to content

Instantly share code, notes, and snippets.

@bahostetterlewis
Last active August 29, 2015 14:20
Show Gist options
  • Save bahostetterlewis/46cc761545472f6e195a to your computer and use it in GitHub Desktop.
Save bahostetterlewis/46cc761545472f6e195a to your computer and use it in GitHub Desktop.
Simple Physics in Clojure
(defn point-builder [start stop step]
(if (< start stop)
(into (vector start) (point-builder (+ start step) stop step))
(vector start)
)
)
(defn half [n] (/ n 2) )
(defn linspace [size n]
(point-builder (- (half size)) (half size) (/ size (dec n)))
)
(def dimentionalize
(partial map (fn [x] (vector x 0 0)))
)
(defn point-charge [charge pos]
{:charge charge, :pos pos}
)
(defn charged-points [size n charge]
(map (partial point-charge (/ charge n)) (linspace size n))
)
(defn unit-distance [charge_point point pos]
(- (get charge_point pos) (get point pos))
)
(defn r [p1 p2]
(map (partial unit-distance p1 p2) [0 1 2])
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment