Question:

Published on: 12 October, 2024

Answer:

When we have to display a large portion of the picture, then not only scaling & translation is necessary, the visible part of picture is also identified. This process is not easy. Certain parts of the image are inside, while others are partially inside. The lines or elements which are partially visible will be omitted.

For deciding the visible and invisible portion, a particular process called clipping is used. Clipping determines each element into the visible and invisible portion. Visible portion is selected. An invisible portion is discarded.

Lines are of three types:

**Visible:**A line or lines entirely inside the window is considered visible**Invisible:**A line entirely outside the window is considered invisible**Clipped:**A line partially inside the window and partially outside is clipped. For clipping point of intersection of a line with the window is determined.

Clipping can be applied through hardware as well as software. In some computers, hardware devices automatically do work of clipping. In a system where hardware clipping is not available software clipping applied.

Following figure show before and after clipping

The window against which object is clipped called a clip window. It can be curved or rectangle in shape.

- It will extract part we desire.
- For identifying the visible and invisible area in the 3D object.
- For creating objects using solid modeling.
- For drawing operations.
- Operations related to the pointing of an object.
- For deleting, copying, moving part of an object.

Clipping can be applied to world co-ordinates. The contents inside the window will be mapped to device co-ordinates. Another alternative is a complete world co-ordinates picture is assigned to device co-ordinates, and then clipping of viewport boundaries is done.

- Point Clipping
- Line Clipping
- Area Clipping (Polygon)
- Curve Clipping
- Text Clipping
- Exterior Clipping

Point Clipping is used to determining, whether the point is inside the window or not. For this following conditions are checked.

- x ≤ x
_{max} - x ≥ x
_{min} - y ≤ y
_{max} - y ≥ y
_{min}

The (x, y) is coordinate of the point. If anyone from the above inequalities is false, then the point will fall outside the window and will not be considered to be visible.

It is performed by using the line clipping algorithm. The line clipping algorithms are:

- Cohen Sutherland Line Clipping Algorithm
- Midpoint Subdivision Line Clipping Algorithm
- Liang-Barsky Line Clipping Algorithm

In the algorithm, first of all, it is detected whether line lies inside the screen or it is outside the screen. All lines come under any one of the following categories:

- Visible
- Not Visible
- Clipping Case

**1. Visible:** If a line lies within the window, i.e., both endpoints of the line lies within the window. A line is visible and will be displayed as it is.

**2. Not Visible:** If a line lies outside the window it will be invisible and rejected. Such lines will not display. If any one of the following inequalities is satisfied, then the line is considered invisible. Let A (x_{1},y_{2}) and B (x_{2},y_{2}) are endpoints of line.

x_{min},x_{max} are coordinates of the window.

y_{min},y_{max} are also coordinates of the window.

x_{1}>x_{max}

x_{2}>x_{max}

y_{1}>y_{max}

y_{2}>y_{max}

x_{1}<x_{min}

x_{2}<x_{min}

y_{1}<y_{min}

y_{2}<y_{min}

**3. Clipping Case:** If the line is neither visible case nor invisible case. It is considered to be clipped case. First of all, the category of a line is found based on nine regions given below. All nine regions are assigned codes. Each code is of 4 bits. If both endpoints of the line have end bits zero, then the line is considered to be visible.

The center area is having the code, 0000, i.e., region 5 is considered a rectangle window.

**Following figure show lines of various types**

Line AB is the visible case

Line OP is an invisible case

Line PQ is an invisible line

Line IJ are clipping candidates

Line MN are clipping candidate

Line CD are clipping candidate

- It calculates end-points very quickly and rejects and accepts lines quickly.
- It can clip pictures much large than screen size.

**Step1:**Calculate positions of both endpoints of the line

**Step2:**Perform OR operation on both of these end-points

**Step3:**If the OR operation gives 0000

Then

line is considered to be visible

else

Perform AND operation on both endpoints

If And ≠ 0000

then the line is invisible

else

And=0000

Line is considered the clipped case.

