Hi All
Given any two points on compass (Start range and End Range) to form a range. Example from 270(Start range) degrees to 45(End range)degrees and given another point say 7 , how can I work out if that point is between Start and End range ?
I'm trying to write some code to work out if the Wind (in the above point 3) is blowing from the sea or from the land , where the land is defind by Start range and End range .
Many Thanks Andy
Update:11/10/2010 18:46BST From @sth's solution the following seems to work for as expected.
#!/usr/bin/perl -w
sub isoffshore {
my ( $beachstart,$beachend,$wind) = @_;
if( $beachend < $beachstart) {
$beachend += 360;
}
if ($wind < $beachstart){
$wind += 360;
}
if ($wind <= $beachend){
print ("Wind is Onshore\n");
return 0;
}else{
print ("Wind is Offshore\n");
return 1;
}
}
isoffshore ("0","190","3"); #Should be onshore
isoffshore ("350","10","11"); #Should be offshore
isoffshore ("270","90","180");#Should be offshore
isoffshore ("90","240","0"); #Should be offshore
isoffshore ("270","90","180");#Should be offshore
isoffshore ("0","180","90"); #Should be onshore
isoffshore ("190","0","160"); #Should be offshore
isoffshore ("110","240","9"); #Should be offshore
isoffshore ("0","180","9"); #Should be onshore
isoffshore ("0","180","179"); #Should be onshore
Results
@localhost ~]$ ./offshore2.pl
Wind is Onshore
Wind is Offshore
Wind is Offshore
Wind is Offshore
Wind is Offshore
Wind is Onshore
Wind is Offshore
Wind is Offshore
Wind is Onshore
Wind is Onshore