Skip to content

Instantly share code, notes, and snippets.

@astanin
Created May 31, 2012 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astanin/2844300 to your computer and use it in GitHub Desktop.
Save astanin/2844300 to your computer and use it in GitHub Desktop.
incanter.contrib.vecmath.naive
(ns ^{:doc "Naive implementation of vector products."}
incanter.contrib.vecmath.naive
(:use [incanter.core :only (matrix mmult)]))
(defn dot
"Dot product between two vectors."
[u v]
(apply + (map * u v)))
(defn cross
"Cross product between two vectors.
Implementation:
http://en.wikipedia.org/wiki/Cross_product#Conversion_to_matrix_multiplication
"
[u v]
(let [[a1 a2 a3] u
m (matrix [[0 (- a3) a2]
[a3 0 (- a1)]
[(- a2) a1 0]])]
(mmult m (matrix v))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment