-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,472 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
/target | ||
/classes | ||
/checkouts | ||
profiles.clj | ||
pom.xml | ||
pom.xml.asc | ||
*.jar | ||
*.class | ||
/lib/ | ||
/classes/ | ||
/target/ | ||
/checkouts/ | ||
.lein-deps-sum | ||
.lein-repl-history | ||
.lein-plugins/ | ||
.lein-failures | ||
.nrepl-port | ||
.cpcache/ | ||
/.lein-* | ||
/.nrepl-port | ||
/public/js | ||
/out | ||
/.repl | ||
*.log | ||
/.env | ||
.shadow-cljs | ||
node_modules | ||
output.* | ||
.cache | ||
.lsp | ||
.clj-kondo | ||
.cpcache | ||
*.cp | ||
.DS_Store | ||
yarn.lock |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{:paths ["src"] | ||
|
||
:deps {thheller/shadow-cljs {:mvn/version "2.11.22"} | ||
applied-science/js-interop {:mvn/version "0.2.7"} | ||
binaryage/devtools {:mvn/version "1.0.0"} | ||
nrepl/nrepl {:mvn/version "0.8.3"}}} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"devDependencies": { | ||
"shadow-cljs": "^2.12.22" | ||
}, | ||
"dependencies": { | ||
"three": "^0.133.0" | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{:deps true | ||
|
||
:builds {:code {:target :npm-module | ||
:output-dir "public/js" | ||
:entries [mathree.core]}} | ||
; | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
(ns mathree.angle | ||
(:require | ||
[goog.math :as gmath])) | ||
|
||
|
||
;; 1. degrees | ||
|
||
(defn standard-angle-in-degrees | ||
";; standardAngle (angle) → number | ||
Normalizes an angle to be in range [0-360). Angles outside this range will be normalized to be the equivalent angle with that range." | ||
[angle] | ||
(gmath/standardAngle angle)) | ||
|
||
(defn to-degrees | ||
";; toDegrees (angleRadians) → number" | ||
[angle-in-radians] | ||
(gmath/toDegrees angle-in-radians)) | ||
|
||
(defn parse-degrees | ||
" convert angle in degrees to parsed format of degrees, minutes and seconds" | ||
[angle-in-degrees] | ||
(let [degree (int angle-in-degrees) | ||
rem-degree (rem angle-in-degrees 1) | ||
minute (int (* 60 rem-degree)) | ||
rem-minute (rem (* 60 rem-degree) 1) | ||
second (* rem-minute 60)] | ||
{:degrees degree | ||
:minutes minute | ||
:seconds second})) | ||
|
||
(defn calculate-degrees | ||
" convert parsed format to angle in degrees" | ||
[parsed-degrees] | ||
(let [{:keys [degrees minutes seconds]} parsed-degrees] | ||
(+ degrees | ||
(/ minutes 60) | ||
(/ seconds 3600)))) | ||
|
||
|
||
;; 2. radians | ||
|
||
(defn standard-angle-in-radians | ||
";; standardAngleInRadians (angle) → number | ||
Normalizes an angle to be in range [0-2*PI). Angles outside this range will be normalized to be the equivalent angle with that range." | ||
[angle-in-radians] | ||
(gmath/standardAngleInRadians angle-in-radians)) | ||
|
||
(defn to-radians | ||
";; toRadians (angleDegrees) → number" | ||
[angle-in-degree] | ||
(gmath/toRadians angle-in-degree)) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
(ns mathree.arithmetic | ||
(:require | ||
[goog.math :as gmath])) | ||
|
||
|
||
(defn almost-equal? | ||
" nearlyEquals (a, b, opt_tolerance) → boolean | ||
opt_tolerance number= | ||
Optional tolerance range. Defaults to 0.000001. If specified, should be greater than 0." | ||
([a b] | ||
(gmath/nearlyEquals a b)) | ||
([a b opt_tolerance] | ||
(gmath/nearlyEquals a b opt_tolerance))) | ||
|
||
|
||
(defn almost-all-equal? | ||
"almost-equal? for every items" | ||
([a b] | ||
(every? (fn [n] (almost-equal? n 0.0)) (map - a b))) | ||
([a b opt_tolerance] | ||
(every? (fn [n] (almost-equal? n 0.0 opt_tolerance)) (map - a b)))) | ||
|
||
|
||
(defn rand-sign [] | ||
(if (< (rand) 0.5) -1 1)) | ||
|
||
(defn log | ||
([n] | ||
(Math/log n)) | ||
([base n] | ||
(/ (Math/log n) (Math/log base)))) | ||
|
||
(defn pow | ||
([x] | ||
(Math/exp x)) | ||
([base x] | ||
(Math/pow base x))) | ||
|
||
(defn exp [n] | ||
(Math/exp n)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(ns mathree.core | ||
(:require | ||
[mathree.angle] | ||
[mathree.arithmetic] | ||
[mathree.euler] | ||
[mathree.math-utils] | ||
[mathree.matrix3] | ||
[mathree.matrix4] | ||
[mathree.quaternion] | ||
[mathree.spherical] | ||
[mathree.vector3])) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
(ns mathree.euler | ||
(:require | ||
[applied-science.js-interop :as j] | ||
["three" :as three])) | ||
|
||
(defprotocol IEuler | ||
(clone' [r]) | ||
(equals [r1 r2]) | ||
(reorder [r order]) | ||
) | ||
|
||
|
||
(extend-type three/Euler | ||
Object | ||
(toString [v] (str (vec v))) | ||
|
||
ISeqable | ||
(-seq [v] (list (.-x v) (.-y v) (.-z v) (.-order v))) | ||
|
||
ISeq | ||
(-first [v] (.-x v)) | ||
(-rest [v] (list (.-y v) (.-z v) (.-order v))) | ||
|
||
ILookup | ||
(-lookup | ||
([v k] (-lookup v k nil)) | ||
([v k not-found] | ||
(case k | ||
0 (.-x v) | ||
1 (.-y v) | ||
2 (.-z v) | ||
3 (.-order v) | ||
:x (.-x v) | ||
:y (.-y v) | ||
:z (.-z v) | ||
:order (.-order v) | ||
not-found))) | ||
|
||
IEuler | ||
|
||
(clone' [v1] (j/call v1 :clone)) | ||
(equals [v1 v2] | ||
(j/call v1 :equals v2)) | ||
|
||
(reorder [e order] | ||
(let [ec (clone' e)] | ||
(j/call ec :reorder order))) | ||
|
||
;; | ||
) | ||
|
||
|
||
(defn euler | ||
([] (three/Euler.)) | ||
([order] (three/Euler. 0 0 0 order)) | ||
([x y z] (three/Euler. x y z)) | ||
([x y z order] (three/Euler. x y z order))) | ||
|
||
(defn from-seq | ||
([sq] | ||
(from-seq sq "XYZ")) | ||
([sq order] | ||
(let [[x y z] sq] | ||
(euler x y z order)))) | ||
|
||
(defn from-quaternion | ||
([q] | ||
(from-quaternion q "XYZ")) | ||
([q order] | ||
(let [e1 (euler order)] | ||
(j/call e1 :setFromQuaternion q order)))) | ||
|
||
|
||
(comment | ||
|
||
(def e1 (euler 1 2 3)) | ||
(vec e1) | ||
(vec (reorder e1 :XZY)) | ||
|
||
(j/call e1 :toVector3) | ||
|
||
) |
Oops, something went wrong.