Fundamentals of basic GIS algorithms

Source: Internet
Author: User

As a GIS developer, no algorithm, too easy to be despised, so must seriously learn the algorithm, and constantly summed up, very grateful to the beginning of the entry, met a serious master. Good memory is better than bad writing, some basic geometric algorithms recorded, for follow-up inspection.

1, Vector concept: If the end of a line segment has a sequence of points, called a directed segment, if there is a point to the beginning of the line segment at the origin of the coordinates, called vectors.

2, vector addition and subtraction: P (x1,y1), Q (x2,y2), p+q= (X1+x2,y1+y2), p-q= (X1-x2,y1-y2). Apparently, P+q=q+p.

3, Vector cross product: is the line and line algorithm core, set vector P (x1,y1), Q (x2,y2), then p*q is to indicate the origin (0,0), p, Q, has p+q composed of parallelogram, p*q= (x1*y2-x2*y1). is a scalar.

Vector cross product of a very important attribute can be used to determine the position of two vectors, if p*q>0, then p in the clockwise direction of Q, if p*q<0, then p in the counterclockwise direction of Q, if p*q=0, then p, Q collinear, for the same direction or the opposite.

4, the broken line of the turn judgment: This can have a vector cross product to judge, for the public end of the P0P1,P1P2, then calculate p2-p0 multiplied by p1-p0, you can determine the turn of the polyline.

if (p2-p0) x (P1-P0) > 0, the P0P1 is p1p2 on the right after the P1 point.

if (p2-p0) x (p1-p0) <0, then p0p1 at P1 Point to the left and then get P1P2.

if (p2-p0) x (p1-p0) = 0, the P0P1P2 three points are collinear.

5. Determine if the line and segment intersect: If the segment p1p2 and line q1q2 intersect, the p1p2 crosses the Q1Q2, namely: (P1-Q1) x (q2-q1) * (Q2-Q1) x (P2-Q1) >= 0.

6, judge whether the rectangle contains points: Determine whether the horizontal and vertical axis of the pity Dorado is sandwiched between the left and right sides of the rectangle and the upper and lower edges.

7, determine whether line segments, polylines, polygons want the rectangle inside: Because the rectangle is a convex set, to determine whether all the endpoints are within the rectangle.

8. Determine if the rectangle is inside the rectangle: only the left and right edges and the upper and lower boundaries need to be compared.

9, determine whether the circle is in the rectangle: only need to judge the center of the rectangle, the radius of the circle is less than the center to the minimum distance of the rectangle.

10, determine whether the point in the polygon: to point to do the ray, see the number of intersections.



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.