Sutherland-hodgman Polygon Clipping algorithm of CGA clipping algorithm

Source: Internet
Author: User

Sutherland-hodgman Polygon Clipping algorithm of CGA clipping algorithm

The Sutherland-hodgman algorithm is also called edge trimming, and the algorithm is Sasserande (i. E. Sutherland) and Trautman (Hodgman) were introduced in 1974.

This algorithm adopts the method of segmentation processing and Edge cutting . This algorithm is suitable for the clipping of any convex or concave, or planar or non-planar polygon in any convex polygon window.

  Edge-by-side cropping features: Edge-by-side is processed by the boundary of the clipping plane, and the processing order of the clipping boundaries is irrelevant. Successive is every time the clipping boundary is processed on each edge of the polygon sequentially, ordered.

1. Basic Ideas

Crop by edge, which in turn crops all edges of the polygon with one edge of the crop window.

Crop edges are cropped with each edge of the polygon, and only the position of the single trimmed edge and single polygon edge is processed. In the polygon vertex list, the adjacent two endpoints make up the edges of the polygon, and the SP acts as an adjacent endpoint (except for P 1th), the position of the SP with the clipping edge is as shown in 4.

  

After each trimmed edge is processed on all sides of the polygon, the output vertex list output is 1, or 2, or 0 (not output) vertices.

"1" If the edges are fully visible, the output p point, note that because it is "successive" processing of the vertices of the polygon, so the S point as the last point of the end of the pendulum has been output;

"2" if completely invisible, then not output, 0;

"3" If partially visible, in two cases, if the case is left, you need to output the intersection I as the output point output, at this time the output of 1, followed by the case of entry, you need to the intersection I and the end point P output, this time output 2.

2. Key problem handling of the algorithm

(1) Special points for processing polygons:

The first point of the "1" polygon is P1, depending on its visibility, to determine whether to output to the output vertex table, if visible then output, and as the starting point S. If it is not visible, it does not output, but still as s save, processing the next second point;

"2" processing polygon left after a side: PnP1, need to separate processing, in order not to eliminate the particularity of P1, you can save P1 as F (first), so that when the last edge of processing is, that is, PNF, you can do the same as other edges of the same processing.

(2) Determining the visibility of vertices and the current clipping edge

  determined by the vector cross product method .
for simple meters, the test points are represented as P points. Assume that the window boundary direction is clockwise , as shown in, for any of the boundary vectors, from the beginning of the vector A to the end of a B look at the past:

"1" If the test point P on the right side of the boundary line (that is, the inside), the direction of abxap perpendicular to the X-y plane and point to the screen, that is, the right-hand coordinate system Z axis negative direction, cross-multiply results <0.
"2" Conversely, if p is on the left side of the boundary line (i.e. outside) or on the boundary, then the direction of the abxap is perpendicular to the X-y plane and points to the outside of the screen, that is, the right-hand coordinate system in the positive direction of the z axis, the result >=0.

Abxap fork Multiply, right-hand coordinates , four fingers from AB to AP direction, along the ab direction, at this time the Thumb Z forward (toward you) as a result positive, Thumb z negative half axis (back to you) is negative.

For example, the boundary ab is clockwise, so when the right hand rule, say something awkward.

  
Set: Point P (x, y), point A (Xa,ya), point B (XB,YB),
Vector ab={(xb-xa), (Yb-ya)},
Vector ap={(X-XA), (Y-ya)},
Then the direction of the abxap can be determined by the following symbol:
v=(xb-xa) · (Y-ya)-(X-XA) · (Yb-ya)
Therefore, when v>=0, p is visible on the inside of the boundary line. While V<0, p is outside the boundary line.

(3) intersection processing of intersecting segments

Methods there are three kinds of "1" area coding, processing, "2" Midpoint Segmentation, "3" parametric equation.

The parametric equation method is most suitable for the two segments that have been determined to intersect.

such as: Segment P1P2, P3P4, their parametric equation is as follows,

P (s) = P1 + s* (P2-P1) 0<= s <=1

P (t) = P3 + t* (p4-p3) 0<= T <=1

Then the intersection p (s) = P (t), because P (s), P (t) are vector functions , that is, p (s) = [X (s), Y (s)] P (t) = [x (t), Y (t)] Two unknown two equations, you can solve the results.

"1" If the equation is not solved, then the two segments are parallel; "2" if s or T is out of range, then the two segments do not want to cross and are not parallel; "3" is not out of range, then a valid intersection.

It is most suitable to solve the equations by means of the form.

Such as:

=, so M=, its determinant =3x1-3x (-2) =9≠0,

M-1=.

∴=m-1==,

The Jiewei of the equation group

(3) The Sutherland_dodman algorithm, which produces a degenerate boundary . that is, the clipping result, part of the polygon Sing Woo the boundary of the window, and transforms the boundary round-trip conjunctions, connecting the two parts of the polygon in the cropping result together. in many applications, such as the "real area Fill" scan transformation, the degraded boundary has no effect, but for other applications, such as the Hide Polygon elimination algorithm, these degraded boundaries need to be removed beforehand.

The problem can be dealt with using the "vertex sorting approach" proposed by Sutherland-hodman .

3. The procedure is as follows

A problem

Sutherland-hodgman Polygon Clipping algorithm of CGA clipping algorithm

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.