I discovered a nice solution using the method of Jacobi, see
http://jsoftware.com/pipermail/programming/2010-April/019081.html
His method essentially gave the structure, the rest was amending.
kfcs1=: 3 : 0
(i.>:{:$y) kfcs1 y
:
t=. ((-*),:2+0=])"(1) (#~ x e.~ [:+/"(1) 0=]) 3 #.^:_1 i.3^{:$y
c=. ({. , +/ , 0 ,: {:) y
t amnd c
)
amnd=: 4 : 0
s=. {:$y
($x)$ ,((s*x) +"1 i.s) { ,y
)
I had to introduce a verb for higher order amends.
C=: 4 3 0 ,: _4 _3 _2
2 (kfcs -:&:([:/:~@,<"2) kfcs1) C
1
(kfcs -:&:([:/:~@,<"2) kfcs1) C
1
R.E. Boss
> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens Kip Murray
> Verzonden: zondag 11 april 2010 3:39
> Aan: Programming forum
> Onderwerp: Re: [Jprogramming] boxes
>
> Hello, R.E. Boss,
>
> It will probably be Tuesday or Wednesday before I can attempt to
> understqand how
> your verb kfcs works. In the meantime, are you willing to give an
> explanation
> analogous to my explanation below of verb cr?
>
> Here is how monadic verb cr (canonical representation) works:
>
> cr =: ({. + 0.5 * [: (- |) {:) ,: [: | {:
>
> Given the argument a ,: h i.e. location ,: components of a box
> diagonal
> vector, verb cr returns
>
> ( (a + 0.5 * h) - 0.5 * |h ) ,: |h
>
> that is, cr locates the center a + 0.5 * h of the box and subtracts 0.5 *
> |h to
> locate the "lower left rear corner" llr . Then llr ,: |h is the canonical
> representation whose components are non-negative. I believe this approach
> works
> correctly in any number of dimensions and on any box, for example, in
> three
> dimensions the "box" can be a corner or an edge or a face or a "whole
> box."
>
> Kip
>
>
> R.E. Boss wrote:
> > <"2 ] 3 kfaces C
> > |length error: kfaces
> > | ,/(({.y)+"1({:y)*"1 (#^:_1"1#:@i.@(2^+/))"1 id),:"1({:y)*"1-.id
> >
> > 3-face of the cube should be included as well.
> >
> >
> > A simpler alternative:
> >
> > kfcs=: 3 : 0
> > t1=. t=. #:i.2^{:$y
> > ;(<y) (*"1&{: ,:~"1 {...@] +"1 }:@[ *"1 {:@] )~&.> t1 <@([ ,~ ] #~ 0 =
> > +/@:*"1)"1 _ t
> > :
> > t1=. (#~ x = +/"1 ) t=. #:i.2^{:$y
> > y (*"1&{: ,:~"1 {...@] +"1 }:@[ *"1 {:@] )~"2 t1 ([ ,~ ] #~ 0 =
> +/@:*"1)"1 _
> > t
> > )
> >
> > <"2 ] 0 kfcs C
> > +-----+------+-----+------+-----+------+-----+------+
> > |4 3 0|4 3 _2|4 0 0|4 0 _2|0 3 0|0 3 _2|0 0 0|0 0 _2|
> > |0 0 0|0 0 0|0 0 0|0 0 0|0 0 0|0 0 0|0 0 0|0 0 0|
> > +-----+------+-----+------+-----+------+-----+------+
> >
> > <"2 ] 1 kfcs C
> > +------+-------+------+-------+
> > |4 3 0|4 0 0 |0 3 0|0 0 0 |
> > |0 0 _2|0 0 _2 |0 0 _2|0 0 _2 |
> > +------+-------+------+-------+
> > |4 3 0|4 3 _2|0 3 0|0 3 _2|
> > |0 _3 0|0 _3 0|0 _3 0|0 _3 0|
> > +------+-------+------+-------+
> > | 4 3 0| 4 3 _2| 4 0 0| 4 0 _2|
> > |_4 0 0|_4 0 0|_4 0 0|_4 0 0|
> > +------+-------+------+-------+
> >
> > <"2 ] 2 kfcs C
> > +-------+--------+
> > |4 3 0|0 3 0 |
> > |0 _3 _2|0 _3 _2 |
> > +-------+--------+
> > | 4 3 0| 4 0 0 |
> > |_4 0 _2|_4 0 _2 |
> > +-------+--------+
> > | 4 3 0| 4 3 _2|
> > |_4 _3 0|_4 _3 0|
> > +-------+--------+
> >
> > <"2 ] 3 kfcs C
> > +--------+
> > | 4 3 0|
> > |_4 _3 _2|
> > +--------+
> >
> > faces are ordered to their diagonal vector.
> >
> > Without left argument, all faces are given:
> >
> > $ kfcs C
> > 27 2 3
> >
> >
> > For higher dimensions:
> >
> > 2 (kfcs -:&(,@:(<"2)) kfaces) 4 3 0 _2,:_4 _3 _2 1
> > 1
> >
> > $ kfcs 4 3 0 _2,:_4 _3 _2 1
> > 81 2 4
> >
> >
> > R.E. Boss
> >
> >
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm