Coordinate order in Array2D

Mike Klein mike at twinsun.com
Wed Jan 21 05:04:11 UTC 1998


> Cristopher Oliver wrote:
> 
> CO> Hey folk!  Why does Array2D at:at: and at:at:put: use a coordinate
> order reversed from normal mathematical conventions?  The first
> coordinate is traditionally the matrix row.  I just got bitten while
> transliterating some cryptology code using matrices.  This sort of
> difference can cause severe brain hemorrhage.
> 
> I don't know why Array2D have this coordinate order but please note that the traditional matrix 
notation, in which the first index is the row, opposes to the also traditional (x, y) order. 
Smalltalk uses the (x , y) order in the class Point, so using first the column (x) and then the row 
(y) seems to adhere to a homogeneous convention.
> 
> Saludos,
> Leandro

Personaly, In my Matrix classes, I use the selector

	down:accross:

this way I never have to remember, (Unless you are used to reading
right to left...  this is an international list :-)

You can then add to Matrix:

down: i accross: j
	^self at: j at: i
	
	
Also, notice that Point reverses the sign of the traditional y-axis orientation, but
in math, it is ordinary for matrices to be numbered downwards.

The moral of the story is that in math, there are all sorts of natural isomorphisms
which we use painlessly, but in CS, these may not seem so natural.

The coordinates of a location in a 2-d axis-aligned euclidean plane bears
as much resemblance to matrix indeces as  an Array of Booleans resembles an Integer.

-- Mike Klein
	





More information about the Squeak-dev mailing list