-
Notifications
You must be signed in to change notification settings - Fork 16
/
geom.clj
52 lines (42 loc) · 866 Bytes
/
geom.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(ns dali.geom
(:require [dali.math :as math]))
(defn v+
"Add two vectors."
[[x1 y1] [x2 y2]]
[(+ x1 x2) (+ y1 y2)])
(defn v-
"Subtract the second vector from the first or negate a
vector (single arity)."
([[x y]]
[(- x) (- y)])
([[x1 y1] [x2 y2]]
[(- x1 x2) (- y1 y2)]))
(defn v-scale
"Scale vector."
[[x y] a]
[(* x a) (* y a)])
(defn v-half
"Scale vector to half its magnitude."
[v]
(v-scale v 0.5))
(defn distance-squared
[[x1 y1] [x2 y2]]
(+ (* (- x1 x2) (- x1 x2))
(* (- y1 y2) (- y1 y2))))
(defn distance
[[x1 y1] [x2 y2]]
(math/sqrt
(+ (* (- x1 x2) (- x1 x2))
(* (- y1 y2) (- y1 y2)))))
(defn slope
[[x1 y1] [x2 y2]]
(/ (- y2 y1) (- x2 x1)))
(defn angle
[[x1 y1] [x2 y2]]
(math/polar-angle [(- x2 x1) (- y2 y1)]))
(defn ->svg-angle
[x]
(- x))
(defn ->standard-angle
[x]
(- x))