Now based on the model below, we get faces=: 4 : ',/((x ,:"1 x&+"1) ,:"1 y&-"1) y*=i.#y'
which finds representation of n-1 components of n-cube in n-space, i.e. faces of cube in 3D, sides of rectangle in 2D, points of segment in 1D etc. fold=: _2 ]\ <"2 NB. compact view fold 0 0 0 0 0 faces 1 1 1 1 1 +---------+---------+ |0 0 0 0 0|1 0 0 0 0| |0 1 1 1 1|0 1 1 1 1| +---------+---------+ |0 0 0 0 0|0 1 0 0 0| |1 0 1 1 1|1 0 1 1 1| +---------+---------+ |0 0 0 0 0|0 0 1 0 0| |1 1 0 1 1|1 1 0 1 1| +---------+---------+ |0 0 0 0 0|0 0 0 1 0| |1 1 1 0 1|1 1 1 0 1| +---------+---------+ |0 0 0 0 0|0 0 0 0 1| |1 1 1 1 0|1 1 1 1 0| +---------+---------+ fold 0 0 0 0 faces 1 1 1 1 +-------+-------+ |0 0 0 0|1 0 0 0| |0 1 1 1|0 1 1 1| +-------+-------+ |0 0 0 0|0 1 0 0| |1 0 1 1|1 0 1 1| +-------+-------+ |0 0 0 0|0 0 1 0| |1 1 0 1|1 1 0 1| +-------+-------+ |0 0 0 0|0 0 0 1| |1 1 1 0|1 1 1 0| +-------+-------+ fold 0 0 0 faces 1 1 1 NB. cf bottom: cr"_1 faces +-----+-----+ |0 0 0|1 0 0| |0 1 1|0 1 1| +-----+-----+ |0 0 0|0 1 0| |1 0 1|1 0 1| +-----+-----+ |0 0 0|0 0 1| |1 1 0|1 1 0| +-----+-----+ fold 0 0 faces 1 1 +---+---+ |0 0|1 0| |0 1|0 1| +---+---+ |0 0|0 1| |1 0|1 0| +---+---+ fold 0 faces 1 +-+-+ |0|1| |0|0| +-+-+ > From: Oleg Kobchenko <[email protected]> Very quick idea, not necessarily right. {(lx,ly,lz) ; (cx, cy, cz)} = {l ; c} = {location ; components} top y | | back left *----x right / bottom front/ z Faces: left: {l ; c - (cx, 0, 0)} right: {l + (cx, 0, 0) ; c - (cx, 0, 0)} bottom: {l ; c - (0, cy, 0)} top: {l + (0, cy, 0) ; c - (0, cy, 0)} front: {l ; c - (0, 0, cz)} top: {l + (0, 0, cz) ; c - (0, 0, cz)} > From: Kip Murray <[email protected]> > Be patient, a programming question is coming. I introduce a discussion of boxes with edges parallel to the coordinate axes. These boxes do not have to be cubes. They are identified by "located vectors" which are diagonals through the center of the box. Such a located vector uniquely determines the box, which in special cases can be a face or an edge. However, in three dimensions a box can be identified by eight different located vectors: these may begin at any of the eight corners of the box and pass through the center of the box to the diagonally opposite corner. Thus our first task is to identify a canonical representation of a box. I will do that below. Your task will be to write a verb that finds the faces of a box. A "located vector" is represented by a table a ,: h in which vector a gives the location of the vector's tail, and vector h contains the components, thus providing the direction and length of the located vector. The located vector goes from location a (the tail) to location a+h (the head). All of this makes sense in any number of dimensions; we can draw pictures in three dimensions (where #a and #h are both 3). Items of array "cubes" below are the eight vectors located at 0 0 0 which represent unit cubes: ]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 Items of array "faces" below represent the faces of the particular unit cube represented by 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 Verb cr (canonical representation) gives the "canonical" located vector representing a given box. In three dimensions the canonical located vector starts at the lower left rear corner of the box and proceeds to the upper right front corner. As a result its components are all positive. (Here is how I am drawing pictures in three dimensions with the axes labeled 0, 1, and 2: 2 | | |_________1 / / / 0 ) cr =: ( {. + 0.5 * [: (- |) {: ) ,: [: | {: cr"_1 cubes _1 _1 _1 1 1 1 _1 _1 0 1 1 1 _1 0 _1 1 1 1 _1 0 0 1 1 1 0 _1 _1 1 1 1 0 _1 0 1 1 1 0 0 _1 1 1 1 0 0 0 1 1 1 cr"_1 faces 0 0 0 0 1 1 0 0 0 1 0 1 0 0 0 1 1 0 0 0 1 1 1 0 0 1 0 1 0 1 1 0 0 0 1 1 DO YOU REMEMBER YOUR ASSIGNMENT? Write a verb that finds the faces of a box. That is, given a located vector representing the box, find located vectors representing the faces. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
