32 lines
403 B
Clojure
32 lines
403 B
Clojure
|
(ns space-sim.vec2
|
||
|
(:require [clojure.math :as math]))
|
||
|
|
||
|
(defn zero
|
||
|
[]
|
||
|
[0. 0.])
|
||
|
|
||
|
(defn add
|
||
|
[v1 v2]
|
||
|
(mapv + v1 v2))
|
||
|
|
||
|
(defn scale
|
||
|
[v & scalars]
|
||
|
(mapv #(* (apply * scalars) %) v))
|
||
|
|
||
|
(defn len2
|
||
|
[v]
|
||
|
(apply + (map #(* % %) v)))
|
||
|
|
||
|
(defn len
|
||
|
[v]
|
||
|
(math/sqrt (len2 v)))
|
||
|
|
||
|
(defn normalize
|
||
|
[v]
|
||
|
(let [length (len v)]
|
||
|
(mapv #(/ % length) v)))
|
||
|
|
||
|
(defn dot
|
||
|
[v1 v2]
|
||
|
(apply + (map * v1 v2)))
|