Last active
August 29, 2015 14:20
-
-
Save bahostetterlewis/46cc761545472f6e195a to your computer and use it in GitHub Desktop.
Simple Physics in Clojure
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 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