Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #910 > unrolled thread
| Started by | Luser droog <mijoryx@yahoo.com> |
|---|---|
| First post | 2012-09-02 14:13 -0500 |
| Last post | 2012-09-05 23:41 -0700 |
| Articles | 9 — 4 participants |
Back to article view | Back to comp.lang.postscript
Dot Product and Cross Product Luser droog <mijoryx@yahoo.com> - 2012-09-02 14:13 -0500
Re: Dot Product and Cross Product tlvp <mPiOsUcB.EtLlLvEp@att.net> - 2012-09-02 23:51 -0400
Re: Dot Product and Cross Product Luser droog <mijoryx@yahoo.com> - 2012-09-03 09:53 -0500
Re: Dot Product and Cross Product tlvp <mPiOsUcB.EtLlLvEp@att.net> - 2012-09-03 19:16 -0400
Re: Dot Product and Cross Product Luser droog <mijoryx@yahoo.com> - 2012-09-03 22:46 -0500
Matrix Multiplication and Transpose; Dot Product and Cross Product Luser droog <mijoryx@yahoo.com> - 2012-09-04 09:43 -0500
Re: Matrix Multiplication and Transpose; Dot Product and Cross Product luser- -droog <mijoryx@yahoo.com> - 2012-09-11 12:09 -0700
Re: Dot Product and Cross Product tlvp <mPiOsUcB.EtLlLvEp@att.net> - 2012-09-04 23:13 -0400
Re: Dot Product and Cross Product gernot.hoffmann@hs-emden-leer.de - 2012-09-05 23:41 -0700
| From | Luser droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2012-09-02 14:13 -0500 |
| Subject | Dot Product and Cross Product |
| Message-ID | <k20b63$r66$1@adenine.netfront.net> |
Dot product works for any two vectors of the same dimension.
Cross product only defined for dimension 3.
552(1)02:11 PM:ps 0> cat mat.ps
%!
/.error where { pop /signalerror { .error } def } if
/dot { % u v
2 copy length exch length ne {
/dot cvx /invalidresult signalerror
} if
% u v
0 % u v sum
0 1 3 index length 1 sub { % u v sum i
3 index 1 index get exch % u v sum u_i i
3 index exch get % u v sum u_i v_i
mul add % u v sum
} for % u v sum
3 1 roll pop pop % sum
} bind def
% [ x1 x2 x3 ] [ y1 y2 y3 ] cross [ x2*y3-y2*x3 x3*y1-x1*y3 x1*y2-x2*y1 ]
/cross { % u v
dup length 3 ne
2 index length 3 ne or {
/cross cvx /invalidresult signalerror
} if
% u v
exch aload pop 4 3 roll aload pop % x1 x2 x3 y1 y2 y3
[
5 index 2 index mul % ... [ x2*y3
3 index 6 index mul sub % ... [ x2*y3-y2*x3
5 index 5 index mul % ... [ x2*y3-y2*x3 x3*y1
8 index 4 index mul sub % ... [ x2*y3-y2*x3 x3*y1-x1*y3
8 index 5 index mul % ... [ x2*y3-y2*x3 x3*y1-x1*y3 x1*y2
8 index 7 index mul sub % ... [ x2*y3-y2*x3 x3*y1-x1*y3 x1*y2-x2*y1
]
7 1 roll 6 { pop } repeat
} bind def
--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---
[toc] | [next] | [standalone]
| From | tlvp <mPiOsUcB.EtLlLvEp@att.net> |
|---|---|
| Date | 2012-09-02 23:51 -0400 |
| Message-ID | <dgmeqh2zvrg6$.1t7xv64a7obxx.dlg@40tude.net> |
| In reply to | #910 |
On Sun, 02 Sep 2012 14:13:58 -0500, Luser droog wrote: > Dot product works for any two vectors of the same dimension. Agreed. And delivers a *number* as value. > Cross product only defined for dimension 3. I respectfully disagree, though it's true that most elementary vector algebra texts over-simplify things just that way. Please forgive this very long, highly tangential, digression. That said: Cross product works, in fact, for any (n-1) vectors all of the same dimension n -- so long as n > 1. And delivers another vector of the same dimension -- perpendicular to each of the (n-1) given vectors, of non-zero length if the original (n-1) vectors are "linearly independent", and of zero length otherwise. The order the "(n-1) vectors all of the same dimension n" are given in matters. The one axiomatic principle governing all there is to know about this: for every n vectors of dimension n, the numerical value of the dot product X(v_1, ... v_(n-1)) • v_n of the cross product X(v_1, ... v_(n-1)) of the first (n-1) of the vectors with the last one v_n is given by the numerical value of the determinant det(v_1, ... v_n) of the matrix whose n rows (if the vectors given are all row vectors) or columns (if instead they're all column vectors) are exactly the originally given n vectors of dimension n: X(v_1, ... v_(n-1)) • v_n = det(v_1, ... v_n) . (And from that you can see: 1) that in the special case n = 3 this is just the traditional 3D cross product; and 2) that the requirement n > 1, posed at the outset, is essential: for when n = 1 the LHS makes very little sense (if any), and when n < 1 neither side makes very much sense at all :-) .) Should further detail be called for, I stand ready to deliver. But I won't overburden you now :-) . Cheers, -- tlvp -- Avant de repondre, jeter la poubelle, SVP.
[toc] | [prev] | [next] | [standalone]
| From | Luser droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2012-09-03 09:53 -0500 |
| Message-ID | <k22g9l$254v$1@adenine.netfront.net> |
| In reply to | #912 |
tlvp wrote: > On Sun, 02 Sep 2012 14:13:58 -0500, Luser droog wrote: > >> Dot product works for any two vectors of the same dimension. > > Agreed. And delivers a *number* as value. > >> Cross product only defined for dimension 3. > > I respectfully disagree, though it's true that most elementary vector > algebra texts over-simplify things just that way. > > Please forgive this very long, highly tangential, digression. That said: > > Cross product works, in fact, for any (n-1) vectors all of the same > dimension n -- so long as n > 1. And delivers another vector of the same > dimension -- perpendicular to each of the (n-1) given vectors, of non-zero > length if the original (n-1) vectors are "linearly independent", and of > zero length otherwise. The order the "(n-1) vectors all of the same > dimension n" are given in matters. > > The one axiomatic principle governing all there is to know about this: > > for every n vectors of dimension n, the numerical value of the dot product > X(v_1, ... v_(n-1)) ? v_n of the cross product X(v_1, ... v_(n-1)) of the > first (n-1) of the vectors with the last one v_n is given by the numerical > value of the determinant det(v_1, ... v_n) of the matrix whose n rows (if > the vectors given are all row vectors) or columns (if instead they're all > column vectors) are exactly the originally given n vectors of dimension n: > > X(v_1, ... v_(n-1)) ? v_n = det(v_1, ... v_n) . > > (And from that you can see: 1) that in the special case n = 3 this is just > the traditional 3D cross product; and 2) that the requirement n > 1, posed > at the outset, is essential: for when n = 1 the LHS makes very little > sense (if any), and when n < 1 neither side makes very much sense at all > :-) .) > > Should further detail be called for, I stand ready to deliver. But I won't > overburden you now :-) . Cheers, -- tlvp I meant merely that this code only works for 3D vectors. :) The generalization looks like a pain to program. (Hmm, maybe it wouldn't be so bad, but a lot of juggling). So for 4D vectors, you need 3 to take a cross product? --- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---
[toc] | [prev] | [next] | [standalone]
| From | tlvp <mPiOsUcB.EtLlLvEp@att.net> |
|---|---|
| Date | 2012-09-03 19:16 -0400 |
| Message-ID | <pwk49b4rilv4.808xh6sxozf.dlg@40tude.net> |
| In reply to | #913 |
On Mon, 03 Sep 2012 09:53:38 -0500, Luser droog wrote: > tlvp wrote: > >> On Sun, 02 Sep 2012 14:13:58 -0500, Luser droog wrote: >> >>> Dot product works for any two vectors of the same dimension. >> >> Agreed. And delivers a *number* as value. >> >>> Cross product only defined for dimension 3. >> >> I respectfully disagree, though it's true that most elementary vector >> algebra texts over-simplify things just that way. >> >> Please forgive this very long, highly tangential, digression. That said: >> >> Cross product works, in fact, for any (n-1) vectors all of the same >> dimension n -- so long as n > 1. And delivers another vector of the same >> dimension -- perpendicular to each of the (n-1) given vectors, of non-zero >> length if the original (n-1) vectors are "linearly independent", and of >> zero length otherwise. The order the "(n-1) vectors all of the same >> dimension n" are given in matters. >> >> The one axiomatic principle governing all there is to know about this: >> >> for every n vectors of dimension n, the numerical value of the dot product >> X(v_1, ... v_(n-1)) ? v_n of the cross product X(v_1, ... v_(n-1)) of the >> first (n-1) of the vectors with the last one v_n is given by the numerical >> value of the determinant det(v_1, ... v_n) of the matrix whose n rows (if >> the vectors given are all row vectors) or columns (if instead they're all >> column vectors) are exactly the originally given n vectors of dimension n: >> >> X(v_1, ... v_(n-1)) ? v_n = det(v_1, ... v_n) . >> >> (And from that you can see: 1) that in the special case n = 3 this is just >> the traditional 3D cross product; and 2) that the requirement n > 1, posed >> at the outset, is essential: for when n = 1 the LHS makes very little >> sense (if any), and when n < 1 neither side makes very much sense at all >> :-) .) >> >> Should further detail be called for, I stand ready to deliver. But I won't >> overburden you now :-) . Cheers, -- tlvp > > I meant merely that this code only works for 3D vectors. :) > The generalization looks like a pain to program. (Hmm, maybe > it wouldn't be so bad, but a lot of juggling). > > So for 4D vectors, you need 3 to take a cross product? Exactly. And you learn what the four numerical coordinates of the cross product X(v_1, ... v_3) (of the three 4-vectors v_1, v_2, and v_3) are by applying the dot product formula above four times, with n=4, viz., X(v_1, ... v_3) [dot] v_4 = det(v_1, ... v_4) for each of the possible choices of the four elementary coordinate-axis unit vectors (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 0, 1), and (0, 0, 0, 1) in the role of v_4 (quite analogous w/ how it works for n=3). Cheers, -- tlvp [PS: apologies that my OP UTF-8 "bullet" (trying to stand in for a "dot product" glyph) got itself transmogrified into a stupid "?" instead.] -- Avant de repondre, jeter la poubelle, SVP.
[toc] | [prev] | [next] | [standalone]
| From | Luser droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2012-09-03 22:46 -0500 |
| Message-ID | <k23tjg$qdl$1@adenine.netfront.net> |
| In reply to | #916 |
tlvp wrote: > On Mon, 03 Sep 2012 09:53:38 -0500, Luser droog wrote: > >> tlvp wrote: >> >>> On Sun, 02 Sep 2012 14:13:58 -0500, Luser droog wrote: >>> >>>> Dot product works for any two vectors of the same dimension. >>> >>> Agreed. And delivers a *number* as value. >>> >>>> Cross product only defined for dimension 3. >>> >>> I respectfully disagree, though it's true that most elementary vector >>> algebra texts over-simplify things just that way. >>> >>> Please forgive this very long, highly tangential, digression. That said: >>> >>> Cross product works, in fact, for any (n-1) vectors all of the same >>> dimension n -- so long as n > 1. And delivers another vector of the same >>> dimension -- perpendicular to each of the (n-1) given vectors, of >>> non-zero length if the original (n-1) vectors are "linearly >>> independent", and of zero length otherwise. The order the "(n-1) vectors >>> all of the same >>> dimension n" are given in matters. >>> >>> The one axiomatic principle governing all there is to know about this: >>> >>> for every n vectors of dimension n, the numerical value of the dot >>> product X(v_1, ... v_(n-1)) ? v_n of the cross product X(v_1, ... >>> v_(n-1)) of the first (n-1) of the vectors with the last one v_n is >>> given by the numerical value of the determinant det(v_1, ... v_n) of the >>> matrix whose n rows (if the vectors given are all row vectors) or >>> columns (if instead they're all column vectors) are exactly the >>> originally given n vectors of dimension n: >>> >>> X(v_1, ... v_(n-1)) ? v_n = det(v_1, ... v_n) . >>> >>> (And from that you can see: 1) that in the special case n = 3 this is >>> just the traditional 3D cross product; and 2) that the requirement n > >>> 1, posed at the outset, is essential: for when n = 1 the LHS makes very >>> little sense (if any), and when n < 1 neither side makes very much sense >>> at all >>> :-) .) >>> >>> Should further detail be called for, I stand ready to deliver. But I >>> won't overburden you now :-) . Cheers, -- tlvp >> >> I meant merely that this code only works for 3D vectors. :) >> The generalization looks like a pain to program. (Hmm, maybe >> it wouldn't be so bad, but a lot of juggling). >> >> So for 4D vectors, you need 3 to take a cross product? > > Exactly. And you learn what the four numerical coordinates of the cross > product X(v_1, ... v_3) (of the three 4-vectors v_1, v_2, and v_3) are by > applying the dot product formula above four times, with n=4, viz., > > X(v_1, ... v_3) [dot] v_4 = det(v_1, ... v_4) > > for each of the possible choices of the four elementary coordinate-axis > unit vectors (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 0, 1), and (0, 0, 0, 1) in > the role of v_4 (quite analogous w/ how it works for n=3). > > Cheers, -- tlvp > > [PS: apologies that my OP UTF-8 "bullet" (trying to stand in for a "dot > product" glyph) got itself transmogrified into a stupid "?" instead.] No worries. And for 2D you only need 1 vector. (x,y) -> (-y,x) I'm still having difficulty with the "geometric significance" of the 4D cross-product. It's sort of the the "fourth wall" from the point of view of a 5D observer, right? --- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---
[toc] | [prev] | [next] | [standalone]
| From | Luser droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2012-09-04 09:43 -0500 |
| Subject | Matrix Multiplication and Transpose; Dot Product and Cross Product |
| Message-ID | <k2543a$28p9$1@adenine.netfront.net> |
| In reply to | #918 |
Haven't generalized the cross-product yet. But here's matrices.
I tried to make it a little forgiving by auto-promoting vectors
to 1D matrices and auto-transposing to find conformance.
Not sure how useful this will actually be. To actually use this
in a program, I think you pretty much have to *know* what
dimensions are going in and out.
571(1)09:37 AM:ps 0> cat mat.ps
%!
%mat.ps
%Matrix and Vector math routines
/.error where { pop /signalerror { .error } def } if
/dot { % u v
2 copy length exch length ne {
/dot cvx /undefinedresult signalerror
} if
% u v
0 % u v sum
0 1 3 index length 1 sub { % u v sum i
3 index 1 index get exch % u v sum u_i i
3 index exch get % u v sum u_i v_i
mul add % u v sum
} for % u v sum
3 1 roll pop pop % sum
} bind def
% [ x1 x2 x3 ] [ y1 y2 y3 ] cross [ x2*y3-y2*x3 x3*y1-x1*y3 x1*y2-x2*y1 ]
/cross { % u v
dup length 3 ne
2 index length 3 ne or {
/cross cvx /undefinedresult signalerror
} if
% u v
exch aload pop 4 3 roll aload pop % x1 x2 x3 y1 y2 y3
[
5 index 2 index mul % ... [ x2*y3
3 index 6 index mul sub % ... [ x2*y3-y2*x3
5 index 5 index mul % ... [ x2*y3-y2*x3 x3*y1
8 index 4 index mul sub % ... [ x2*y3-y2*x3 x3*y1-x1*y3
8 index 5 index mul % ... [ x2*y3-y2*x3 x3*y1-x1*y3 x1*y2
8 index 7 index mul sub % ... [ x2*y3-y2*x3 x3*y1-x1*y3 x1*y2-x2*y1
]
7 1 roll 6 { pop } repeat
} bind def
/transpose { STATICDICT begin
/A exch def
/M A length def
/N A 0 get length def
[
0 1 N 1 sub { /n exch def
[
0 1 M 1 sub { /m exch def
A m get n get
} for
]
} for
]
end } dup 0 6 dict put def
/matmul { STATICDICT begin
/B exch def
B 0 get type /arraytype ne { /B [B] def } if
/A exch def
A 0 get type /arraytype ne { /A [A] def } if
/Q B length def
/R B 0 get length def
/P A length def
Q A 0 get length ne {
/A A transpose def
/P A length def
Q A 0 get length ne {
A B end /matmul cvx /undefinedresult signalerror
} if
} if
[
0 1 R 1 sub { /r exch def
[
0 1 P 1 sub { /p exch def
0
0 1 Q 1 sub { /q exch def
A p get q get
B q get r get mul
add
} for
} for
]
} for
]
end } dup 0 10 dict put def
% Here's a trick. Hashtables (ie. dictionaries) are fastest
% when less than half-full.
--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---
[toc] | [prev] | [next] | [standalone]
| From | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2012-09-11 12:09 -0700 |
| Subject | Re: Matrix Multiplication and Transpose; Dot Product and Cross Product |
| Message-ID | <3abef488-dd67-4872-a751-d2512974c670@googlegroups.com> |
| In reply to | #924 |
While trying to do a 3D l-system, I found a pretty
serious bug in my matrix multiplication routine.
So here's the corrected mat.ps for posterity.
%!
%mat.ps
%Matrix and Vector math routines
/.error where { pop /signalerror { .error } def } if
/dot { % u v
2 copy length exch length ne {
/dot cvx /undefinedresult signalerror
} if
% u v
0 % u v sum
0 1 3 index length 1 sub { % u v sum i
3 index 1 index get exch % u v sum u_i i
3 index exch get % u v sum u_i v_i
mul add % u v sum
} for % u v sum
3 1 roll pop pop % sum
} bind def
% [ x1 x2 x3 ] [ y1 y2 y3 ] cross [ x2*y3-y2*x3 x3*y1-x1*y3 x1*y2-x2*y1 ]
/cross { % u v
dup length 3 ne
2 index length 3 ne or {
/cross cvx /undefinedresult signalerror
} if
% u v
exch aload pop 4 3 roll aload pop % x1 x2 x3 y1 y2 y3
[
5 index 2 index mul % ... [ x2*y3
3 index 6 index mul sub % ... [ x2*y3-y2*x3
5 index 5 index mul % ... [ x2*y3-y2*x3 x3*y1
8 index 4 index mul sub % ... [ x2*y3-y2*x3 x3*y1-x1*y3
8 index 5 index mul % ... [ x2*y3-y2*x3 x3*y1-x1*y3 x1*y2
8 index 7 index mul sub % ... [ x2*y3-y2*x3 x3*y1-x1*y3 x1*y2-x2*y1
]
7 1 roll 6 { pop } repeat
} bind def
/transpose { STATICDICT begin
/A exch def
/M A length def
/N A 0 get length def
[
0 1 N 1 sub { /n exch def
[
0 1 M 1 sub { /m exch def
A m get n get
} for
]
} for
]
end } dup 0 6 dict put def
/matmul { STATICDICT begin
/B exch def
B 0 get type /arraytype ne { /B [B] def } if
/A exch def
A 0 get type /arraytype ne { /A [A] def } if
/Q B length def
/R B 0 get length def
/P A length def
Q A 0 get length ne {
/A A transpose def
/P A length def
Q A 0 get length ne {
A B end /matmul cvx /undefinedresult signalerror
} if
} if
[
0 1 P 1 sub { /p exch def
[
0 1 R 1 sub { /r exch def
0
0 1 Q 1 sub { /q exch def
A p get q get
B q get r get mul
add
} for
} for
]
} for
]
end } dup 0 10 dict put def
%u v {operator} vop u(op)v
%apply a binary operator to corresponding elements
%in two vectors producing a third vector as result
/vop { 1 dict begin
/op exch def
2 copy length exch length ne {
/vop cvx end /undefinedresult signalerror
} if
[ 3 1 roll % [ u v
0 1 2 index length 1 sub { % [ ... u v i
3 copy exch pop get % u v i u_i
3 copy pop get % u v i u_i v_i
op exch pop % u v u_i(op)v_i
3 1 roll % u_i(op)v_i u v
} for % [ ... u v
pop pop ]
end } def
%length of a vector
/mag { 0 exch { dup mul add } forall } def
[toc] | [prev] | [next] | [standalone]
| From | tlvp <mPiOsUcB.EtLlLvEp@att.net> |
|---|---|
| Date | 2012-09-04 23:13 -0400 |
| Message-ID | <1uydxdwzowc8q.1kl7f2iqtin1i$.dlg@40tude.net> |
| In reply to | #918 |
On Mon, 03 Sep 2012 22:46:48 -0500, Luser droog wrote: > No worries. And for 2D you only need 1 vector. > > (x,y) -> (-y,x) Exactly. It's the "positively oriented" choice of vector of same length as, and perpendicular to, the original vector. > I'm still having difficulty with the "geometric significance" of the 4D > cross-product. It's sort of the the "fourth wall" from the point of view > of a 5D observer, right? Well, the 3D cross-product gives you the one "positively oriented" choice of vector perpendicular to the original two and of algorithmically "suitable" length (length = to the area of the parallelogram the two vectors to "be crossed" determine) (just as is the case for the 2D situation you described); and the 4D case is completely analogous: the three given vectors "to be crossed" determine a (sorry!) parallelopiped, and its volume is what the length of their cross product should be; once again, there are only two vectors of that length perpendicular to all three original vectors, and again it's the "positively oriented" one of those that serves as the cross product. What am I going on about with my "positively oriented" here? This: a fourth 4D vector v_4 is *positively oriented" with respect to the ordered triple (v_1, v_2, v_3) of three 4D vectors if the matrix whose four rows (assuming these are all row-vectors) are, from top to bottom, exactly v_1, v_2, v_3, and v_4 has nonnegative determinant (i.e., det(v_1, v_2, v_3, v_4) >/= 0) . (Notice that the main dot-product desideratum for cross products tells you, even for general values of n (not just 2 or 3 or 4) that the cross product X(v_1, ..., v_(n-1)) is positively oriented with respect to the ordered (n-1)-tuple (v_1, ..., v_(n-1)) exactly because the determinant in question (viz., det(v_1, ..., v_(n-1), X(v_1, ..., v_(n-1))) is numerically the same as the dot product of the cross product X(v_1, ..., v_(n-1)) with itself, and that's the square of the length of that cross product; and that, of course, like the square of any real number, is >/= 0 :-) .) OK, I'm supposed to be retired now; so enough of this pedagogy :-) . Cheers, -- tlvp -- Avant de repondre, jeter la poubelle, SVP.
[toc] | [prev] | [next] | [standalone]
| From | gernot.hoffmann@hs-emden-leer.de |
|---|---|
| Date | 2012-09-05 23:41 -0700 |
| Message-ID | <9e2f844d-06b1-4adc-8807-0636150cbc13@googlegroups.com> |
| In reply to | #910 |
Am Sonntag, 2. September 2012 21:14:19 UTC+2 schrieb luser- -droog:
> Dot product works for any two vectors of the same dimension.
>
> Cross product only defined for dimension 3.
>
>
>
> 552(1)02:11 PM:ps 0> cat mat.ps
>
> %!
>
>
>
> /.error where { pop /signalerror { .error } def } if
>
>
>
> /dot { % u v
>
> 2 copy length exch length ne {
>
> /dot cvx /invalidresult signalerror
>
> } if
>
> % u v
>
> 0 % u v sum
>
> 0 1 3 index length 1 sub { % u v sum i
>
> 3 index 1 index get exch % u v sum u_i i
>
> 3 index exch get % u v sum u_i v_i
>
> mul add % u v sum
>
> } for % u v sum
>
>
>
> 3 1 roll pop pop % sum
>
> } bind def
>
>
>
> % [ x1 x2 x3 ] [ y1 y2 y3 ] cross [ x2*y3-y2*x3 x3*y1-x1*y3 x1*y2-x2*y1 ]
>
> /cross { % u v
>
> dup length 3 ne
>
> 2 index length 3 ne or {
>
> /cross cvx /invalidresult signalerror
>
> } if
>
> % u v
>
> exch aload pop 4 3 roll aload pop % x1 x2 x3 y1 y2 y3
>
> [
>
> 5 index 2 index mul % ... [ x2*y3
>
> 3 index 6 index mul sub % ... [ x2*y3-y2*x3
>
> 5 index 5 index mul % ... [ x2*y3-y2*x3 x3*y1
>
> 8 index 4 index mul sub % ... [ x2*y3-y2*x3 x3*y1-x1*y3
>
> 8 index 5 index mul % ... [ x2*y3-y2*x3 x3*y1-x1*y3 x1*y2
>
> 8 index 7 index mul sub % ... [ x2*y3-y2*x3 x3*y1-x1*y3 x1*y2-x2*y1
>
> ]
>
> 7 1 roll 6 { pop } repeat
>
> } bind def
>
>
>
>
>
Simple procedures:
Dot product (Rn) and Cross product (R3) are part of the Matrix Library
Chapter 18.
(1)
http://www.fho-emden.de/~hoffmann/pstutor22112002.pdf
Cross product and Exterior Product:
p.37 Application of "Cross product" for vectors in R4. Result is in R6.
(2)
http://www.fho-emden.de/~hoffmann/quater12012002.pdf
(3)
http://en.wikipedia.org/wiki/Bivector#The_exterior_product
Personally, I would use the name 'Cross product' for the well known
operation in R3. In higher dimensions it's called 'Exterior product
of bivectors'. In R4 it's useful for handling quaternions (2).
I'm not a mathematician, I had just applied this stuff a while ago.
Best regards --Gernot Hoffmann
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.postscript
csiph-web