Clipping Algorithms

Clipping Algorithm in Computer Graphics

Clipping removes the part of an object that lies outside a selected viewing area. It is used before displaying graphics so only the visible portion appears inside the screen or viewport.

Published May 28, 2026 - 8 min read

What is clipping in computer graphics?

Clipping is the process of cutting away graphics that fall outside a fixed boundary called the clipping window. The clipping window is usually a rectangle that represents the visible area of the screen, viewport, or drawing region.

For example, if a line starts outside the window and ends inside the window, only the visible part should be drawn. Clipping algorithms decide what part is visible and what part should be removed.

Clipping window

A rectangular clipping window is normally represented by four values:

xmin = left boundary
ymin = top boundary
xmax = right boundary
ymax = bottom boundary

In graphics.h, the y-coordinate increases downward. So a point is above the window when y < ymin and below the window when y > ymax.

Types of clipping algorithms

Point clipping

Point clipping checks whether a point is inside or outside the clipping window. A point is visible if its x and y coordinates are within the window boundaries.

Line clipping

Line clipping removes the outside part of a line segment. Cohen-Sutherland and Liang-Barsky are common line clipping algorithms.

Polygon clipping

Polygon clipping clips a complete polygon against the clipping window. Sutherland-Hodgman is a common polygon clipping algorithm.

Text and curve clipping

Text clipping removes text that lies outside the viewing area. Curve clipping is used for curves and arcs that cross the boundary.

Point clipping condition

A point (x, y) is visible if it satisfies this condition:

x >= xmin and x <= xmax
y >= ymin and y <= ymax

Point clipping program in C using graphics.h

This program draws a clipping window, asks for a point, and displays whether the point is inside or outside the clipping window.

C / Point Clipping
#include <graphics.h>
#include <conio.h>
#include <dos.h>
#include <stdio.h>

int main()
{
    int gd = DETECT, gm;
    int xmin = 150, ymin = 120;
    int xmax = 450, ymax = 340;
    int x, y;

    printf("Enter point x y: ");
    scanf("%d %d", &x, &y);

    initgraph(&gd, &gm, "");

    setcolor(WHITE);
    rectangle(xmin, ymin, xmax, ymax);
    outtextxy(xmin, ymin - 20, "Clipping Window");

    if (x >= xmin && x <= xmax && y >= ymin && y <= ymax)
    {
        setcolor(GREEN);
        putpixel(x, y, GREEN);
        circle(x, y, 4);
        outtextxy(170, 360, "Point is inside the clipping window");
    }
    else
    {
        setcolor(RED);
        putpixel(x, y, RED);
        circle(x, y, 4);
        outtextxy(170, 360, "Point is outside the clipping window");
    }

    getch();
    closegraph();
    return 0;
}

Try it online: open the graphics.h online compiler, paste the program, then use sample point 250 200.

Why clipping is important

  • It prevents drawing outside the visible screen area.
  • It improves performance by skipping invisible objects.
  • It is required for viewports, windows, and camera-like graphics systems.
  • It makes rendering cleaner and more predictable.

Common mistakes

Confusing clipping with transformation

Transformation changes an object's position, size, or angle. Clipping removes the part that is outside a boundary.

Using the wrong boundary comparison

In graphics.h, top means smaller y and bottom means larger y. This matters when checking whether a point is above or below the clipping window.

Drawing before clipping

In real graphics pipelines, clipping should happen before final drawing so only visible objects are rendered.