?

Log in

No account? Create an account
I have just noticed something that I think has been annoying me on a… - Sally's Journal
April 5th, 2006
12:12 pm

[Link]

Previous Entry Share Next Entry
I have just noticed something that I think has been annoying me on a subconcious level for years.

If you write things in cartesian coordinates, you write (x,y)

But if you write things in matrix notation, you write (row, column)
and if you write out your matrix in a grid... the row number will increase as you go down the grid, and look an awful lot like a y coordinate, and the column number will increase as you go across the grid, and look an awful lot like an x coordinate. So you're almost writing (y,x)

My brain hurts.

(25 comments | Leave a comment)

Comments
 
[User Picture]
From:pjc50
Date:April 5th, 2006 11:31 am (UTC)
(Link)
That too has annoyed me for years, especially in the context of graphics versus text programming - text coordinates are usually (row, column).
[User Picture]
From:atreic
Date:April 5th, 2006 11:47 am (UTC)
(Link)
Yes. I was trying to write an array that said if a square had a tile in it or not, and the mapping from the x,y co-ordinates of the squares to the members of the array was the thing that finally made it click.
[User Picture]
From:smhwpf
Date:April 5th, 2006 11:32 am (UTC)
(Link)
Do you know, that had never occurred to me, but it's true! And it probably is one of the things that makes playing with matrix formulae that bit trickier.

For bonus head-hurt - I wonder if you'd look at it differently if you wrote in a semitic language (Hebrew, Arabic, etc.) that reads from right to left?
[User Picture]
From:requiem_17_23
Date:April 5th, 2006 11:35 am (UTC)
(Link)
Ah.... *that's* why I keep persistently writing it the wrong way round....
[User Picture]
From:phlebas
Date:April 5th, 2006 11:37 am (UTC)
(Link)
Or even (n-y,x) !!!
[User Picture]
From:filecoreinuse
Date:April 5th, 2006 12:05 pm (UTC)
(Link)
Don't forget that the 'origin' of matrices is row 1, column 1 not (0,0). Generally it doensn't bother me. It is simply a typing problem. All co-ordinates have an associated frame which they are relative to that can be expressed notationally. For example in my line of work we generally have world, view and screen spaces which we keep track of by a) prepending w/v/s to the variable [1] and b) making sure that lines which do wFoo = vBar are looked at very carefully and documented.

[1] Horribly Hungarian.
[User Picture]
From:atreic
Date:April 5th, 2006 12:08 pm (UTC)
(Link)
This array seems to think its origin is [0][0]...
[User Picture]
From:filecoreinuse
Date:April 5th, 2006 12:22 pm (UTC)
(Link)
The origin or arrays in computer science[1] is 0 but mathematically one usually has the first element being 1. So the first element of a matrix $A$ with elements $a_{ij}$ is $a_{11}$ but the first element of a C-style 2d array float A[N][M] is A[0][0]. Further the element $a_{ij}$ is the jth element in the ith row as is A[i][j] in programming[2].

[1] Not for FORTRAN. It uses the mathematical convention.
[2] Again, not for FORTRAN.
[User Picture]
From:filecoreinuse
Date:April 5th, 2006 12:24 pm (UTC)
(Link)
Whoops. Correct my last statement there.
[User Picture]
From:cartesiandaemon
Date:April 5th, 2006 12:14 pm (UTC)
(Link)
Wonderfully hungarian! OK, if you declare them as different types (wint, vint, etc), your editor would *hopefully* flag it in some way, and maybe even your compiler check if you've been anal enough, but I think that extra letter is surely worth it to be able to see which the variable is -- you can't rememeber all the time, and every time you get muddled you lose minutes of productivity :)
[User Picture]
From:simont
Date:April 5th, 2006 12:15 pm (UTC)
(Link)
It is a pain, that. I tend to see matrices in particular as a special case: matrices are written as HxW and coordinates within them as (r,c) because that way the nearby dimensions cancel during multiplication: a 3x4 matrix multiplied by a 4x5 one gives a 3x5 one, and an element cij of the result is given by the sum of aikbkj over all k. If the dimensions and coordinates were written in x,y order, all that would look much weirder.

(You could of course solve this problem by reversing the conventions of matrix multiplication at the same time, but I don't think the inventors of matrices can reasonably be blamed for not realising that the first way round that sprang to mind would give rise to this confusion. It's a shame, but it's too entrenched to change really.)

Everything other than matrices really ought to be x,y, on the grounds that one should follow a near-universal standard unless there's a specific good reason not to. A few things in computing get this wrong, and they annoy me a lot more than matrices because they have no excuse.
[User Picture]
From:cartesiandaemon
Date:April 5th, 2006 12:27 pm (UTC)
(Link)
We could all change over on the same date we switch the playing card suite order and side of the road we drive on :)

But yes, what he said. Though I'm not sure if you *could* rearrange everything to make all coordinates be in that order, or if you end up with some cases that don't work out as well.

Everything other than matrices really ought to be x,y, on the grounds that one should follow a near-universal standard unless there's a specific good reason not to.

I can't decide. Probably. Though there's also something to be said for just always specifying.
[User Picture]
From:cartesiandaemon
Date:April 5th, 2006 12:25 pm (UTC)
(Link)
And of course, if your drawing these planes on a computer, you typically prefer pixels[y][x] at least internally, because then your raster lines are stored together internally.

*Actually* -- that is somewhat similar to matrices.

Let capital letters be matrices, small letters be column vectors, and subscripts be y,x indices. Vectors and matrices dimension n or nxn.

You often think of A as an function A: v -> Av. But you can usefully break this down into n functions, each of which is a row of A, a row vector, which takes v to one element of Av.

If your y subscript is first, you can write the rows as A1: v -> (Av)1 by leaving off the x subscript.

If you reversed the order, you'd have to say A(.),1 to mean the row vector, or have the function be a post multiplier of a row vector by the matrix, allowing column vectors to be the components.
[User Picture]
From:king_of_wrong
Date:April 5th, 2006 12:29 pm (UTC)
(Link)
Matrices are broken. Just transpose them and it'll be fine...

Of course, there's then the problem with left-handed vs right-handed coordinate systems (i.e. does y go up or down?)
[User Picture]
From:gerald_duck
Date:April 5th, 2006 01:11 pm (UTC)
(Link)
Hell, yeah.

I recently implemented the graphics subsystem for our product. I used cartesian co-ordinates, with y increasing up the screen.

Now everyone's complaining that they want to lay things out down the screen, so it's having to be changed.

Fortunately, I wrote most of the low-level code properly and it's completely agnostic about this, so the change is tidier than it might have been.
[User Picture]
From:king_of_wrong
Date:April 5th, 2006 01:14 pm (UTC)
(Link)
I thought everyone knew that (0,0) was the top-left corner of the screen...? ;)
[User Picture]
From:fanf
Date:April 5th, 2006 02:20 pm (UTC)
(Link)
gerald_duck is an Acorn weenie so has Y positive upwards.
From:wildfyre
Date:April 5th, 2006 03:03 pm (UTC)
(Link)
Glad I'm not the only one who struggles with that :-)
[User Picture]
From:arnhem
Date:April 5th, 2006 03:12 pm (UTC)
(Link)
A colleague has been getting very irritated by the fact that in his area, the measurement of change of thickness in a lump of stuff you're compressing is (by convention) positive if it's been squashed ...
[User Picture]
From:serenasnape
Date:April 5th, 2006 03:16 pm (UTC)
(Link)
I KNEW I shouldn't have clicked to read the comments ... I didn't even understand matrices at GCSE and now my head has exploded - more with a whimper than a bang, I fear!
[User Picture]
From:samholloway
Date:April 5th, 2006 09:56 pm (UTC)
(Link)
When I first met matrices, this upset me a lot. I had to mentally store that matrices had their co-ordinates "the wrong way round".

However, I've now learnt to treat the two systems separately. Cartesian is (x,y), and has its origin in 'the bottom left'. Matrices are (y,x) and have their origins in 'the top left'. And as I'm a C++/C# developer by trade, they all start from (0,0). :-)
[User Picture]
From:cowe
Date:April 5th, 2006 11:41 pm (UTC)
(Link)
Meh, it's just a rotation. Lie on your side.
From:yrieithydd
Date:April 5th, 2006 11:51 pm (UTC)
(Link)
I remember in year 7 doing map references and latitude and longitude. My memory is that grid references are eastings then northings (so like cartesian co-ordinates, I think, but I might just be horribly confused) whereas you give lat-long which is like matrices (from what you've said). I definitely remember them being different. It's liveable with; as is the fact that the mixer taps have hot and cold the other way round from the non-mixer taps in this house!
[User Picture]
From:jdc39
Date:April 6th, 2006 03:33 pm (UTC)
(Link)
I try not to relate the two, though mainly because it took nearly 3 years of undergrad maths to figure out which matrix labels were which.

Every time I've had to code matrix multiplication up the trick is to just be consistent rather than know the convention, e.g. once I scribbled lots of code on paper which happened to be correct but when I began explaining it to someone I was instantly lost.

Because of the difficulty of matrix labels versus knowing Cartesian coordinates for over 10 years, I can't really connect them in my head.
From:emarkienna
Date:April 7th, 2006 11:46 pm (UTC)
(Link)
I'm okay with remembering row then column for matrices, but I hate looking at computer code dealing with matrices, as I'm never quite sure which way the arrays are specified.
Powered by LiveJournal.com