Calculate the closest and closest Line Segments

Source: Internet
Author: User

The last time I posted a post "know a little about recent points (ask questions)", I will discuss this issue further today. Last time, it was implemented based on the MapX control. Today, it is implemented based on text files instead of MapX.
Problem Review: if the point P (latitude and longitude) is known, the nearest vertex D (point, line, and surface) is found. The name of D is returned, and the direction, position, and distance between D and P are returned, the total number of features is greater than 0.5 million.
Current functions: generate a vertex to judge the coordinates, distance, and direction of the vertex closest to the vertex; generate a vertex and generate a line segment, determine the shortest distance from a point to a straight line (whether or not the vertical foot falls on the line segment ).
The general idea is to find the nearest vertex and traverse it. Find the closest point on the line segment, first judge the vertical foot, here is the product of the slope of the two vertical lines is-1, then judge whether the vertical foot falls on the line segment, that is, to determine whether the vertical foot is the smallest range rectangular frame of the online segment. If the vertical foot falls on the line segment, the shortest distance is the distance from the point to the vertical foot. If not, the shortest distance is the distance from the closest endpoint of the line segment.
Found OriginalAlgorithmThe problem is a mathematical problem. I am not good at mathematics. Alas, a simple problem has taken me quite a long time. None of the above optimizations were made, and the Earth coordinates were treated as Cartesian coordinates (a bit inappropriate, but I think this error may be acceptable when the speed is given priority ), if you think there are any optimizations, you are welcome to raise them. For example, when traversing, you should first determine whether the rectangle is located at a fixed distance near a known point.

Code: Http://files.cnblogs.com/Tangf/neardis_new.rar

The interface is shown as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.