#! perl -slw
use strict;
use enum qw[ IMAGENO MINLAT MAXLAT MINLON MAXLON ];
sub overlapLat {
my( $a, $b ) = @_;
return
if $a->[MINLAT]+90 > $b->[MAXLAT]+90
or $a->[MAXLAT]+90 < $b->[MINLAT]+90;
return 1;
}
sub overlapLon {
my( $a, $b ) = @_;
return
if $a->[MINLON]+360 > $b->[MAXLON]+360
or $a->[MAXLON]+360 < $b->[MINLON]+360;
return 1;
}
##discard header
<DATA>;
my @rects = map[ split ',' ], <DATA>;
for my $first ( 0 .. $#rects ) {
for my $second ( $first + 1 .. $#rects ) {
if( overlapLat( @rects[ $first, $second ] )
and overlapLon( @rects[ $first, $second ] )
) {
print "@{$rects[ $first ] } overlaps \n@{ $rects[ $second
+] }";
}
}
}
__DATA__
"Image number","minlat","maxlat","minlon","maxlon"
...
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
Why reinventing the wheel?
Clipping algorithms are the basis of most computer graphics book.
IMHO Cohen–Sutherland is quite straight forward...
Nota bene: you need spherical geometry to calculate "lines" (great circles) connecting "corners". But then it's the same principle.
Latitudes are not the shortest connections between 2 points!!!
| [reply] |
This is no problem
All you have to do is be careful how you define your min and max longitude. If an area starts at longitude 350 and is 20 clicks wide going to 10, then your minimum longitude is 350 and max is 10. The same algorithm works that either I and BrowserUk provided
If your data is defined so that it gives you a range of 350-370, then all you need to is take modulus 360 of your data ($max = $max % 360). Same thing is true if it's -10 to 20 ($min = $min % 360).
There's no reason to touch latitudes, as they won't ever be outside of the -90 to 90 range.
| [reply] [d/l] [select] |
There's no reason to touch latitudes, as they won't ever be outside of the -90 to 90 range.
Satellites that do global imaging tend to fly in polar orbits. So, it possible to imagine an image taken when the sat is directly over the pole, (I think that this is technically infeasible, but they can get pretty damn close), that has coordinates for its four corners:
(85,45) 90 (85,135)
+--------|--------+
| | North |
| | Pole |
| | / |
0/360 +--------0--------+ 180
| | |
| | |
| | |
+--------|--------+
(85,315) 270 (85,225)
If that was represented by the OPs minlat/maxlat, minlon/maxlon system, then you get: nnn, 85, 85, 0, 360 which isn't going to play well for overlap detection.
The simplest fix is to break such transition images into two (or 4) parts: nnn-a, 85, 90, 0, 180
nnn-b, 85, 90, 180, 360
But even then, the distortions that occur at high latitudes screws the math as soon as you start doing any trig, so spherical coordinates become pretty much de rigueur.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |
Aye. However, your example image isn't exactly representative of what his coordinates would define, which would be two adjacent pie slices instead of a full rectangle. I doubt that his data would work that way, but yes anything is possible.
Your solution of breaking up the wierd region would work though, yes. For MaxLong > 90
MinLat, MaxLat, MinLong, MaxLong
to
MinLat, MaxLat, MinLon, 90
# and
(MinLat+180)%360, (MaxLat+180)%360, 180-MaxLong, 90
| [reply] [d/l] [select] |