**Step4:**If a line is clipped case, find an intersection with boundaries of the window

m=(y_{2}-y_{1} )(x_{2}-x_{1})

**(a)** If bit 1 is "1" line intersects with left boundary of rectangle window

y_{3}=y_{1}+m(x-X_{1})

where X = X_{wmin}

where X_{wmin}is the minimum value of X co-ordinate of window

**(b)** If bit 2 is "1" line intersect with right boundary

y_{3}=y_{1}+m(X-X_{1})

where X = X_{wmax}

where X more is maximum value of X co-ordinate of the window

**(c)** If bit 3 is "1" line intersects with bottom boundary

X_{3}=X_{1}+(y-y_{1})/m

where y = y_{wmin}

y_{wmin} is the minimum value of Y co-ordinate of the window

**(d)** If bit 4 is "1" line intersects with the top boundary

X_{3=X}1+(y-y_{1})/m

where y = y_{wmax}

y_{wmax} is the maximum value of Y co-ordinate of the window

Let R be the rectangular window whose lower left-hand corner is at L (-3, 1) and upper right-hand corner is at R (2, 6). Find the region codes for the endpoints in fig:

The region code for point (x, y) is set according to the scheme

Bit 1 = sign (y-y_{max})=sign (y-6) Bit 3 = sign (x-x_{max})= sign (x-2)

Bit 2 = sign (y_{min}-y)=sign(1-y) Bit 4 = sign (x_{min}-x)=sign(-3-x)

Here

So

A (-4, 2)→ 0001 F (1, 2)→ 0000

B (-1, 7) → 1000 G (1, -2) →0100

C (-1, 5)→ 0000 H (3, 3) → 0100

D (3, 8) → 1010 I (-4, 7) → 1001

E (-2, 3) → 0000 J (-2, 10) → 1000

We place the line segments in their appropriate categories by testing the region codes found in the problem.

**Category1 (visible):** EF since the region code for both endpoints is 0000.

**Category2 (not visible):** IJ since (1001) AND (1000) =1000 (which is not 0000).

**Category 3 (candidate for clipping):** AB since (0001) AND (1000) = 0000, CD since (0000) AND (1010) =0000, and GH. since (0100) AND (0010) =0000.

The candidates for clipping are AB, CD, and GH.

In clipping AB, the code for A is 0001. To push the 1 to 0, we clip against the boundary line x_{min}=-3. The resulting intersection point is I_{1} (-3,3). We clip (do not display) AI_{1} and I_{1} B. The code for I_{1}is 1001. The clipping category for I_{1} B is 3 since (0000) AND (1000) is (0000). Now B is outside the window (i.e., its code is 1000), so we push the 1 to a 0 by clipping against the line y_{max}=6. The resulting intersection is l_{2} (-1,6). Thus I_{2} B is clipped. The code for I_{2} is 0000. The remaining segment I_{1} I_{2} is displayed since both endpoints lie in the window (i.e., their codes are 0000).

For clipping CD, we start with D since it is outside the window. Its code is 1010. We push the first 1 to a 0 by clipping against the line y_{max}=6. The resulting intersection I_{3} is (,6),and its code is 0000. Thus I_{3} D is clipped and the remaining segment CI_{3} has both endpoints coded 0000 and so it is displayed.

For clipping GH, we can start with either G or H since both are outside the window. The code for G is 0100, and we push the 1 to a 0 by clipping against the line y_{min}=1.The resulting intersection point is I_{4} (2,1) and its code is 0010. We clip GI_{4} and work on I_{4} H. Segment I_{4} H is not displaying since (0010) AND (0010) =0010.

Subjects

Trending

Random questions

**What is Resource management?**

12 October, 2024

**Explain the concept of frequency reuse in cellular systems. **

12 October, 2024

Write the recursive algorithm to find x^ n.

12 October, 2024

**Difference between Inspections and Walkthrough**

12 October, 2024

12 October, 2024

What is a minimum spanning tree ? Describe Huffman’s Algorithm.

12 October, 2024