Skip to content

Instantly share code, notes, and snippets.

@TeMPOraL
Created August 28, 2014 02:42
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 TeMPOraL/6d80cb9243f8b2b02fcb to your computer and use it in GitHub Desktop.
Save TeMPOraL/6d80cb9243f8b2b02fcb to your computer and use it in GitHub Desktop.
(defun ⋅ (a b)
"Compute dot product of two vectors."
(assert (= (length a)
(length b))
(a b)
"Cannot compute a dot product of ~S and ~S - lengths of vectors differ." a b)
(reduce #'+ (map 'vector #'* a b)))
(defun × (a b)
"Compute cross product of two 3D vectors."
(assert (and (vector-3d-p a)
(vector-3d-p b))
(a b)
"Cannot compute a cross product of ~S and ~S." a b)
(make-vector-3d (- (* (vec-y a) (vec-z b))
(* (vec-y b) (vec-z a)))
(- (* (vec-z a) (vec-x b))
(* (vec-z b) (vec-x a)))
(- (* (vec-x a) (vec-y b))
(* (vec-x b) (vec-y a)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment