Thread: I stink at math

1. I stink at math

Ok i am playing ultima online again, and when i play games i like to write tools for them,
from time to time, UO has a very large map, and info on how its structured is here
http://uo.stratics.com/uoam/geo.shtml

So, i read the clients memory, in a location i took time to find, and where your player stands,
the game returns tile coords, such as 2136.2085 which is the in game tile location of
my house on atlantic.

In the game, you can use a sextant, it displays a kind of latitude longitude, in a messed up way.
if i stand in the same spot in my house i got the above coords from, the sextant reads
40o 31' S 57o 9' E or 44 degrees 31 minutes north and 57 degrees 9 minutes east.

So, now i need to convert from the tile coords of 2136.2085 to the sextant coords of 40o 31' S 57o 9' E.

The page http://uo.stratics.com/uoam/geo.shtml kind of explains how to do this,
but it speaks of normalizing the output, and if you read it states the formulas he gives examples of
will cause the final calculation to be off by a degree and or a minute, or within a tile, which is exactly
what happens, so my question is, how would i normalize the output for a more accurate end result ?

Here is some VERY sloppy and slow code, this is not the way i should do this, but for me learning how to get
the formula correct, this does suffice.

Code:
public string ConvertToSextantString(int x, int y)
{
// Center of map for fel and tram
double centerY = 1624;
double centerX = 1323;
double mapY = 4096;
double mapX = 5120;
// Work with Y first
// Turn x into a double
string xDouble = string.Format(".{0}", x);
string yDouble = string.Format(".{0}", y);
double minsX = double.Parse(xDouble) * 60;
double minsY = double.Parse(yDouble) * 60;
double degreeY = ((y - centerY) * 360 / mapY);
double degreeX = ((x - centerX) * 360 / mapX);

// Returns 40.25390625o - 57.1640625'
string Y = degreeY.ToString();
string[] Ycoords = Y.Split('.');
string X = degreeX.ToString();
string[] Xcoords = X.Split('.');
// Like the guys webpage says, the second portion of this double value on each coord, needs to be multiplied by 60
// Pos S neg N
double Ymins = double.Parse(string.Format(".{0}",Ycoords.ToString())) *60;
// Pos E Neg W
double Xmins = double.Parse(string.Format(".{0}",Xcoords.ToString())) *60;
// If the Degree Output for Y is a positive number for N/S then its a South Degree, if its negative its a north
// If the Degree Output for X is a positive number for W/E then its a East Degree if negative its west
string NS = string.Empty;
string EW = string.Empty;
if (int.Parse(Ycoords) < 0) { NS = "N"; }
else { NS = "S"; }
if (int.Parse(Xcoords) < 0) { EW = "W"; }
else { EW = "E"; }
// Remove the - in front of any negative number
if (Ycoords.StartsWith("-")) { Ycoords = Ycoords.Substring(1); }
if (Xcoords.StartsWith("-")) { Xcoords = Xcoords.Substring(1); }
// Return all of our calculations formatted as a sextant output
return string.Format("{0}o {1}'{2} - {3}o {4}'{5}'",
Ycoords,
Math.Ceiling(Ymins),
NS,
Xcoords,
Math.Ceiling(Xmins),
EW);
}
Yeah i know, its confusing, but i am taking the chance one of yall are awsome at math Last edited by Pactor; 08-09-2013 at 10:23 PM.  Reply With Quote Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•