age-of-sail/src/age_of_sail/vec2.clj

32 lines
405 B
Clojure

(ns age-of-sail.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)))