"Introduction to Algorithm"-chaper33-computational geometry

Source: Internet
Author: User

Cross product:

In order to measure the tilt state of a straight line in the plane, we introduce the concept of inclined angle. By establishing tanα= K in a Cartesian coordinate system, we realize the connection between geometric relations and algebraic relationships, which in fact is a core of solving geometrical problems with computers, and the computer is doing numerical operations, so what you need to do is to express the relations in algebraic relation. In space, in order to indicate the degree of inclination of a plane relative to the spatial Cartesian coordinate system, we measure it by a normal vector of the plane perpendicular to it (as this translates into a problem that describes the degree of linear tilt).

Defined:

The operation of vectors conforms to the following algebraic laws.

Obviously this definition we do not like, because it is still too low in algebra, mainly because the sine of the angle is not easy to find, but this does not affect the definition of the importance of the application, the following problem we need to solve is to find an equivalent algebraic degree of a higher definition.

Determinant formula for cross-product:

The ① formula is the modulus length of the normal vector obtained by the cross-multiplication, because the stipulation in the right-hand rule θ≤π, so the ① both sides must be greater than or equal to zero. But now we do some great things, through the basic definition and the direction of our right-hand rule to determine the normal vector, the range of θ is limited to the range of sinθ∈[0,1], adding we specify the direction of the normal vector only one, we can transfer the position of the vector to the modulo length of the algebraic relationship.

In computational geometry, we often do not look at the normal vector, but only in the two-dimensional plane using the algebraic relationship of the cross-multiplication coefficient, we can get the following very important conclusion:

To determine the intersection of segments:

With the introduction of the cross product above, we can use its properties to involve a variety of algorithms, in which it is judged that the intersection of segments is one of them.

In order to use the good properties of the cross product, it is necessary to understand the intersection of the segments from the angle of "cross-stand". That is, in general, two line segments intersect, and two endpoints of one segment (segment_1) are on either side of the line where the other segment (Segment_2) is located, and also to satisfy the two endpoints of the other segment (segment_2) across the front segment (segment_1) On both sides of the line.

And the concept of "across" the geometrical position, you can cross the product.

For some of the more special cases, such as the point on one segment falls in the line where another line segment is located, we need to give a special sentence, we can get the following pseudo-code form:

Segments-intersect (P1, p2, p3, p4)//Determine if the segment P1P2,P3P4 intersect.

D1 = DIRECTION (P3, P4, p1);

D2 = DIRECTION (P3, P4, p2);

D3 = DIRECTION (P1, p2, p3);

D4 = DIRECTION (P1, p2, p4);

if (D1 > 0 and D2 0 or D1 0 and d2>0) and ((D3 > 0 and D4 0 or D4, 0 and d3>0)) return true;

else if (D1 = 0) and on-segment (P3, P4, p1)

return true;

else if (d2 = 0) and on-segment (P3, P4, p2)

return true;

else if (d3 = 0) and on-segment (P1, p2, p3)

return true;

else if (D4 = 0) and on-segment (P1, p2, p4)

return true;

Else

return false;

DIRECTION (pi, PJ, pk)//vector pkpi fork multiply vector pjpi.

Return (PK-PI) x (PJ-PI).

On-segment (pi, PJ, PK)//Judge whether the point PK is on the line PIPJ.

if (min (xi, XJ) ≤xk≤max (xi, XJ) and Min (Yi, yj) ≤yk≤max (Yi, yj))

return True

Else

return false;

The following shows the intersection of several segments to facilitate understanding of the entire algorithm flow.

To find a convex bag:

Finding the convex hull of a point set V is a common and basic algorithm in computational geometry, and locating the nearest point pair based on the convex hull will also optimize the complexity of the time.

The algorithm for finding convex hull is based on the Graham Scan (Graham's scan) and the Jarvis stepping method (Jarvis March), all of which use a technique called "Rotary sweep", which uses the properties of the cross product.

There are several other ways to construct the convex hull:

    1. Increment method: First sort from left to right, get point set V={v1, V2, ..., vn}. Then construct the convex hull P (3) ={v1,v2,v3}, then sequentially scan backward, add the I point each time, and update P (i-1), to get a new convex hull P (i), when scanning to the nth point in the dot concentration , the construction of the convex hull is completed.
    2. Divide-and-conquer method: Divide the point set into a split and then recursively perform the convex-packet operation on the subset
    3. Pruning-Search method: In the construction process, similar to the Nineth chapter of the worst-case low-limit Line time algorithm, it will be constructed two times, respectively, the construction of the chain and the bottom of the convex package.

The method described above is very general, for beginners will appear confused, the following we started on one-by-one analysis algorithm steps, correctness analysis and time complexity.

The general search algorithm for constructing convex hull is a combination of the Graham scanning method/jarvis step and the following increment/prune-search/divide method, and the different combinatorial methods often depend on different sort modes (horizontal order, polar angle order).

Basic Graham Scanning method:

This method is based on the polar order, using a stack S structure to store the convex set V1, and then update to the point I, get the current top of the stack of two elements s[top], s[top-1], using the cross product to examine the relative position of the two points and P[i] (this is what we described earlier "Rotary sweep" technology), Update the convex packet point set V1, the following shows the pseudo-code of this algorithm:

Graham-scan (P)

Let P0 is the point in P the minimum y-coordinate,

Or the leftmost such point in case of a tie

LET<P1, p2, ..., pn> is th remaining points in P,

Sorted by polar angle in counterclockwise order around P0

(If more tan one point have the same angle, remove all but

The on this is farthest from p0)

If M < 2

Return "Convex hull is empty"

Else let S is an empty stack

PUSH (P0, S)

PUSH (P1, S)

PUSH (P2, S)

For i = 3 to M

While the angle formed by points next-to-top (s), TOP (s), pi

Makes a nonleft turn

POP (S)

PUSH (pi, S)

Return S

Below we give a simulation of the basic Graham scanning method:

Find nearest Point pair:

In the traffic control system, in order to detect the potential collision accident, in the air or ocean transportation system, the need to identify two distance of the nearest means of transport, abstracted out, the nearest point is to point set P, find the nearest two points.

The time complexity of the naïve enumeration is O (n^2), where we introduce the divide-and-conquer algorithm to reduce the complexity of time to O (NLGN).

Divide and conquer strategy:

Decomposition: Find a vertical line L (in the Cartesian system, x=a), which divides the point set P into two point set pl,pr. Make |pl| = | Pr| and all points in PL and PR are distributed on the left and right side of the vertical line L. Then get the PL set according to the X, Y coordinates in ascending order of auxiliary array xl,yl, get the PR set in the x, Y coordinates ascending order of auxiliary array xr,yr.

For each recursive come in, we need to follow the X ascending array p, because only then can we determine the vertical line L. This is why it is necessary to get XL,XR when decomposing the problem, for the following recursive process to prepare the point set parameters in ascending order of X. And what is the use of point set yl,yr? We can see the usefulness of the other auxiliary array y ' in the analysis algorithm later.

Solution: After getting PL,PR, recursive call above we have constructed a search for the nearest point pair algorithm, the first call of the point set parameter is PL, the second call of the point set parameter is PR.

Merge: Suppose in the previous step we returned two values: Δ1, δ 2 represents the solution set for two sub-problems after division, δ= min (δ1, δ2) and possibly the answer to the current question. In order to ensure that the answer is correct, we must take into account those situations that are not traversed. It can be seen that if there are more optimized results, then the corresponding two points must be distributed in the rectangular region of the δ* 2δ with the symmetric axis of L, and it is easy to see that if we place the points in the P collection in ascending y ' y ', if there is a more advantageous pair (PI,PJ), then j-i must be [ 1,7], based on this conclusion, we reduced the time complexity of the supplemental enumeration process in the merging process to O (n).

And why Y ' in the more advantages of the subscript distance is necessarily less than or equal to 7? The principle is actually very simple, refer to the following figure.

The question below is, how do we construct y '? Based on the point set X in the recursive call, we get the vertical line L = A, in order to construct Y ', we can find the point set Y ordered by Y in the shadow region by judging whether the horizontal axis is in the (a–δ,a+δ) range, based on the set Y,o (n) Complexity of the point set P in ascending order Y.

Summing up, each recursive call, we need to point set X, Y, divide and conquer need to find the corresponding sub-problem point set parameter Xl,yl,xr,yr, and the time complexity of constructing these arrays are O (n).

The following is an analysis of the time complexity of this algorithm:

According to the main theorem previously introduced, T (n) = O (Nlogn).

For the initial state given the unordered point set P, we use O (NLOGN) to order it by X, Y, then the sub-problem will no longer need the ordering process, using O (n) time complexity of the x, y array binary can be xr,xl,yr,yl.

T ' (n) = t (n) + O (NLOGN)

For the initial state given by the unordered point set p, the entire search for the shortest point pair algorithm time complexity T ' (n) = O (Nlogn).

"Introduction to Algorithm"-chaper33-computational geometry

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.