16 August 2008

Going off the deep end with geometry

[Warning to Nathan: Lots of math is about to ensue. You might want to cover your eyes...]

Yesterday it took me all night to learn that single precision numbers and double precision numbers are not at all the same thing. Not that Matlab will tell you this, of course. They'll look exactly the same to the untrained eye. No, you have to specifically ask, using an obscure function such as superiorfloat(). All Matlab will do is inexplicably refuse to make straightforward plots of those numbers until after you change them.

Today I learned that it's quite difficult to rotate the axes of a cartesian system to anything other than 90 degrees, especially if you've never learned any math past calculus (and you didn't do so good in calculus).

There's:
origin=newpole(polelat, polelon);
[lat_rotate,lon_rotate] = rotatem(lat, lon, origin, 'forward', 'degrees');

... which will indeed do some rotating of the data. However, the end result won't bear much resemblance to what you had at the start.

Then (via John) there's:
xdist = sqrt(((m*lat - m*b) ./ (1 + m^2)).^2 + (((1-m^2)*lat - b + b*m^2 + m*lon) ./ (1 + m^2)).^2);
or
xdist = sqrt((((lon + m*lat + m*b) / (m + 1/m)) + b - lat).^2 + (((lon/m + lat + b) / (m + 1/m)) - lon).^2);

... which uses linear algebra and vectors and dot products and all sorts of stuff that go completely over my head. I have no clue how the equations got derived, only that they don't seem to do what I want them to, and I don't know how to fix them. Also it occurred to me while I was fiddling with them that they'll only give me the x values, not the y values...

Snave tells me it's simple. Those matrices look scary to me. o.O

On Monday I'll reveal my utter ignorance to the local Matlab expert, and maybe she'll figure out how to do all this for me. Either that or I'll abandon this foray and go to Plan B (which is to do what my boss actually asked for as opposed to what he wants (and will probably be asking for when he finds out that what he asked for won't be sufficient)).

5 comments:

Nathan said...

[Warning to Nathan: Lots of math is about to ensue. You might want to cover your eyes...]

Either that or I'll abandon this foray and go to Plan B (which is to do what my boss actually asked for as opposed to what he wants (and will probably be asking for when he finds out that what he asked for won't be sufficient)).


What's the special significance of those two sentences? They're the only two in the entire post that I understood.

Good luck with you foray. Foray's are good.

Tom said...

AAAA (for Nathan. He seems to like forays)

The matrix I referenced shows translation around the origin. To rotate in place, you have to translate to the origin, rotate around the origin, then translate back to the original locale. If your approximate center of rotation is +a,+b then subtract a from all x coordinates, and subtract b from all y coordinates (translating the center of rotation to the origin), then apply the rotation around the origin. Then add a to all x coordinates, and add b to all y coordinates (translating the center of rotation back to the original locale).

It seems easy to me... :)

(Darn typos. Maybe I'll learn to proofread before hitting submit)

MWT said...

Nathan: lemme see if I can translate those two sentences better. The first one says "Nathan might want to cover his eyes."

The second one says "I wish I could cover my eyes too."

:p

Tom: Translation! That might be what I'm missing... I'll try that.
*wanders off to try again*

MWT said...

Well that didn't work...

Here's what I'm doing:

angle = 0.5235987756;
[30 degrees --> 0.5235987756 radians]

origin = (-81.5, 31.5)

x=lon072chl;
y=lat072chl;

x_origin = lon072chl +81.5;
y_origin = lat072chl - 31.5;

new_x_origin = x_origin * cos(angle) - y_origin * sin(angle);
new_y_origin = x_origin * sin(angle) + y_origin * cos(angle);

new_x = new_x_origin -81.5;
new_y = new_y_origin +31.5;

... this results in a pool of data points that still point in the same diagonal direction as before, except now it's slightly misshapen.

Nathan said...

Damn,

You'd think I would have learned to stay outta this room.

(I snorted from the translation, though.)