[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

2058.0. "Rotating Equaliteral Triangle Array" by RUSURE::EDP (Always mount a scratch monkey.) Thu Aug 22 1996 08:58

    Here's a not-too-hard problem I found a bit interesting.  I've got a
    rectangular array of equilateral triangles, indexed by row number r and
    column number c.  (Equilateral triangles can tile the plane with
    triangles fitting together in alternate orientations of pointing "up"
    and pointing "down".  If r+c is even, the triangle there points down;
    if r+c is odd, the triangle points up.)
    
    We want to rotate the triangles by 120 degrees around the center of the
    triangle at (0,0).  What are the new row-column coordinates of the
    triangle at (r,c)?  (Especially in C code.)
    
    
    				-- edp
    
    
Public key fingerprint:  8e ad 63 61 ba 0c 26 86  32 0a 7d 28 db e7 6f 75
To find PGP, read note 2688.4 in Humane::IBMPC_Shareware.
T.RTitleUserPersonal
Name
DateLines
2058.1use homogenous coordinatesTDCIS3::ROTHGeometry is the real life!Thu Aug 22 1996 13:4721
   Think of addressing the vertices of the triangles in
   "homogenous indices" (i,j,k) such that i+j+k = constant.

   The indices each select a line from each of 3 families
   of parallel ones that make up the sides of the
   triangles.  Rotation is by 120 degrees is then
   just cyclic permutation of the indices.

   This is as if you imbedded a plane in a 3 dimensinal
   cubic lattice in the manner of an "isometric view" from
   drafting.  The constraint i+j+k = constant is the
   equation of your plane, x+y+z = const.

   A triangle bounded by sides (i,j,k) will be even
   or odd depending on whether i+j+k = n-1 or n+1 and this
   is independant of whether you permute the indices,
   so you could address your triangles by any two of these
   indices along with this flag and it would then be trivial
   to "rotate".

   - Jim
2058.2answer with possibly flipped coordinatesFLOYD::YODERMFYThu Aug 22 1996 15:3033
I finished the derivation and then realized I had been using row numbers that
increased going up the page, as it were, rather than down.  Oh well, I'll give
the results anyway.

If you superimpose an x,y coordinate system with its origin at the center of the
(r=0,c=0) triangle, then x is a linear function of c, and if we consider only
those triangles with x+y even, y is a linear function of r.

Therefore rotation around (0,0) transforms (r,m) linearly with no messy
constants, i.e. (r',m') = (ar+bm, cr+dm), where I've used m for column in order
to avoid a variable name clash.

We know the rotation moves (1,1)->(0,-2) and (-1,1)->(1,1); adding and
subtracting gives (2,0)->(-1,-3) [so (2a,2c) = (-1,-3)] and (0,2)->(1,-1) [so
(2b,2d) = (1,-1)].

Thus (r',m') = (-r+m, -3r-m)/2 if r+m is even.

To get what happens when r+m is odd it is easiest to move up and to the left,
adding (0,-1) to (r,m), then rotate, then move up, adding (1,0).  This gives

  (r',m') = (-r+m-1,-3r-m+1)/2

or, combining cases, (r',m') = ((-r+m+b)/2, r'-r-m) where b = 1 if r+m is odd
and 0 otherwise.

Clearly b is the least significant bit of -r+m, so we can rewrite this as

  r' = ash(m-r+1,-1), m' = r'-r-m

where ash is an arithmetic shift.

Does this agree with your result?
2058.3RUSURE::EDPAlways mount a scratch monkey.Mon Aug 26 1996 09:3617
    Re .2:
    
    That's what I got except for the "+1".  That may be due to the
    orientation you selected.  I was surprised the C code came out so
    simply:
    
    	y_new = x-y >> 1;
    	x_new = y_new-x-y;
    
    Looking at that, you'd hardly imagine it is rotating by 120 degrees.
    
    
    				-- edp
    
    
Public key fingerprint:  8e ad 63 61 ba 0c 26 86  32 0a 7d 28 db e7 6f 75
To find PGP, read note 2688.4 in Humane::IBMPC_Shareware.