Liang youdong-Barsky algorithm principle

Source: Internet
Author: User
  • Main features of this algorithm

    • The problem of two-dimensional cropping is converted into a secondary one-dimensional cropping problem, and the problem of cropping is transformed into solving a set of inequalities;

    • The improvement of the Cohen-Sutherland encoding algorithm is only applicable to the shortcomings of the line segments on the same side (or left, or right, or top or bottom) of the window.

The algorithm is divided into one and two dimensions. The former is the basis of the latter.

  • One-dimensional Cropping

    • The essence of one-dimensional pruning is to obtain the public part of two line segments.

      Principle of one-dimensional cropping Algorithm

      • Position distribution of P1P2 and w1w2 in one-dimensional window (the condition of multiple endpoints is not listed)

    • If w1w2 is a one-dimensional window and P1P2 is a given line segment, the visible part of P1P2 in w1w2 is:

      S = w1w2 2017p1p2

      Make W1, W2, X1, and X2 the coordinates of W1, W2, P1, and P2, respectively, and make P1P2 visible in at least some of the following conditions:

      Max (min (x1, x2), min (W1, W2) ≤ min (max (x1, x2), max (W1, W2 ))

      (Assume that the line segments and windows are arranged from left to right, which can be abbreviated as Max (x1, W1) ≤ min (X2, W2), that is

      • Line Segments and Windows: medium to large at the left endpoint ≤ small at the right endpoint
         

  • 2d Cropping

    • The essence of the Two-dimensional cropping algorithm is how to turn the two-dimensional cropping problem into a secondary one-dimensional cropping.

      The two-dimensional window is determined by the following equation:

      X = XL
      X = XR (note that the area of XL ≤ x ≤ XR is △x)
      Y = Yb
      Y = yt (note that the area of Yb ≤ y ≤ yt is △y)
       

      The section of P1P2 in the window of any line segment on the plane is:

      P1P2 ∩ △x ∩ △y

      If the intersection of the line through P1P2 and the left, right, top, and bottom boundaries of the window is l, R, B, and T, the visible part of P1P2 can also be shown:

      P1P2 upstream LR upstream BT


       

    • When the line is vertical

      • Xp1 = xp2
         

        When XL ≤xp1 ≤xr, P1P2 then LR then bt is equivalent to P1P2 then Bt;
         

    • When the line is parallel

      • Yp1 = yp2
         

        When Yb ≤yp1 ≤yt, P1P2 then LR then bt is equivalent to P1P2 then LR;

         

    • The P1P2 line is not even perpendicular to the window boundary or horizontal window boundary.

      • That is, when xp1 is less than xp2, and yp1 is less than yp2

        • L, R, B, and t are all definite.
           

        • The slope k = (yp2-yp1)/(xp2-xp1) of P1P2 is non-zero or non-singular value.

          XB = xp1 + (Yb-yp1)/K;
          XT = xp1 + (yt-yp1)/K;

          And XB <XT, when k> 0;
          XT <XB, when k <0.

        Ling
        X1 = max (XL, min (xp1, xp2 ))
        X2 = min (XR, max (xp1, xp2 ))

        The following are the necessary and sufficient conditions for the P1P2 distinct LR non-empty set:

        X1 ≤ X2 (max (x1, W1) ≤ min (X2, W2 ))

        In this case, the common part of the P1P2 line and window in the X axis is:

        [X1, x2]

        The additional conditions for the P1P2 sort LR sort BT non-empty set are:

        Max (x1, min (XB, XT) ≤ min (X2, max (XB, XT ))
         

      • It is equivalent to the following three inequalities:
         

        • X1 ≤ X2

          X1 ≤ max (XB, XT)
          Min (XB, XT) ≤ X2
           

      • The three inequalities are equivalent to the following two groups of inequalities.

        • X1 ≤ X2 (1) x1 ≤ X2
          X1 ≤ XT (2) (k> 0) x1 ≤ Xb (k <0)
          XB ≤ X2 (3) XT ≤ X2
           

      • When either of the above two groups of inequalities does not meet the requirements, the line segment and window cannot have a public part.
         

      • Observe the geometric meaning of the above three Inequalities
         

        • Set K> 0
           

        • Formula (1) x1> X2
           

          • The intersection of P1P2 primary LR is null, that is, P1P2 primary △x is null,

            In this case, P1P2 is displayed on the left side of the left boundary X = XL of the window, or on the right side of the right boundary X = XR of the window.


             

        • Formula (2) x1> XT

          • This formula means max (XL, min (xp1, xp2)> XT

            It is equivalent to: XL> XT, or min (xp1, xp2)> XT

            K> 0, when XL> XT, T (XT) is the intersection of the upper boundary of the window through the straight line of P1P2 on the left side of the left boundary of the window, as shown in

            Min (xp1, xp2)> xt is equivalent to xp1> XT, or xp2> XT, which indicates that the P1P2 line is above the upper boundary of the window, as shown in B.
             

        • Formula (3) XB> X2

          • Likewise, XB> X2 indicates that the bottom boundary y = Yb and the right boundary X = XR (C in the figure) of the straight line traversing window, or P1P2 is below y = Yb (d in the figure)


             

        • When K <0

          • When K is less than 0, the line segment corresponds to the position of the window.

            This method adds a quick denial decision for straight line segments (A and C states) across three regions.

            These States cannot be solved at one time using the Sutherland encoding method (it can only quickly refuse to determine B and D ).


             

  • Implementation of two-dimensional cropping Algorithms

    • When the preceding three conditions are not met, the P1P2 line must at least be in the window. If K> 0, the endpoint of the visible part is:

      When K is less than 0, as long as Yb and yt are exchanged, the conclusions listed in the table are applicable.

 

From: http://cg.sjtu.edu.cn/lecture_site/chap3/mainframe312.htm#1

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.