Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tweaked a few parameters.

  • Loading branch information...
commit 19b8a6cc15d7ec12c8a5e483539752ac3c5903a9 1 parent 1c09d01
unclebob authored
View
12 src/orbit/world.clj
@@ -14,7 +14,7 @@
(defstruct controls :magnification :center)
(defn size-by-mass [{m :mass}]
- (+ 3 m)
+ (+ 3 (Math/sqrt m))
)
(defn color-by-mass [{m :mass}]
@@ -127,15 +127,17 @@
(defn random-velocity [p sun]
(let [
sp (:position sun)
+ sd (position/distance p sp)
+ v (Math/sqrt (/ 1 sd))
direction (vector/rotate90 (vector/unit (vector/subtract p sp)))
]
- (vector/scale direction (+ (rand 0.3) 0.3))
+ (vector/scale direction (+ (rand 0.01) (* v 13.5)))
)
)
(defn random-position [sun-position]
(let [
- r (+ (rand 150) 80)
+ r (+ (rand 300) 30)
theta (rand (* 2 Math/PI))
]
(position/add sun-position (position/make (* r (Math/cos theta)) (* r (Math/sin theta))))
@@ -155,9 +157,9 @@
(defn create-world []
(let [
v0 (vector/make)
- sun (object/make center 30 (vector/make 0 0) v0 "sun")
+ sun (object/make center 150 (vector/make 0 0) v0 "sun")
]
- (loop [world [sun] n 300]
+ (loop [world [sun] n 500]
(if (zero? n)
world
(recur (conj world (random-object sun n)) (dec n))
View
18 src/physics/object.clj
@@ -81,11 +81,23 @@
)
)
+(defn center-of-mass [
+ {p1 :position, m1 :mass}
+ {p2 :position, m2 :mass}]
+ (let [
+ s (/ m1 (+ m1 m2))
+ uv (vector/unit (vector/subtract p2 p1))
+ d (vector/scale uv s)
+ ]
+ (position/add p1 d)
+ )
+ )
+
(defn merge [
- {n1 :name, p1 :position, m1 :mass, v1 :velocity f1 :force}
- {n2 :name, p2 :position, m2 :mass, v2 :velocity f2 :force}]
+ {n1 :name, m1 :mass, v1 :velocity f1 :force, :as o1}
+ {n2 :name, m2 :mass, v2 :velocity f2 :force, :as o2}]
(let [
- p (position/average p1 p2)
+ p (center-of-mass o1 o2)
m (+ m1 m2)
mv1 (vector/scale v1 m1)
mv2 (vector/scale v2 m2)
View
2  src/physics/object_test.clj
@@ -127,7 +127,7 @@
om (object/merge o1 o2)
]
(is (= "o2.o1" (:name om)))
- (is (= (position/make 1 1.5) (:position om)))
+ (is (= (position/make 1 1.4) (:position om)))
(is (= 5 (:mass om)))
(is (= (vector/make -1/5 0) (:velocity om)))
(is (= (vector/make 2 2) (:force om)))
Please sign in to comment.
Something went wrong with that request. Please try again.