Oblivious
Is Kredit to Team!!
- Local time
- Tomorrow 3:25 AM
- Joined
- Apr 30, 2008
- Messages
- 1,266
- Location
- Purgatory with the cool kids
In the programming language of course.
Just starting to learn this wonderful language, and was wondering if there was anyone else here who was experienced in this language to help me evaluate my style. I was learning C before this, so this might affect how I think about the problem.
Oh, it's working correctly (I think) at the very least for 3-dimensional vectors. I can't seem to find online calculators that evaluate higher dimensions then that.
(Is there anyone who knows the proper way to evaluate 7-dimensional vectors? Is it the same as 3-dimensional?)
The code below generalizes the following formula:
c = a Χ b
c0 = a1·b2 - a2·b1
c1 = -(b2·a0 - b0·a2)
c2 = a0·b1 - a1·b0
(I know its weird to have 0 value subscripts in math, but it matches array indexing, so it is clearer.)
It was an interesting problem
Just starting to learn this wonderful language, and was wondering if there was anyone else here who was experienced in this language to help me evaluate my style. I was learning C before this, so this might affect how I think about the problem.
Oh, it's working correctly (I think) at the very least for 3-dimensional vectors. I can't seem to find online calculators that evaluate higher dimensions then that.
(Is there anyone who knows the proper way to evaluate 7-dimensional vectors? Is it the same as 3-dimensional?)
The code below generalizes the following formula:
c = a Χ b
c0 = a1·b2 - a2·b1
c1 = -(b2·a0 - b0·a2)
c2 = a0·b1 - a1·b0
(I know its weird to have 0 value subscripts in math, but it matches array indexing, so it is clearer.)
Code:
[SIZE=2](defun cross-product (a b)
(let ((sub-1 1)) ;Subscripts refer to starting positions
(let ((sub-2 2)) ;These starting values correspond to first c0 value
(let ((result-vector(make-array (length a))))
(dotimes (i (length result-vector))
(setf (svref result-vector i) (- (* (svref a sub-1) (svref b sub-2))
(* (svref a sub-2) (svref b sub-1))
)) ;Main computation
(setf sub-1(move sub-1 (length a)))
(setf sub-2(move sub-2 (length a))))result-vector))))
(defun move (sub size) ;Subscript increment and reset
(if (= sub (1- size)) 0 (1+ sub)))
(setf *A* #(1 2 3))[/SIZE] [SIZE=2]
(setf *B* #(6 7 8))
(print(cross-product *A* *B*))[/SIZE]