NB. The "box" in direction h from base-point a is the array a ,: h
NB. Vectors a and a+h are diagonally opposite corners of this "box".
NB.
NB. Items of the following array are the eight unit cubes based at 0 0 0
]cubes =: 8 2 3 $ cubedata
0 0 0
_1 _1 _1
0 0 0
_1 _1 1
0 0 0
_1 1 _1
0 0 0
_1 1 1
0 0 0
1 _1 _1
0 0 0
1 _1 1
0 0 0
1 1 _1
0 0 0
1 1 1
NB. Items of the following array are the six faces of cube 0 0 0 ,: 1 1 1
]faces =: 6 2 3 $ facedata
0 0 0
0 1 1
0 0 0
1 0 1
0 0 0
1 1 0
1 1 1
_1 _1 0
1 1 1
_1 0 _1
1 1 1
0 _1 _1
NB. Exercise for the reader: write verbs to produce cubes and faces.
--Kip Murray
Kip Murray wrote:
> Consider a ,: b where a is a vertex and a+b is the diagonally opposite
> vertex. An equivalent "cube" with vertex at the origin n would be n ,:
> b . Think about it. Kip
>
>
> Raul Miller wrote:
>> I am looking for elegant ways of describing cubes in J.
>>
>> For example:
>>
>> points=: _1+2*#:i.8
>> surfaces=: 1 A. I. (, 1 - |.) 8&$...@#&0 1">4 2 1
>>
>> Here, points is a list of vertices and a vertex is
>> a list of xyz coordinates, and surfaces is a list
>> of polygons where a polygon is a list of
>> four vertex indices.
>>
>> Here, I consider 'points' to be elegant, but I am
>> looking for something more meaningful (and yet
>> still concise) for surfaces.
>>
>> Here is an example of an equivalent but more meaningful
>> expression for surfaces:
>>
>> surfaces=: 1 A."1 I. (#~ (1 e. [: */^:2 0: = points -"1/~...@#~ ])"1)
>> (#~ 4=+/"1)#:i.2^#points
>>
>> Here, I start by generating every combination of the available
>> points, choosing those combinations which have four
>> points, then choosing those combinations which are coplanar
>> and then rearranging them. This is somewhat meaningful
>> (though that 1 A. bothers me), but it is not concise.
>>
>> Does anyone have any good ideas for a meaningful
>> sentence to define 'surfaces'?
>>
>> Thanks,
>>
>
> ------------------------------------------------------------------------
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm