Nav nav mesh pathfinding (3)--Some necessary computational geometry knowledge

Source: Internet
Author: User

This article is a turn, the original http://blianchen.blog.163.com/blog/static/13105629920103614613291/

Before continuing with the following NAV mesh generation algorithm, let's introduce the computational geometry involved. Here are only a list of the conclusions, to learn more about the reference related books.

  • Vector Plus subtraction:
    To set the two-dimensional vector p = (x1, y1), Q = (x2, y2), the vector addition is defined as: P + Q = (x1 + x2, y1 + y2), and similarly, vector subtraction is defined as: P-q = (x1-x2, y1-y2). Obviously there is a nature P + q = q + p,p-q =-(q-p).
  • Vector Cross Product
    With vector P = (x1, y1), Q = (x2, y2), the vector fork product is defined as a signed area of 0,0 consisting of (P1), p2, p1+p2, and parallelogram, that is: Pxq = x1*y2-x2*y1, and the result is a scalar. Obviously there are properties Pxq =-(QXP) and PX (-Q) =-(PXQ).
  • To determine the turn of a broken segment:
    The method of turning judgment of the broken segment can be directly introduced by the character of the vector cross product. For segments P0p1 and p1p2 with a common endpoint, you can determine the turn of a broken segment by calculating the symbol (P2-P0) x (p1-p0):
    if (p2-p0) x (P1-P0) > 0, then p0p1 to the right after P1 point to get p1p2.
    if (p2-p0) x (P1-P0) < 0, then P0P1 to the left after P1 point to get p1p2.
    if (p2-p0) x (p1-p0) = 0, then the P0, P1, p2 three points collinear.
  • Determine if two segments intersect:
    We determine whether two segments intersect in two steps:
    (1) Rapid rejection test
    The rectangle with the diagonal line p1p2 is R, the rectangle with the segment q1q2 diagonal is T, and if R and T do not intersect, it is obvious that the two segments do not intersect.
    (2) Cross-stand test
    If two segments intersect, the two segments must cross each other. If P1p2 crosses the q1q2, the vectors (p1-q1) and (P2-Q1) are on either side of the vector (Q2-Q1) (P1-Q1) x (q2-q1) * (P2-Q1) x (Q2-Q1) < 0 。 The above formula can be changed to (P1-Q1) x (q2-q1) * (Q2-Q1) x (P2-Q1) > 0. When (P1-Q1) x (q2-q1) = 0 o'clock, the description (P1-Q1) and (Q2-Q1) collinear, but because of the rapid rejection test, so P1 must be on the line segment q1q2; Similarly, (Q2-Q1) x (p2-q1 ) = 0 indicates that the P2 must be on the segment q1q2. So the basis for judging p1p2 q1q2 is: (p1-q1) x (q2-q1) * (Q2-Q1) x (P2-Q1) >= 0. Similarly, the basis for judging q1q2 p1p2 is: (Q1-P1) x (P2-P1) * (P2-P1) x (Q2-P1) >= 0.
  • Convex polygon
    Suppose we take two points on a polygon (including the boundary of the polygon and the bounding envelope of the boundary) and link the two points with a line segment, and if each point on the line is on that polygon, then we say that the polygon is convex.
  • Convex bag
    A set of (finite) points on a given plane (that is, a set of points), the convex hull of the point set is a convex polygon that contains the smallest area of all points in a point set.
  • The judgment of point in convex polygon
    Assuming that the polygon is convex, and that the vertex p0,p1,..., PN in a clockwise direction, the point is pi-1 on either side of the polygon, and the pi is to the right.
  • Voronoi graphs and Dual graphs
  • Delaunay triangulation (Voronoi dual graph)

    The most commonly used triangulation in practice is Delaunay triangulation, which is a special triangulation. Start with the Delaunay side:
    "Definition" Delaunay edge: Suppose an E in an edge E (two endpoints is a, A, b), E if the following conditions, it is called Delaunay edge: There is a circle through a, b two points, the circle (note is within the circle, the circle on a maximum of three points round) does not include any other points in the point set V, This feature is also known as the Empty Circle feature.
    "Definition" Delaunay triangulation: If a triangulation t of Point set V contains only Delaunay edges, then the triangulation is called a triangulation of Delaunay.
    Here are the excellent features of the Delaunay split:
    1. Closest: A triangle is formed at the nearest three points, and each segment (The edge of the triangle) does not intersect.
    2. Uniqueness: No matter where you start building from the region, you will eventually get a consistent result.
    3. Optimality: The diagonal of the convex quadrilateral formed by any two adjacent triangles if interchangeable, then the smallest angle in the six inner angles of the two triangles does not become larger.
    4. Most rule: If the minimum angle of each triangle in the triangular network is arranged in ascending order, the Delaunay triangular network is arranged to get the highest value.
    5. Culture: Adding, deleting, and moving a vertex only affects the neighboring triangles.
    6. Shell with convex polygon: the outermost boundary of the triangular network forms a convex hull.
  • Polygon Clipping


    Weiler-athenton algorithm

– Main polygon: Clipped Polygon, recorded as a

– Crop polygon: Crop window, record as B

The order in which the polygon vertices are arranged (so that the polygon area is on the left side of the forward edge) outer ring: counterclockwise; inner ring: Clockwise

The main polygon and the clipping polygon divide the two-dimensional planar plane into parts.

Inside Cut: A∩B

Outside cut: A-B

The boundary of the clipping result area is composed of part boundary of a and part boundary of B, alternating at the boundary of intersection, that is, the boundary of a is transferred to the boundary of B, or the boundary of B is transferred to the boundary of a.

If the main polygon has an intersection with the clipping polygon, the intersection appears in pairs, which are divided into the following two classes:

in point : The main polygon boundary is thus entered within the clipping polygon such as, I1,i3, I5, I7, I9, I11

out point: the main polygon boundary leaves the clipping polygon area. such as, I0,i2, I4, I6, I8, I10

Algorithm steps

(1) Create an empty vertex table for the cropped result polygon.

(2) Select any non-tracked intersection as the starting point and output it to the result polygon vertex table.

(3) If the intersection is an in point, the edge of the main polygon is traced, otherwise the clipping polygon boundary is traced.

(4) Trace the polygon boundary, and output it to the resulting polygon vertex table each encounter of the polygon Vertex until a new intersection is encountered.

(5) Output the intersection to the result polygon vertex table and change the tracking direction by the bidirectional pointer connecting the intersection (if the previous step is tracking the main polygon boundary, the clipping polygon boundary is now tracked instead, and if the previous step tracks the clipping polygon boundary, the main polygon boundary is now tracked instead).

(6) Repeat (4), (5) until you return to the starting point

Nav nav mesh pathfinding (3)--Some necessary computational geometry knowledge

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.