[lisplab-cvs] r160 - in trunk: . src/matrix

Jørn Inge Vestgården jivestgarden at common-lisp.net
Thu May 13 14:18:21 UTC 2010


Author: jivestgarden
Date: Thu May 13 10:18:21 2010
New Revision: 160

Log:
vector functions

Added:
   trunk/src/matrix/level2-vector.lisp
Modified:
   trunk/lisplab.asd
   trunk/package.lisp
   trunk/src/matrix/level2-interface.lisp

Modified: trunk/lisplab.asd
==============================================================================
--- trunk/lisplab.asd	(original)
+++ trunk/lisplab.asd	Thu May 13 10:18:21 2010
@@ -104,6 +104,7 @@
       ; (:file "level2-array-functions")
       (:file "level2-view")
       (:file "level2-list")
+      (:file "level2-vector")
       ))
 
    ;;

Modified: trunk/package.lisp
==============================================================================
--- trunk/package.lisp	(original)
+++ trunk/package.lisp	Thu May 13 10:18:21 2010
@@ -203,6 +203,9 @@
    "CIRC-SHIFT"
    "PAD-SHIFT"
    "MREVERSE"
+   "VDOT"
+   "VNORM"
+   "VCROSS"
 
    ;; Matrix level 3
    ;; IO

Modified: trunk/src/matrix/level2-interface.lisp
==============================================================================
--- trunk/src/matrix/level2-interface.lisp	(original)
+++ trunk/src/matrix/level2-interface.lisp	Thu May 13 10:18:21 2010
@@ -154,4 +154,15 @@
   (:documentation "Shifts the matrix and pads results"))
 
 (defgeneric mreverse (m)
-  (:documentation "Reverts elements of matrix or vector. Similar to cl:reverse"))
\ No newline at end of file
+  (:documentation "Reverts elements of matrix or vector. Similar to cl:reverse"))
+
+;; Some vector functions 
+
+(defgeneric vcross (a b)
+  (:documentation "Cross product. Must be a vecotors of length 3"))
+
+(defgeneric vdot (a b)
+  (:documentation "Dot product of vectors"))
+
+(defgeneric vnorm (a)
+  (:documentation "The vector norm"))

Added: trunk/src/matrix/level2-vector.lisp
==============================================================================
--- (empty file)
+++ trunk/src/matrix/level2-vector.lisp	Thu May 13 10:18:21 2010
@@ -0,0 +1,41 @@
+;;; Lisplab, level2-vector.lisp
+;;; A small number of vector functions, general and specialized
+
+;;; Copyright (C) 2009 Joern Inge Vestgaarden
+;;;
+;;; This program is free software; you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 2 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License along
+;;; with this program; if not, write to the Free Software Foundation, Inc.,
+;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+(in-package :lisplab)
+
+;;; For general matrices
+
+(defmethod vdot ((a matrix-base) (b matrix-base))
+  (msum (.* a b)))
+
+(defmethod vcross :before ((a matrix-base) (b matrix-base))
+  (assert (= (size a) (size b) 3)))
+
+(defmethod vcross ((a matrix-base) (b matrix-base))
+  (let ((out (mcreate a)))
+    (setf (vref out 0) (.- (.* (vref a 1) (vref b 2))
+			   (.* (vref a 2) (vref b 1)))
+	  (vref out 1) (.- (.* (vref a 2) (vref b 0))
+			   (.* (vref a 0) (vref b 2)))
+	  (vref out 2) (.- (.* (vref a 0) (vref b 1))
+			   (.* (vref a 1) (vref b 0))))
+    out))
+
+(defmethod vnorm ((a matrix-base))
+  (.sqrt (vdot (.conj a) a)))
\ No newline at end of file




More information about the lisplab-cvs mailing list