How to calculate the X,Y index of a cell in a matrix

imk

New member
Joined
Apr 7, 2023
Messages
16
Hello,
Imagine a sheet of graph paper where the center is the middle of a cell, and the center cell is addressed as 0,0
Given an angle and a distance from the middle of cell address 0,0 how do I calculate the address of the cell at the end of the line?
Tested on 10mm square graph paper from center of cell 0,0 looking 0 deg, at a distance of 50mm I get cell X0,Y5
Tested on 10mm square graph paper from center of cell 0,0 looking 315 deg, at a distance of 70mm I get cell X-5,Y5
I have read and read on this problem and always end up with the Cartesian math or ( X=Sin * Distance, Y=Cos * Distance )
Neither of which are correct or I have really really missed something.
Many thanks Ian
 
I have read and read on this problem and always end up with the Cartesian math or ( X=Sin * Distance, Y=Cos * Distance )
Neither of which are correct or I have really really missed something.
Why do you say that is incorrect?

It isn't clear how you are measuring angles (standard position, or starting at "north"? Clockwise or counter?) and counting cells (x horizontal and increasing to the right, y vertical and increasing upward, or otherwise?).

You'll also need to adjust for units and do some rounding in order to get integer indices, assuming that's what you want.

But for your formulas, given 70 mm at 315 degrees, I get
  • x=70sin(315)=49.5mmx=70\sin(315^\circ)=-49.5mm, which is index -4.95 and rounds to -5; and
  • y=70cos(315)=49.5mmy=70\cos(315^\circ)=49.5mm, which is index 4.95 and rounds to 5.
That's what you say you expect.
 
Hello Dr Peterson,
Really sorry for late reply, been busy with jobs etc.
Yes your/the math is correct, where I was going wrong is with the distance scaling from centre to the cell I am trying to find.
Many thanks again
 
Top