Perl-Sensitive Sunglasses PerlMonks

### Re^2: Algorithm: point with N distance of a line between two other points

by japhy (Canon)
 on Nov 04, 2010 at 01:23 UTC ( #869380=note: print w/replies, xml ) Need Help??

Yes, LR, my initial idea had been to solve a quadratic equation and test the values of the two solutions. But I've found that Math::Geometry::Planar's DistanceToSegment() function works well with cartesian coordinates.

I'm facing two problems, though: 1) I'm starting with lat/long coordinates, not cartesian coordinates; and 2) I'd like the algorithm to run in a mysql query. I already have a GEO_DISTANCE(lat1,lng1,lat2,lng2) function in mysql, and I can reproduce DistanceToSegment() in mysql, but I'm not confident that DistanceToSegment() works appropriately with lat/long coordinates. Any ideas here?

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)
• Comment on Re^2: Algorithm: point with N distance of a line between two other points

Replies are listed 'Best First'.
Re^3: Algorithm: point with N distance of a line between two other points
by Limbic~Region (Chancellor) on Nov 04, 2010 at 02:05 UTC
japhy,
The shortest distance between two points on a sphere (forget that Earth is squished a bit) is the arc of the great circle passing between those two points so you may have reason for concern. You should read this and this (Cross-track distance). You may find that treating the surface of the sphere as a flat plane acceptable if your talking about a small enough area - otherwise, you need non-planar math.

Regarding your statement about MySQL query - I assume have no idea what built-in trig functions are available and I don't envy re-implementing them from scratch. If this were Pg, you could just use plperl and use the module that did what you wanted :-)

Cheers - L~R

Create A New User
Node Status?
node history
Node Type: note [id://869380]
help
Chatterbox?
 [shmem]: stevieb: in my case, it's just light controlling via some chip from the arduino family, and a couple of MPR121 sensor chips [shmem]: well finally. [stevieb]: nice! I just finished a GPS "take me home" device last week, and did a bunch of software updates to it yesterday. I also created a pseudo chip with an Arduino to simulate an IC, where it responds to register read/writes over the I2C bus...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2017-06-25 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How many monitors do you use while coding?

Results (572 votes). Check out past polls.