On 7/6/06, Idris Samawi Hamid wrote:
> Hi, Aditya,
>
> (I must admit I'm still struggling with mastering Mojca's approach ;-).

I guess that I should read this as "please comment your code better next time"

> pair diag[]; diag1 = (2,1.25); diag2=(10,-2.5);

I used diag1 to define the translation between the front and the back
face and diag2 to define the translation between the first and the
second cube.

for i=0 upto 1:
 for j=0 upto 1:
   for k=0 upto 1:
     for l=0 upto 1:
       z[i+2j+4k+8l] = (((i,j) scaled a) shifted (diag1 scaled k)
                 shifted (diag2 scaled l)) scaled u;
     endfor;
   endfor;
 endfor;
endfor;

i is the counter for x axes: i=0 means left, i=1 means the right point
j is the counter for y axes: j=0 means bottom, j=2 means the upper point

Original point will thus have coordinates (i,j) and we create 4 points
(sorry, I'm leaving out the braces):

z2---z3
|     |
z0---z1

k is the counter for z axes: z=0 means the front face, z=1 means the back face

The original point(s) are translated for diag1: shifted (diag1 scaled
k): if k=0, no translation is present, if k=1 it's translated to the
back.

You then get additional 4 poins, namely

z6---z7
|     |
z4---z5

traslated for vector diag1 to form the back face.

Finally, you use the counter l for the first and the second cube.
shifted (diag2 scaled l) doesn't do anything if l=0 ("shifted (diag
scaled 0)" is same as "shifted (0,0)" which is identity) and
translates the first cube into the second one when l=1.

z[...+8l] will number the points from 0 to 7 (depending on i,j,k) when
l=1 and from 8 to 15 when l=1, so you get the same points with index
of z increased for 8 if you're in the second cube.


> for i=0 upto 3:
> draw z[4i]--z[4i+1]--z[4i+3]--z[4i+2]--cycle;

this will draw:
- z0--z1--z3--z2--cycle (first cube, the front face)
- z4--z5--z7--z6--cycle (first cube, the front face)
- z8--z9--z11--z10--cycle (second cube, the front face)
- z12--z13--z15--z14--cycle (second cube, the front face)

> % small diagonals
> draw z[i]--z[i+4];
> draw z[i+8]--z[i+12];

this will draw
    z0--z4, z1--z5, z2--z6, z3--z7: "diagonals" connecting the front
face with back face and same for the second cube, only for z[index+8]

> draw z[i]--z[i+8];

this will connect the fron face of the first cube with the fron face
of the second cube (+8)

> draw z[i+4]--z[i+12];

same, bu for the back face; this could be done with the first
definition already if 'i' went from 0 to 7 instead from 0 to 3.

> label (textext("Sans Serif"),.5[z[3],z[4]]) ;

z3 is the upper right point in the front face and z4 the lower left
point in the back face, .5 is the point in the middle then.

> label (textext("Serif"),.5[z[11],z[12]]) ;

z11 and z12 are the same points (3+8 and 4+8) on the second cube.

Hope that helps,
    Mojca

(Asymptote does some conversions directly since it supports 3D, but I
never worked with it, most probably because it's not integrated so
well with ConTeXt, although it seems a bit more optimistic in the last
time.)
_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

Reply via email to