I have now struggled with a problem for a while so I finally resort to asking here in the hope somebody can help me, or at least give a few pointers. The problem is very simple, so I hope there is a simple solution also, that I just haven't seen. Here goes:
I have a list of coordinates (X,Y,Z) which I know form a rectangular grid with all datapoints within that rectangle existing in the list. However, the grid is rotated and translated, relative to a "normal" coordinate system. That is, if I do scatter(X,Y), I see the rectangle as a diamond shape (i.e., rotated) and shifted away from the origin (i.e., translated). The points are equally spaced.
What I would like is a matrix with the surface formed by the coordinates (X,Y,Z) so that row 1 in the matrix corresponds to all the Z values found along the lower edge of the rectangle, row 2 corresponds to the next row up, etc. In effect, I am thereby defining my own coordinate system like this, with axes parallel to the sides of the rectangle. Simple as that. Had the data not been rotated, this would of course be trivial, but since it is, I can't "travel" along, e.g., a row in the rotated grid and copy the Z values over to the right spot in a matrix, since a row is not a row in the "straight" coordinate system.
I of course know the angle and offset so I have tried to simply shift all points so that the lower left corner has (0,0) and then rotate the points with:
This works, however, this is not a very "nice" result, in that there are rounding issues causing the point spacing that I know to be an even number (500) no longer to be so. This, in turn makes is difficult to find the correct coordinates in my matrix for a given Z value.
So, how can I move around along a row in a rotated grid in a simple, efficient manner? Any suggestions?