Created
August 28, 2014 02:42
-
-
Save TeMPOraL/6d80cb9243f8b2b02fcb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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