Computer Graphics-Segment clipping-Liang Barsky algorithm (Liang Youdong algorithm)

Source: Internet
Author: User

Algorithm Description:

The basic starting point of the Liang_barsky algorithm is the parametric equation of the straight line. Give any straight line segment, the two ends of the points are and, so, the linear equation is:
  
If any point in the line is inside the window, the following relationships must be met:
  
The above inequalities can be expressed as:
  
where p and q are defined as:

  

If any line is parallel to a clipping boundary, then the subscript k corresponds to the window boundary parallel to the line segment (and represents the left, right, bottom, and top bounds of the cropping window, respectively). If for a certain k value, satisfies, then the straight line is completely outside the window, can discard. If the line is inside its parallel window boundary, further calculations are required to determine whether the line is inside, outside, or intersecting the window. At that time, the line was extended from the outside of the clipping boundary to the interior, and if so, the line was extended from the inside of the clipping boundary to the outside. For pk≠0, the parameter U of the intersection of the line and the boundary K can be calculated using the formula.
For each line, you can calculate the parameter value of the line in the inner segment of the cropping window.
Values are determined by the window boundaries that make the line extend from outside to inside.
For these edges, calculate. Value and the maximum value in the set of 0.
Values are determined by the bounds of the window that makes the line extend from inside to outside.
Calculates the minimum value in the set consisting of 1. If the line is completely outside the window, you can simply discard it, otherwise the end of the cropped segment is calculated based on the two values of the parameter U.

Detailed code: Computer Graphics-code_1

Build Result:

Computer Graphics-Segment clipping-Liang Barsky algorithm (Liang Youdong 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.