C
cerr
Hi There,
I need to do some calculations with GPS coordinates and i get all
weird values and i can't see where i'm going wrong.
My code:
The explanation the first lines are GPS coordinates from a polygon and
i take the average from the 4 points to figure out the centre of the
polygon (I know, geometrically it's not 100% correct but I figured
this should be good enough for me/my polygons) anyways I multiply it
by 10,000,000 in order to get rid of the digits pst the decimal point.
Then after the division by 4 i get two decimal places back....
then i add the numbers to a map in order to be able to easily access
them. type xy is a class with two double variables, x and y. This is
how my globals are declared:
map<int, xy>AvgHashTable;
xy TopLeft;
xy BottomRight;
Then i wanna loop through all the elements and figure out the largest
and the smallest value...
somewhere my double values get screwed and i have all weird numbers in
BottomRight as well as in TopLeft
Now my source values are all in the format with 7 decimal numbers. And
in the end I have in TopLeft.x 49.213812599999997 and in BottomRight.x
I got 49.281173000000003... The y values look good for both... any
ideas why these numbers look so awkwardly?
Thanks,
Ron
I need to do some calculations with GPS coordinates and i get all
weird values and i can't see where i'm going wrong.
My code:
Code:
// calculate the average xy coordinates out of the
polygon's corner points
double CinXAvg =((((sphericalpolygon *) curApproach-[QUOTE]
getCheckInPolygon())->getCornerPoints()->at(0).x +[/QUOTE]
((sphericalpolygon *) curApproach-[QUOTE]
getCheckInPolygon())->getCornerPoints()->at(1).x +[/QUOTE]
((sphericalpolygon *) curApproach-[QUOTE]
getCheckInPolygon())->getCornerPoints()->at(2).x +[/QUOTE]
((sphericalpolygon *) curApproach-[QUOTE]
getCheckInPolygon())->getCornerPoints()->at(3).x)*10000000)/4;[/QUOTE]
double CinYAvg =((((sphericalpolygon *) curApproach-[QUOTE]
getCheckInPolygon())->getCornerPoints()->at(0).y +[/QUOTE]
((sphericalpolygon *) curApproach-[QUOTE]
getCheckInPolygon())->getCornerPoints()->at(1).y +[/QUOTE]
((sphericalpolygon *) curApproach-[QUOTE]
getCheckInPolygon())->getCornerPoints()->at(2).y +[/QUOTE]
((sphericalpolygon *) curApproach-[QUOTE]
getCheckInPolygon())->getCornerPoints()->at(3).y)*10000000)/4;[/QUOTE]
//save the average value in a hash table so we can later
go ahead and find the outest polygons
xy AvgCIN(static_cast<double>(CinXAvg/10000000),
static_cast<double>(CinYAvg/10000000));
AvgHashTable[AvgHashTable.size()]=AvgCIN;
}
}
for (int i=0; i < AvgHashTable.size(); i++) {
if (i==0) {
TopLeft.x=AvgHashTable[i].x;
TopLeft.y=AvgHashTable[i].y;
BottomRight.x=AvgHashTable[i].x;
BottomRight.y=AvgHashTable[i].y;
}
else {
if (AvgHashTable[i].x < TopLeft.x)
TopLeft.x=AvgHashTable[i].x;
if (AvgHashTable[i].y < TopLeft.y)
TopLeft.y=AvgHashTable[i].y;
if (AvgHashTable[i].x > BottomRight.x)
BottomRight.x=AvgHashTable[i].x;
if (AvgHashTable[i].y > BottomRight.y)
BottomRight.y=AvgHashTable[i].y;
}
}
i take the average from the 4 points to figure out the centre of the
polygon (I know, geometrically it's not 100% correct but I figured
this should be good enough for me/my polygons) anyways I multiply it
by 10,000,000 in order to get rid of the digits pst the decimal point.
Then after the division by 4 i get two decimal places back....
then i add the numbers to a map in order to be able to easily access
them. type xy is a class with two double variables, x and y. This is
how my globals are declared:
map<int, xy>AvgHashTable;
xy TopLeft;
xy BottomRight;
Then i wanna loop through all the elements and figure out the largest
and the smallest value...
somewhere my double values get screwed and i have all weird numbers in
BottomRight as well as in TopLeft
Now my source values are all in the format with 7 decimal numbers. And
in the end I have in TopLeft.x 49.213812599999997 and in BottomRight.x
I got 49.281173000000003... The y values look good for both... any
ideas why these numbers look so awkwardly?
Thanks,
Ron