P is for Practical  
PerlMonks 
comment on 
( #3333=superdoc: print w/replies, xml )  Need Help?? 
I have a world map with world events (like volcanoes, earthquakes, hurricanes, etc.) mapped on it. I also have buildings (like the Empire State Building) mapped on it. I can determine through simple math if an event is within N miles of a building. I've done this in Perl and translated the math to a mysql function, since these calculations are done at the database level.
But now I have a more complex sort of "building" to map. This isn't a building in a single place, it's essentially a path, like for a pipeline. The pipeline is defined by its vertices: every place the pipeline changes direction is a vertex (obviously). I want to determine now if an event is within N miles of this "pipeline". However, this is more than just checking each individual vertex of the pipeline, because it is possible for the event to be too far from a vertex to register a hit, yet close enough to a line drawn between the two vertices (which is the actual pipeline). I sort of know the math for this situation... I need to test for a point (X0,Y0) on the line from (X1,Y1) to (X2,Y2)  that's the pipeline  that is on the perimeter of a circle of radius R from point (X3,Y3)  that's the event. But I'm not sure I know how to convert that into lat/lng math for use in mysql. Any pointers? Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker Nos autem praedicamus Christum crucifixum (1 Cor. 1:23)  The Cross Reference (My Blog)

