I have a SQL call which brings me all the lat/lon station points in a radius. This works and is proven.
Now I need to find all the points of that group that fall in an arbitrary arc of say 90degrees. If the degrees are in one range, they are good, if outside that range, they are useless.
Let's ignore the fact that lat/lon are spherical coordinates and use Euclidean (plane) geometry. This is ok to do provided the points are not spread more than a few degrees apart and are not near a pole. (Otherwise, the problem becomes quite a bit more complicated.) However, we have to compensate for the latitude we're at. First, though, I will totally ignore the compensation factor, in case you don't want it.
From your message, I understand the problem to be this: relative to a point (x0, y0) and an angle a at that point, find a (simple) criterion to select all other points lying at an angle between a and a+90 degrees relative to (x0, y0). These points form a quadrant.
One way is to characterize the quadrant as the intersection of two half planes. If we can write a criterion for a point to fall within a specific half plane, then the conjunction of two such criteria will do the job.
The points to the left of a line passing through a point (x0, y0) making an angle of 'a' degrees (counterclockwise relative to the parallel through the point) all satisfy an equation of the form
c*(y-y0) - s*(x-x0) >= 0
In this case, c is the cosine of angle 'a' and s is its sine.
A simplification in your case is that your angles are 90 degrees apart. If one of them has (c, s) for its cosine and sine, then the other has (s, -c) for its cosine and sine. Thus your quadrant contains all points (x, y) satisfying this conjunction:
c*(y-y0) - s*(x-x0) >= 0 and s*(y-y0) + c*(x-x0) >= 0
If you prefer to use degrees east of north, then just switch c and s throughout.
It's ok to use constant positive multiples of c and s, too, because that does not change the inequalities.
Example: at 30 degrees north (latitude +30), 100 degrees west (longitude -100), with the quadrant extending from 45 degrees to 135 degrees (45 degrees east of north to 45 degrees west of north). Here, x0 = -100, y0 = 30, a = 45 so c = s = sqrt(2)/2. We can rescale c and s and choose c = s = 1 for simplicity. The criterion is
(y-30) - (x+100) >= 0 and (y-30) + (x+100) >= 0.
This simplifies further to
y-x >= 130 and x+y >= -70
You can check this by graphing the two inequalities.
Now let's consider compensating for the metric distortion at nonzero latitudes. On a spherical earth, one degree along the parallel (in the x direction) is actually only cos(latitude) = cos(y0) as long as one degree along the meridian. Thus, we should be rescaling (x-x0) by cos(y0) to make distances along the parallel (x-x0) comparable to distances along the meridian (y-y0). Writing d = cos(y0) gives the modified equation
c*(y-y0) - s*d*(x-x0) >= 0 and s*(y-y0) + c*d*(x-x0) >= 0.
Continuing the example, y0 = 30 degrees and d = cos(y0) = sqrt(3)/2 = 0.866, approximately. We can still rescale s and c to equal 1, so the quadrant is defined by
(y-30) - 0.866*(x+100) >= 0 and (y-30) + 0.866*(x+100) >= 0.
If you graph this (in the plane), it will appear to contain quite a bit _more_ than a 90 degree range of angles, but the corresponding region on the surface of the earth will indeed be a quadrant (at least locally).
On an ellipsoidal earth, d = cos(y0) is only an approximation. Unless your points are all within a few meters of the base point, however, the error in this approximation is so small (compared to the approximation involved in using plane geometry in the first place) that we can neglect it.
To summarize, given data x0, y0, and a, you need to compute c = cos(a), s = sin(a), and d = cos(y0). Your SQL statement can be modeled after the last, most general equation above, where x and y refer to the longitude and latitude (respectively) of the points to be selected.
For arbitrary sectors (not quadrants), your data are x0, y0, a1, and a2, say, where the sector spans all angles from a1 counterclockwise to a2, which is within 180 degrees of a1. Compute c1 = cos(a1), s1 = cos(a1), c2= cos(a2), s2 = cos(a2), and d = cos(y0) as before. The criterion is
c1*(y-y0) - s1*d*(x-x0) >= 0 and c2*(y-y0) - s2*d*(x-x0) <= 0.
(Note the less than sign in the right hand inequality.)
For comparable expressions in the plane (that is, using projected coordinates), omit the factor of d.
--Bill Huber Quantitative Decisions
--------------------------------------------------------------------- List hosting provided by Directions Magazine | www.directionsmag.com | To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Message number: 6175
