Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #2665 > unrolled thread
| Started by | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| First post | 2016-06-20 12:34 -0700 |
| Last post | 2016-09-13 18:30 -0700 |
| Articles | 14 — 6 participants |
Back to article view | Back to comp.lang.postscript
hypercube rotations luser- -droog <mijoryx@yahoo.com> - 2016-06-20 12:34 -0700
Re: hypercube rotations luser droog <luser.droog@gmail.com> - 2016-06-22 22:11 -0700
Re: hypercube rotations Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-22 23:48 -0700
Re: hypercube rotations JohnF <john@please.see.sig.for.email.com> - 2016-06-24 04:28 +0000
Re: hypercube rotations luser droog <luser.droog@gmail.com> - 2016-07-08 01:43 -0700
Re: hypercube rotations Peter Billam <peter@www.pjb.com.au> - 2016-07-14 09:41 +0000
Re: hypercube rotations Peter Billam <peter@www.pjb.com.au> - 2016-07-15 06:19 +0000
Re: hypercube rotations Bogus@Embarq.com (Steve) - 2016-07-15 12:15 +0000
Re: hypercube rotations JohnF <john@please.see.sig.for.email.com> - 2016-07-16 00:14 +0000
Re: hypercube rotations luser droog <luser.droog@gmail.com> - 2016-07-15 21:42 -0700
Re: hypercube rotations JohnF <john@please.see.sig.for.email.com> - 2016-07-16 05:01 +0000
Re: hypercube rotations luser droog <luser.droog@gmail.com> - 2016-09-13 18:14 -0700
Re: hypercube rotations Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-08-05 00:10 -0700
Re: hypercube rotations luser droog <luser.droog@gmail.com> - 2016-09-13 18:30 -0700
| From | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2016-06-20 12:34 -0700 |
| Subject | hypercube rotations |
| Message-ID | <e35d5a10-2ff9-4577-a49a-48559970cba8@googlegroups.com> |
http://codegolf.stackexchange.com/a/83318/2381
Uses https://github.com/luser-dr00g/xpost/blob/master/data/mat.ps
and ghostscript cmd-line args option.
$ gs -- hc.ps 30 0 0 0 0 30 #<- must supply 6 numbers
%!
(mat.ps)run
/lineto{{lineto}stopped{moveto}if}bind def
ARGUMENTS aload pop{f e d c b a}{exch cvr def}forall
/V[[0 0 0 0][1 0 0 0][1 0 1 0][0 0 1 0][0 1 0 0][1 1 0 0][1 1 1 0][0 1 1 0]
[0 0 0 1][1 0 0 1][1 0 1 1][0 0 1 1][0 1 0 1][1 1 0 1][1 1 1 1][0 1 1 1]]def
/V [ V { [ exch { .5 sub } forall ] } forall ] def
%ABCDEFGHIJKLMNOP
% 111111
%0123456789012345
/F[[0 1 2 3][0 1 5 4][0 1 9 8][0 3 7 4][0 3 11 8][0 4 12 8]
[1 2 6 5][1 2 10 9][1 5 13 9][2 3 7 6][2 3 11 10][2 6 14 10]
[3 7 15 11][4 5 6 7][4 5 13 12][4 7 15 12][5 6 14 13][6 7 15 14]
[8 9 10 11][8 9 13 12][8 11 15 12][9 10 14 13][10 11 15 14][12 13 14 15]
]def
/ROT[[[1 0 0 0][0 a cos a sin neg 0][0 a sin a cos 0][0 0 0 1]]
[[b cos 0 b sin 0][0 1 0 0][b sin neg 0 b cos 0][0 0 0 1]]
[[c cos c sin neg 0 0][c sin c cos 0 0][0 0 1 0][0 0 0 1]]
[[d cos 0 0 d sin][0 1 0 0][0 0 1 0][d sin neg 0 0 d cos]]
[[1 0 0 0][0 e cos 0 e sin neg][0 0 1 0][0 e sin 0 e cos]]
[[1 0 0 0][0 1 0 0][0 0 f cos f sin neg][0 0 f sin f cos]]]def
/P{aload pop{w z y x}{exch def}forall
x 2 mul
z 2 add div %w 2 add div 4 mul
y 2 mul
z 2 add div %w 2 add div 4 mul
neg
exch
%neg
}def
/V V ROT {transpose
matmul} forall def
300 400 translate
currentlinewidth
100 dup dup scale
div setlinewidth
F{
{V exch get P pstack()= lineto}forall
closepath stroke
}forall
showpage
[toc] | [next] | [standalone]
| From | luser droog <luser.droog@gmail.com> |
|---|---|
| Date | 2016-06-22 22:11 -0700 |
| Message-ID | <46e56073-6c7b-416e-8733-a2fe836c3a71@googlegroups.com> |
| In reply to | #2665 |
On Monday, June 20, 2016 at 2:34:08 PM UTC-5, luser droog wrote: > http://codegolf.stackexchange.com/a/83318/2381 > I've wanted to write this program ever since reading Rudy Rucker and P.D. Ouspensky, and A.K. Dewdney. For review, here's a very nice paper I just found about the wonders of rotation matrices: http://www.fastgraph.com/makegames/3drotation/ I've reduced the golfed version to 683 chars, using the binary-token-strings from my golf library, and abbreviated system names for stuff that would be longer in a binary-token- string. The rotations are the prime candidate for further reductions, but none of the other answers have solved that yet either! :)
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D’Oliveiro <lawrencedo99@gmail.com> |
|---|---|
| Date | 2016-06-22 23:48 -0700 |
| Message-ID | <111f1aa8-9d59-44a5-a1ca-6b6282edea2c@googlegroups.com> |
| In reply to | #2669 |
On Thursday, June 23, 2016 at 5:11:45 PM UTC+12, luser droog wrote: > For review, here's a very nice paper I just found about the wonders of > rotation matrices: > > http://www.fastgraph.com/makegames/3drotation/ Beware, if you combine a long enough series of rotation matrices (e.g. in a long animation), you will accumulate rounding errors that distort the shape of the object. This can be fixed by periodically renormalizing the matrix so its determinant is 1. Alternatively, you can use quaternions to represent rotations. Then you won’t get rounding distortions. Quaternions also have other advantages, like smooth interpolation between different orientations.
[toc] | [prev] | [next] | [standalone]
| From | JohnF <john@please.see.sig.for.email.com> |
|---|---|
| Date | 2016-06-24 04:28 +0000 |
| Message-ID | <nkicu7$f72$1@reader1.panix.com> |
| In reply to | #2669 |
luser droog <luser.droog@gmail.com> wrote: > On Monday, June 20, 2016 at 2:34:08 PM UTC-5, luser droog wrote: >> http://codegolf.stackexchange.com/a/83318/2381 > > I've wanted to write this program ever since reading Rudy Rucker > and P.D. Ouspensky, and A.K. Dewdney. For review, here's a very > nice paper I just found about the wonders of rotation matrices: > > http://www.fastgraph.com/makegames/3drotation/ > > I've reduced the golfed version to 683 chars, using the > binary-token-strings from my golf library, and abbreviated > system names for stuff that would be longer in a binary-token- > string. The rotations are the prime candidate for further > reductions, but none of the other answers have solved that > yet either! :) In addition to your fastgraph.com link above, I found http://paulbourke.net/geometry/rotate/ very useful when I programmed this stuff in C. It's a bit more "cookbook", and it also (though briefly) discusses quaternions (which I agree is likely the better approach, though, at least for me, harder to intuitively see how it's working). -- John Forkosh ( mailto: j@f.com where j=john and f=forkosh )
[toc] | [prev] | [next] | [standalone]
| From | luser droog <luser.droog@gmail.com> |
|---|---|
| Date | 2016-07-08 01:43 -0700 |
| Message-ID | <f132286f-f907-48ae-8b9b-ecd6c28a5f83@googlegroups.com> |
| In reply to | #2672 |
On Thursday, June 23, 2016 at 11:28:56 PM UTC-5, JohnF wrote: > luser droog <luser.droog@gmail.com> wrote: > > On Monday, June 20, 2016 at 2:34:08 PM UTC-5, luser droog wrote: > >> http://codegolf.stackexchange.com/a/83318/2381 > > > > I've wanted to write this program ever since reading Rudy Rucker > > and P.D. Ouspensky, and A.K. Dewdney. For review, here's a very > > nice paper I just found about the wonders of rotation matrices: > > > > http://www.fastgraph.com/makegames/3drotation/ > > > > I've reduced the golfed version to 683 chars, using the > > binary-token-strings from my golf library, and abbreviated > > system names for stuff that would be longer in a binary-token- > > string. The rotations are the prime candidate for further > > reductions, but none of the other answers have solved that > > yet either! :) > > In addition to your fastgraph.com link above, I found > http://paulbourke.net/geometry/rotate/ > very useful when I programmed this stuff in C. > It's a bit more "cookbook", and it also (though briefly) > discusses quaternions (which I agree is likely the > better approach, though, at least for me, harder to > intuitively see how it's working). A year or two ago I tried to beef-up my vector analysis skills by reading the very interesting History of Vector Analysis. I can now spell Ausdehnungslehre, but I never figured out how to do a Grassman product. Quaterions freak me out. For that matter, the complex plane still freaks me out. I think I need to take a math class. The same author's History of Newtonian Mechanics OTOH is refreshingly mathematical while still historical and entertaining. It's too bad the VA book didn't have sidebars.
[toc] | [prev] | [next] | [standalone]
| From | Peter Billam <peter@www.pjb.com.au> |
|---|---|
| Date | 2016-07-14 09:41 +0000 |
| Message-ID | <slrnnoenhl.4ov.peter@box8.pjb.com.au> |
| In reply to | #2689 |
On 2016-07-08, luser droog <luser.droog@gmail.com> wrote: > > A year or two ago I tried to beef-up my vector analysis skills > by reading the very interesting History of Vector Analysis. > I can now spell Ausdehnungslehre, but I never figured out how > to do a Grassman product. Quaterions freak me out. For that > matter, the complex plane still freaks me out. I think I need > to take a math class. I posted a followup to this, but I'm not sure it got through because my newsserver; well sure it displays the title, but when I try to get my post it says Article 23453 is unavailable. :-( So if it has got through to you all, could someone repost it so that I can save my posting ? And if it hasn't got through to you all, I'll try to remember what I said and followup again... Peter ( P.S. I hope this one behaves better ) -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html
[toc] | [prev] | [next] | [standalone]
| From | Peter Billam <peter@www.pjb.com.au> |
|---|---|
| Date | 2016-07-15 06:19 +0000 |
| Message-ID | <slrnnoh03s.3g3.peter@box8.pjb.com.au> |
| In reply to | #2689 |
On 2016-07-08, luser droog <luser.droog@gmail.com> wrote: > A year or two ago I tried to beef-up my vector analysis skills > by reading the very interesting History of Vector Analysis. > I can now spell Ausdehnungslehre, but I never figured out how > to do a Grassman product. Quaterions freak me out. For that > matter, the complex plane still freaks me out. I think I need > to take a math class. I wrote: > I posted a followup to this, but I'm not sure it got through > because my newsserver; well sure it displays the title, but when > I try to get my post it says Article 23453 is unavailable. :-( > So if it has got through to you all, could someone repost it so > I can save my posting ? And if it hasn't got through to you all, > I'll try to remember what I said and followup again... Well groups.google.com hasn't got it either, so here goes: The most helpful intro to Grassman products I know is Roger Penrose "The Road To Reality" pp.211-215, 227-229. He's a great explainer, but it's a heavy book, 1094 pages... Not that I've ever actually _used_ a Grassman product :-) The complex plane is not scary, in fact Roger Penrose mostly exists in the complex plane. He introduces it in pp.81-83, 87-88 ... Wikipedia is really authoritative in this kind of thing, but it's often overwhelming, and https://en.wikipedia.org/wiki/Exterior_algebra is a example of that :-( Regards, Peter P.S. I've never used a quaternion either, and mainly know them from http://math.ucr.edu/home/baez/octonions/ by John C. Baez who I always have to introduce to people with a "not to be confused with Joan Baez": well, it turns out that not everything is coincidence; his uncle Albert Baez, also a physicist, was the father of Joan Baez. (Off-topic apologies) -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html
[toc] | [prev] | [next] | [standalone]
| From | Bogus@Embarq.com (Steve) |
|---|---|
| Date | 2016-07-15 12:15 +0000 |
| Message-ID | <c1.2b8.3rrWjr$05x@NOVOSAD3.EMBARQ.COM> |
| In reply to | #2701 |
hi,
Peter Billam <peter@www.pjb.com.au> writes:
>On 2016-07-08, luser droog <luser.droog@gmail.com> wrote:
>> A year or two ago I tried to beef-up my vector analysis skills
>> by reading the very interesting History of Vector Analysis.
>> I can now spell Ausdehnungslehre, but I never figured out how
>> to do a Grassman product. Quaterions freak me out. For that
>> matter, the complex plane still freaks me out. I think I need
>> to take a math class.
>
>I wrote:
>> I posted a followup to this, but I'm not sure it got through
>> because my newsserver; well sure it displays the title, but when
>> I try to get my post it says Article 23453 is unavailable. :-(
Google Groups usually has most postings even when other
news servers may not. So a quick check there may help.
>> So if it has got through to you all, could someone repost it so
>> I can save my posting ? And if it hasn't got through to you all,
>> I'll try to remember what I said and followup again...
>Well groups.google.com hasn't got it either, so here goes:
>
>The most helpful intro to Grassman products I know is
>Roger Penrose "The Road To Reality" pp.211-215, 227-229.
>He's a great explainer, but it's a heavy book, 1094 pages...
>Not that I've ever actually _used_ a Grassman product :-)
>
>The complex plane is not scary, in fact Roger Penrose mostly exists
>in the complex plane. He introduces it in pp.81-83, 87-88 ...
>
>Wikipedia is really authoritative in this kind of thing,
>but it's often overwhelming, and
> https://en.wikipedia.org/wiki/Exterior_algebra
>is a example of that :-(
The best discussion of the complex number system that I know of
is "An Imaginary Tale: The Story of {symbol for the square root} -1"
by Paul j. Nahin, Princeton Unuversity Press, 1998. Starts as a
history, and then covers uses of complex numbers, and then complex
functions.
The history part walks you through the how and why of complex
numbers. The usage part works some interesting examples and
gives a feel for working with the complex plane. The rest will be
left as an advanced study of some sort.
Roger Penrose's discussion is good as well. But it's less thorough.
Recommended,
Steve N.
>
>Regards, Peter
>
>P.S. I've never used a quaternion either, and mainly know them from
> http://math.ucr.edu/home/baez/octonions/
>by John C. Baez who I always have to introduce to people with a
>"not to be confused with Joan Baez": well, it turns out that not
>everything is coincidence; his uncle Albert Baez, also a physicist,
>was the father of Joan Baez. (Off-topic apologies)
>
>--
>
>Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html
[toc] | [prev] | [next] | [standalone]
| From | JohnF <john@please.see.sig.for.email.com> |
|---|---|
| Date | 2016-07-16 00:14 +0000 |
| Message-ID | <nmbu8h$d73$1@reader1.panix.com> |
| In reply to | #2701 |
Peter Billam <peter@www.pjb.com.au> wrote: > On 2016-07-08, luser droog <luser.droog@gmail.com> wrote: >> A year or two ago I tried to beef-up my vector analysis skills >> by reading the very interesting History of Vector Analysis. >> I can now spell Ausdehnungslehre, but I never figured out how >> to do a Grassman product. Quaterions freak me out. For that >> matter, the complex plane still freaks me out. I think I need >> to take a math class. > > The most helpful intro to Grassman products I know is > Roger Penrose "The Road To Reality" pp.211-215, 227-229. > He's a great explainer, but it's a heavy book, 1094 pages... > Not that I've ever actually _used_ a Grassman product :-) > The complex plane is not scary, in fact Roger Penrose mostly > exists in the complex plane. He introduces it in pp.81-83,87-88... That's a terrific book, uniquely filling an otherwise empty niche, introducing a lot of significant "mathematics for physicists" for readers without all the usual prerequisites. You do need enough background so as not to get scared just looking at math, but then you come away really knowing some stuff. (Sometimes I find him a bit too wordy with tangential prose, unnecessarily interrupting the main stream of concepts to the point you can lose track of what you were doing.) > Wikipedia is really authoritative in this kind of thing, > but it's often overwhelming, and > https://en.wikipedia.org/wiki/Exterior_algebra > is a example of that :-( Regards, Peter > P.S. I've never used a quaternion either, and mainly know them from > http://math.ucr.edu/home/baez/octonions/ > by John C. Baez He's done some really good work, too, and put up a lot of good stuff on the web. Two nice references, pjb. -- John Forkosh ( mailto: j@f.com where j=john and f=forkosh )
[toc] | [prev] | [next] | [standalone]
| From | luser droog <luser.droog@gmail.com> |
|---|---|
| Date | 2016-07-15 21:42 -0700 |
| Message-ID | <9f79426f-2e3b-475d-a98e-b6f9ec215ec6@googlegroups.com> |
| In reply to | #2703 |
On Friday, July 15, 2016 at 7:14:09 PM UTC-5, JohnF wrote: > Peter Billam <peter@www.pjb.com.au> wrote: > > On 2016-07-08, luser droog <luser.droog@gmail.com> wrote: > >> A year or two ago I tried to beef-up my vector analysis skills > >> by reading the very interesting History of Vector Analysis. > >> I can now spell Ausdehnungslehre, but I never figured out how > >> to do a Grassman product. Quaterions freak me out. For that > >> matter, the complex plane still freaks me out. I think I need > >> to take a math class. > > > > The most helpful intro to Grassman products I know is > > Roger Penrose "The Road To Reality" pp.211-215, 227-229. > > He's a great explainer, but it's a heavy book, 1094 pages... > > Not that I've ever actually _used_ a Grassman product :-) > > The complex plane is not scary, in fact Roger Penrose mostly > > exists in the complex plane. He introduces it in pp.81-83,87-88... > > That's a terrific book, uniquely filling an otherwise empty niche, > introducing a lot of significant "mathematics for physicists" > for readers without all the usual prerequisites. You do need > enough background so as not to get scared just looking at math, > but then you come away really knowing some stuff. (Sometimes > I find him a bit too wordy with tangential prose, unnecessarily > interrupting the main stream of concepts to the point you can > lose track of what you were doing.) > > > Wikipedia is really authoritative in this kind of thing, > > but it's often overwhelming, and > > https://en.wikipedia.org/wiki/Exterior_algebra > > is a example of that :-( Regards, Peter > > P.S. I've never used a quaternion either, and mainly know them from > > http://math.ucr.edu/home/baez/octonions/ > > by John C. Baez > > He's done some really good work, too, and put up a lot of good > stuff on the web. Two nice references, pjb. Thanks, fellows! Wikipedia also led me to this free textbook: "Linear Algebra via Exterior Products" (2010) by Sergei Winitzki. https://sites.google.com/site/winitzki/linalg which I will be reading while amazon does its thing.
[toc] | [prev] | [next] | [standalone]
| From | JohnF <john@please.see.sig.for.email.com> |
|---|---|
| Date | 2016-07-16 05:01 +0000 |
| Message-ID | <nmcf30$lkk$1@reader1.panix.com> |
| In reply to | #2704 |
luser droog <luser.droog@gmail.com> wrote: > On Friday, July 15, 2016 at 7:14:09 PM UTC-5, JohnF wrote: >> Peter Billam <peter@www.pjb.com.au> wrote: >> > On 2016-07-08, luser droog <luser.droog@gmail.com> wrote: >> >> A year or two ago I tried to beef-up my vector analysis skills >> >> by reading the very interesting History of Vector Analysis. >> >> I can now spell Ausdehnungslehre, but I never figured out how >> >> to do a Grassman product. Quaterions freak me out. For that >> >> matter, the complex plane still freaks me out. I think I need >> >> to take a math class. >> > >> > The most helpful intro to Grassman products I know is >> > Roger Penrose "The Road To Reality" pp.211-215, 227-229. >> > He's a great explainer, but it's a heavy book, 1094 pages... >> > Not that I've ever actually _used_ a Grassman product :-) >> > The complex plane is not scary, in fact Roger Penrose mostly >> > exists in the complex plane. He introduces it in pp.81-83,87-88... >> >> That's a terrific book, uniquely filling an otherwise empty niche, >> introducing a lot of significant "mathematics for physicists" >> for readers without all the usual prerequisites. You do need >> enough background so as not to get scared just looking at math, >> but then you come away really knowing some stuff. (Sometimes >> I find him a bit too wordy with tangential prose, unnecessarily >> interrupting the main stream of concepts to the point you can >> lose track of what you were doing.) >> >> > Wikipedia is really authoritative in this kind of thing, >> > but it's often overwhelming, and >> > https://en.wikipedia.org/wiki/Exterior_algebra >> > is a example of that :-( Regards, Peter >> > P.S. I've never used a quaternion either, and mainly know them from >> > http://math.ucr.edu/home/baez/octonions/ >> > by John C. Baez >> >> He's done some really good work, too, and put up a lot of good >> stuff on the web. Two nice references, pjb. > > Thanks, fellows! Wikipedia also led me to this free textbook: > "Linear Algebra via Exterior Products" (2010) by Sergei Winitzki. > https://sites.google.com/site/winitzki/linalg > which I will be reading while amazon does its thing. Penrose is also free online, http://chaosbook.org/library/Penr04.pdf (which I hesitated to mention earlier since it's pretty obviously pirated) -- John Forkosh ( mailto: j@f.com where j=john and f=forkosh )
[toc] | [prev] | [next] | [standalone]
| From | luser droog <luser.droog@gmail.com> |
|---|---|
| Date | 2016-09-13 18:14 -0700 |
| Message-ID | <5dfcd59c-8f58-4933-b81c-6c8e28b1e38e@googlegroups.com> |
| In reply to | #2701 |
On Friday, July 15, 2016 at 1:19:41 AM UTC-5, Peter Billam wrote: > The complex plane is not scary, in fact Roger Penrose mostly exists > in the complex plane. He introduces it in pp.81-83, 87-88 ... > I begin to see (never did place that order yet: spent all my liquid on an amplifier and wah-wah pedals). If you believe Florian Cajori another very useful mathematico-arithmetical tool for which we have the complex plane and i to thank is ... ... the plus sign: + Before there was an unreal component, there was no need to notate addition. You'd just use the word "plus" or "sum" (in your native language). The plus sign arose with the need to represent /deferred/ addition or "symbolic" addition, to which you might then apply algebraic transforms. When there was just numbers and numbers, you'd just do it and write the answer. ref. A History of Mathematical Notation
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D’Oliveiro <lawrencedo99@gmail.com> |
|---|---|
| Date | 2016-08-05 00:10 -0700 |
| Message-ID | <6b0cfc4f-9f64-48d2-886f-394331f6c85a@googlegroups.com> |
| In reply to | #2689 |
On Friday, July 8, 2016 at 8:43:48 PM UTC+12, luser droog wrote: > Quater[n]ions freak me out. Quaternions are wonderfully useful in 3D graphics: * Because they express pure rotations, they are good for accumulated rotation transformations, e.g. spinning objects, without the rounding errors introducing other distortions to the shape. It’s easy enough to convert a quaternion to a matrix representation as needed. * In animation, when you interpolate between two rotation orientations expressed as quaternions, you get a uniform movement along the great circle connecting those two orientations. This is usually what you want, for example in the movement of the joints in a character’s skeleton. Whereas if you try interpolating between Euler angles (latitude/longitude representation), weird things happen. The only thing I still don’t understand is why they use the sine and cosine of half the rotation angle, rather than the actual rotation angle...
[toc] | [prev] | [next] | [standalone]
| From | luser droog <luser.droog@gmail.com> |
|---|---|
| Date | 2016-09-13 18:30 -0700 |
| Message-ID | <20f69478-c8cc-4f95-9fd4-2481732e76f3@googlegroups.com> |
| In reply to | #2669 |
On Thursday, June 23, 2016 at 12:11:45 AM UTC-5, luser droog wrote:
> On Monday, June 20, 2016 at 2:34:08 PM UTC-5, luser droog wrote:
> > http://codegolf.stackexchange.com/a/83318/2381
> >
>
> I've wanted to write this program ever since reading Rudy Rucker
> and P.D. Ouspensky, and A.K. Dewdney.
I forgot to share the super-golfed version. 307 bytes.
---- snip here ----
7(G)run $
ex
du
A B
idi 2 mo .5 su
2 mu Z 2(!V)@
fore
3 4 100(&>88)$(,)# div(<N)#[0 1 15{[(C1DC2DC4DA8D){(2?)$}F]}fo]0
1 5{ARGUMENTS 1(XK/>)${{rotyz}{rotxz}{rotxy}{rotxw}{rotyw}{rotzw}}(>K?)$
matmul}fo du(019;:89=?;37?>:26><804<=576451320){48
su get al po(WZYX){(>3)$}F X E Y E{li}(D)#{mov}if du}fora(HB)#
---- snip here ----
It relies on the new features of this version of the G library,
which now includes my matrix library functions.
https://github.com/luser-dr00g/G/blob/acf1debf0868305d1b0d077e979159defffa9bd1/G
%!
%G
%ps golfing utilities collection
%
%eg.
% %!
% n(G)run % where n controls which pieces are activated:
%
% (G)run
% 0(G)run %activate . $ @ #
% equivalent to the former (and still valid): (G)run
%
% 1(G)run %activate . $ @ # and operator abbreviations
% equivalent to the former: (G)run A % load abbreviation dict,
%
% 2(G)run $ %activate . $ @ # and begin implicit procedure block
% equivalent to the former: (G)run D % begin implicit procs
%
% 3(G)run $ %activate all of the above
% equivalent to the former: (G)run A D % abbreviations and implicit procs
%
% 4(G)run %activate matrix functions
% also available at any level by calling `matrices begin` after loading G
%
% implicit procedure blocks require a $ to activate, since it must
% be delayed until `currentfile` is the program file.
%
% To reiterate, the base-level is just the binary-coded strings support: 0(G)run
% To add operator abbreviations, add 1 to the argument: 1(G)run
% To add an implicit procedure block,
% add 2 to the argument and '$' after: 2(G)run $
% For both, add 1 and 2 to produce 3: 3(G)run $
% For all that, and matrices, add 4 to produce 7: 7(G)run $
%
%Version 0c
%0a bugfixes. remove output from ABBR construction
%0b add n argument
%0c add iter, foreach, split, ncat, acat and (expanded) matrix library
%%% Base level
%!
%operators by code number or number-strings
%by dynamically constructing a binary token in a string
/.{<920>dup 1 4 3 roll put cvx exec}def % execute operator by table number
/${//. 73 .}def %73== /forall % execute each char in string as operator number
/@{{32 sub //. exec}73 .}def % ' '->0
/#{{95 add //. exec}73 .}def % ' '->127
%!
% access multidim arrays and deep nested dicts with index array
%
/!{{get}forall}def % comp [indices] ! element_indices
/*{ % comp [indices] value * -
3 1 roll % v c a
dup dup length % v c a a n
1 sub 0 exch getinterval % v c a a[0:n-2]
exch dup length 1 sub get % v c a[0:n-2] a[n-1]
/! cvx exch % v c a[0:n-2] ! a[n-1]
cvlit % v c a[0:n-2] ! a_n-1
3 2 /roll cvx % v c a[0:n-2] ! a_n-1 3 2 roll
/put cvx % v c a[0:n-2] ! a_n-1 3 2 roll put
6 array astore cvx exec
}def
% start inc fin iter proc
/iter {
[ 4 1 roll
{ % s i f
2 index lt { pop pop exit } if % s i
1 index 3 1 roll % s s i
add % s s'
/SELF exch 0 exch put % s
}aload pop
]
0 1 2 index length 1 sub { % [] i
2 copy get /SELF eq { % [] i
1 index 3 copy put % []' i []'
pop % []' i
} if % [] i
pop % []
} for % []
cvx % {}
}def
%/i 0 1 9 iter def
%i = i = i =
%{ i == } loop
%[ 0 1 9 iter /something load /something load ] cvx loop
% (string){proc} foreach -
% (s) proc
% (t) proc
% ...
% [/A/R/R/A/Y]{proc} foreach -
% [/A] proc
% [/R] proc
% ...
%
% <</dict<def>/key(val)...>> foreach -
% <</dict<def>>> proc
% <</key(val)>> proc
% ...
/foreach {
10 dict begin
{proc src}{exch def}forall
/src load type /dicttype ne {
0 1 /src load length 1 sub {
/src load exch 1 getinterval
[
/proc load /exec load
currentdict /begin load
] cvx end exec
} for
}{ % dicttype
/src load
[
([) cvn cvx 3 1 /roll load
(>>) cvn cvx
/proc load /exec load
] cvx
[
/forall load currentdict /begin load
] cvx exec
} ifelse
end
} def
%eg.
%(string){==}foreach
%[/A/R/R/A/Y]{==}foreach
%<</dict<def>/key(val)>>{===}foreach %gs extension
%!
%
%(string) (delimiter) split [(s)(t)(r)(i)(n)(g)]
/split { % str del
[ 3 1 roll % [ str del
{ % [ ... str del
search { % [ ... post match pre
3 1 roll % [ ... pre post match %ie. [ ... pre str' del
}{ % [ ... str
exit % [ ... str %% break-from-loop
}ifelse
}loop % [ ...
] % [ ... ]
} def
%
%(string of words separated by spaces)( )split ==
%-> [(string) (of) (words) (separated) (by) (spaces)]
%
%(string.of.words.separated.by.dots)(.)split ==
%-> [(string) (of) (words) (separated) (by) (dots)]
% (s1) (s2) (s3) ... (sN) n ncat (s1s2s3...sN)
% [a1] [a2] [a3] ... [aN] n ncat [a1 a2 a3 ... aN]
/ncat { % s1 s2 s3 .. sN n % first sum the lengths
dup 1 add % s1 s2 s3 .. sN n n+1
copy % s1 s2 s3 .. sN n s1 s2 s3 .. sN n
0 exch % s1 s2 s3 .. sN n s1 s2 s3 .. sN 0 n
{
exch length add
} repeat % s1 s2 s3 .. sN n len % then allocate string
2 index type /stringtype eq { string }{ array } ifelse
exch % s1 s2 s3 .. sN str n
0 exch % s1 s2 s3 .. sN str off n
-1 1 { % s1 s2 s3 .. sN str off n % copy each string
2 add -1 roll % s2 s3 .. sN str off s1 % bottom to top
3 copy putinterval % s2 s3 .. sN str' off s1
length add % s2 s3 .. sN str' off+len(s1)
% s2 s3 .. sN str' off'
} for % str' off'
pop % str'
} def
%
%(abc) (def) (ghi) (jkl) 4 ncat == %(abcdefghijkl)
% (s1) (s2) cat (s1s2)
% [a1] [a2] cat [a1 a2]
/cat {
2 ncat
} def
%array-of-string acat
%array-of-arrays acat
/acat { % [ (s1) (s2) ... (sn) ] ascat (s1s2...sn)
% [...]
0 1 index { length add } forall % [...] len
1 index type /stringtype eq { string }{ array } ifelse
exch 0 exch % (...) 0 [...]
{ % (...) pos (.)
3 copy putinterval % (...) pos (.)
length add % (...) pos
} forall % (...) pos
pop
} def
%%% Implicit Proc Block (arg 1 and 0 ne)
%!
%implicit procedure definitions
%-library- version
%D begins an implicit-procedure block,
%defining the next line as A, the next as B, ...
%according to ascii sequence, until a blank line.
/D{[(A){
currentfile 99 string readline not { pop exit } if
dup length 0 eq { exit } if
cvx
1 index 1 string copy dup dup 0 get 1 add 0 exch put
}loop>>begin}def
%%% Abbreviated Names (arg 2 and 0 ne)
%!
%abbr.ps
% abbreviated system names
% exports (defines) 1 procedure:
% - ABBR dict
% which generates an abbreviation dictionary.
%
% This allows you to use alphabetic abbreviations for
% standard systemdict names, suxh as:
%
% a %= abs
% ad %= add
% mu %= mul
% pr %= print
% g %= ge
% f %= file
% etc. Check PLRM 2ed or 3ed, Appendix F Encoded System Names
% Edit for compilation: name ABBR has been shortened to A
% and dict is left on dictstack.
/A {
2 dict begin
225 -1 0 { % generate defs in reverse alphabetic (numeric) order
%dup =only( )=only
<910> dup 1 4 3 roll put cvx exec
%dup =only( )=only
cvx dup =string cvs % op str
%pstack()= stop
exch
dup { currentdict end exch load
} stopped { pop begin cvlit }{ exch begin exch pop } ifelse
exch
%pstack() = %stop
0
1 1 3 index length
%1 sub
{ % opname str 0 i
3 copy getinterval % opname str 0 i str[0,i]
%dup =only( )=only
cvn 4 index def
pop % opname str 0
} for
%()=
pop pop pop
} for
0 1 225 { % print out the shortest ABBR name for each system name.
%dup =only( )=only
<910> dup 1 4 3 roll put cvx exec % opname
%dup =only( )=only
cvx dup =string cvs
exch
dup { currentdict end exch load
} stopped { pop begin cvlit }{ exch begin exch pop } ifelse
exch
0
{
1 1 3 index length 1 sub {
3 copy getinterval
dup cvn load % opname str 0 i str[0,i] loaded
5 index eq {
pop%=only( )=only
pop
stop
}{
pop pop
} ifelse
} for
} stopped pop
%()=
pop pop pop
} for
/fore {foreach} def
/A where pop /A currentdict put %memo
%currentdict end
} bind def
/matrices 20 dict def
matrices begin
%!
%mat.ps
%Matrix and Vector math routines
/ident { 1 dict begin /n exch def
[
1 1 n { % [ i
[ exch % [ [ i
1 1 n { % [ [ i j
1 index eq { 1 }{ 0 } ifelse % [ [ i b
exch % [ [ b i
} for % [ [ b+ i
pop ] % [ [ b+ ]
} for % [ [b+]+ ]
]
end } def
/rotx { 1 dict begin /t exch def
[ [ 1 0 0 ]
[ 0 t cos t sin neg ]
[ 0 t sin t cos ] ]
end } def
/roty { 1 dict begin /t exch def
[ [ t cos 0 t sin ]
[ 0 1 0 ]
[ t sin neg 0 t cos ] ]
end } def
/rotz { 1 dict begin /t exch def
[ [ t cos t sin neg 0 ]
[ t sin t cos 0 ]
[ 0 0 1 ] ]
end } def
/rotxy { 1 dict begin /t exch def
[ [ t cos t sin neg 0 0 ]
[ t sin t cos 0 0 ]
[ 0 0 1 0 ]
[ 0 0 0 1 ] ]
end } def
/rotyz { 1 dict begin /t exch def
[ [ 1 0 0 0 ]
[ 0 t cos t sin neg 0 ]
[ 0 t sin t cos 0 ]
[ 0 0 0 1 ] ]
end } def
/rotxz { 1 dict begin /t exch def
[ [ t cos 0 t sin 0 ]
[ 0 1 0 0 ]
[ t sin neg 0 t cos 0 ]
[ 0 0 0 1 ] ]
end } def
/rotxw { 1 dict begin /t exch def
[ [ t cos 0 0 t sin ]
[ 0 1 0 0 ]
[ 0 0 1 0 ]
[ t sin neg 0 0 t cos ] ]
end } def
/rotyw { 1 dict begin /t exch def
[ [ 1 0 0 0 ]
[ 0 t cos 0 t sin neg ]
[ 0 0 1 0 ]
[ 0 t sin 0 t cos ] ]
end } def
/rotzw { 1 dict begin /t exch def
[ [ 1 0 0 0 ]
[ 0 1 0 0 ]
[ 0 0 t cos t sin neg ]
[ 0 0 t sin t cos ] ]
end } def
/.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 % rows of A
[
0 1 R 1 sub { /r exch def % cols of B
0
0 1 Q 1 sub { /q exch def % terms of sum
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 { 10 dict begin
/op exch def
2 copy length exch length ne {
/op load /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 load /exch load /pop load /get load
%3 copy pop get % u v i u_i v_i
3 /copy load /pop load /get load
%op exch pop % u v u_i(op)v_i
/op load /exec load /exch load /pop load
3 1 /roll load % u_i(op)v_i u v
] cvx end
for % [ ... u v
pop pop ]
} def
%length of a vector
/mag { 0 exch { dup mul add } forall } def
% u v {operator} sop u(op)v
% where one of u or v is a scalar
% and the other is a vector
/sop {
3 1 roll
dup type /arraytype eq { % v array
exch % v u
[ exch % v [ u
2 index length 1 sub { dup } repeat % v [ u^#v
] exch % u v
}{ % v scalar
[ exch % u [ v
2 index length 1 sub { dup } repeat % u [ v^#u
} ifelse
3 2 roll
vop
} def
%4 [ 2 3 4 ] { add } sop ==
end
% process options
count 0 ne { % empty stack: do nothing
dup 4 and 0 ne {
matrices begin
} if
dup 1 and 0 ne { % n&1
2 and 0 ne { % n&2 1+2
A
{D} (?) % "exec" activate selected components with $
}{ % 1
A
} ifelse
}{
2 and 0 ne { % 2
{D} (?) % "exec" activate selected components with $
} if
} ifelse
} if
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.postscript
csiph-web