Shortest distance between a point and a line segment

Eli, the code you’ve settled on is incorrect. A point near the line on which the segment lies but far off one end of the segment would be incorrectly judged near the segment. Update: The incorrect answer mentioned is no longer the accepted one. Here’s some correct code, in C++. It presumes a class 2D-vector … Read more

Calculate distance between 2 GPS coordinates

Calculate the distance between two coordinates by latitude and longitude, including a Javascript implementation. West and South locations are negative. Remember minutes and seconds are out of 60 so S31 30′ is -31.50 degrees. Don’t forget to convert degrees to radians. Many languages have this function. Or its a simple calculation: radians = degrees * … Read more

How do you detect where two line segments intersect? [closed]

There’s a nice approach to this problem that uses vector cross products. Define the 2-dimensional vector cross product v × w to be vx wy − vy wx. Suppose the two line segments run from p to p + r and from q to q + s. Then any point on the first line is representable as p + t r (for a scalar parameter t) and any point … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)