Clipping is the process of drawing pixels only to a selected region or well-defined window. In this, pixels that lie outside the window or clip region get removed by using various clipping algorithms. It is mainly used for artistic purposes.
Technically, it can be viewed as a method or procedure that determines whether a pixel is outside or inside of a specified region. The method is termed as clipping or clipping algorithm.
There are various applications ranging from surface visibility identification in three-dimensional view, drawing operation, to object creation using solid modeling method.
Based on application, clipping window boundaries is identified i.e. polygon.
A portion of two-dimensional scene that is chosen for display is termed as clipping window.
A region to which an object inside the clipping window is mapped is called viewport.
Read : What is window and viewport?
A line or an object can be partially or completely inside in a window.
If the given line or object is partially inside the clip region, then the portion which is outside the window would be removed.
Point Clipping:
In point clipping, a point (x,y) is checked whether it falls within the window or not.
- A point that lies inside the clipping window is considered as visible and no clipping is required for such case
- If it lies outside the window, then it would be considered as invisible
Line Clipping:
A line clipping comes into play, where the extra portion of a given line that lies outside the window is cut off from the clip region. There is a popular line clipping algorithm named Cohen Sutherland algorithm.
- If a line intersects the clipping window, then the line is required to be clipped as it is considered as partially visible
- If a line falls inside the clipping window, then it is considered as visible
- Otherwise, invisible
Polygon clipping:
Ploygon clipping also follows the same concept, it cuts out vertices of the polygon that is outside the windows. Sutherland–Hodgman algorithm and Weiler-Atherton polygon clipping algorithm techniques are used for clipping a polygon.
Clipping a polygon is a complex procedure, unlike line clipping where only two points need to map one another. In polygon clipping, a method may generate a sequence of vertices as output that can be represented as clipping boundaries.
- If a part of polygon intersects the clipping window, then a particular portion that lies outside the window is needed to be removed
Text Clipping:
It can be defined as a process where a string (a sequence of character) that falls outside the window is removed.
There are various text clipping methods and its usage depends on character generation mechanisms. all-or-none clipping is the simplest method for clipping text corresponding to a window.
- If string falls outside the clip window, then don’t consider it
- If string falls partially inside the window, then discard it completely
- Otherwise. consider it