Skip to content

Commit

Permalink
More geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
kephale committed Nov 23, 2014
1 parent d023d9d commit 3617c15
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ docs
*.csv
*.jnlp
*.ser
.project

29 changes: 29 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>brevis</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>ccw.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>ccw.leiningen.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>ccw.leiningen.nature</nature>
<nature>ccw.nature</nature>
</natures>
</projectDescription>
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject brevis "0.9.66"
(defproject brevis "0.9.67"
:description "A Functional Scientific and Artificial Life Simulator"
:url "http://brevis.us"
:license {:name "Apache License v2"
Expand Down Expand Up @@ -43,7 +43,7 @@
[com.fifesoft/rsyntaxtextarea "2.5.3"]
]
;:javac-options ["-target" "1.6" "-source" "1.6" "-Xlint:-options"]
:aot [#_clojure.main brevis.ui.core]; brevis.example.swarm]
;:aot [#_clojure.main brevis.ui.core]; brevis.example.swarm]
:main ^:skip-aot brevis.Launcher
;:manifest {"SplashScreen-Image" "brevis_splash.gif"}
;:warn-on-reflection true
Expand Down
49 changes: 29 additions & 20 deletions src/brevis/geometry/intersection.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,33 @@
[brevis.shape box sphere cone cylinder]))

(defn cylinder-contains?-maker
"Make a cylinder-contains? function for a specific cylinder.
"Make a cylinder-contains? function for a specific cylinder.
Takes 2 points and 2 radii. Currently only uses the first radius"
[^Vector3f A ^Vector3f B
Ra Rb]
(let [^Vector3f AB (sub-vec3 B A)
^Vector3f BA (sub-vec3 A B)
ab (length-vec3 AB)
ab2 (java.lang.Math/pow ab 2)
r Ra
r2 (* r r)]
(fn [point]
(let [AP (sub-vec3 point A)
BP (sub-vec3 point B)]
(when (and (>= (dot-vec3 AP AB) 0)
(>= (dot-vec3 BP BA) 0))
(let [ap-dot-ab (dot-vec3 AP AB)
t (/ ap-dot-ab ab2)]
(let [^Vector3f Pcore (add-vec3 A (mul-vec3 AB t))
^Vector3f Dcore (sub-vec3 point Pcore)
d-core (length-vec3 Dcore)]
(< d-core r))))))))
[^Vector3f A ^Vector3f B
Ra Rb]
(let [^Vector3f AB (sub-vec3 B A)
^Vector3f BA (sub-vec3 A B)
ab (length-vec3 AB)
ab2 (java.lang.Math/pow ab 2)
r Ra
r2 (* r r)]
(fn [point]
(let [AP (sub-vec3 point A)
BP (sub-vec3 point B)]
(when (and (>= (dot-vec3 AP AB) 0)
(>= (dot-vec3 BP BA) 0))
(let [ap-dot-ab (dot-vec3 AP AB)
t (/ ap-dot-ab ab2)]
(let [^Vector3f Pcore (add-vec3 A (mul-vec3 AB t))
^Vector3f Dcore (sub-vec3 point Pcore)
d-core (length-vec3 Dcore)]
(< d-core r))))))))

(defn sphere-contains?-maker
"Make a sphere-contains? function for a specific sphere.
Takes 1 point and 1 radius."
[^Vector3f A r]
(fn [point]
(<= (length-vec3 (sub-vec3 point A)) r)))


9 changes: 9 additions & 0 deletions test/brevis/test/geometry/intersection.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@
(is (cylinder-contains? (vec3 5 0 0)))
))

(deftest test-sphere-contains?-maker
(let [sphere-contains? (sphere-contains?-maker (vec3 0 0 0) 5)]
(is (sphere-contains? (vec3 0 0 0)))
(is (not (sphere-contains? (vec3 6 0 0))))
(is (sphere-contains? (vec3 5 0 0)))
(is (not (sphere-contains? (vec3 0 0 6))))
(is (sphere-contains? (vec3 0 0 5)))
))

0 comments on commit 3617c15

Please sign in to comment.