- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Point Clipping Algorithm in Computer Graphics in C++

Computer graphics deals with drawing images and graphics on a computer screen. Here, we treat the screen as a 2-D coordinate system. This coordinate system starts from top-left (0,0) and ends at bottom-right.

**Viewing plane** is the area defined for drawing graphics in computer graphics. Or the visible area of the screen.

Clipping is deleting those points or graphics that are outside the viewing plane.

Let's take an example to understand clipping.

Here points C and D will be clipped as they are outside the viewing plane marked with blue color.

In order to clip a point in computer graphics. We need to know the coordinates of the viewing place i.e. (X_{min}, Y_{min}) and (Xmax, Ymax). Then we will compare the coordinates of the point with these coordinates.

If (X_{min}, Y_{min}) <= (Xpoint, Y point) <= (X_{max}, Y_{max}), then the point lies inside the viewing plane otherwise it will be clipped off.

## Example

Program to illustrate point clipping,

#include <iostream> using namespace std; void pointClipping(int points[][2], int n, int Xmin, int Ymin, int Xmax, int Ymax) { cout<<"Points that are removed by Point clipping Algorithm are :"<<endl; for (int i = 0; i < n; i++){ if ((points[i][0] < Xmin) || (points[i][0] > Xmax)) cout<<"("<<points[i][0]<<","<<points[i][1]<<")\t"; else if ((points[i][1] < Ymin) || (points[i][1] > Ymax)) cout<<"("<<points[i][0]<<","<<points[i][1]<<")\t"; } } int main() { int points[6][2] = {{0, 0}, {-10, 10}, {1000, 1000}, {100, 900}, {501, 311}, {250, 250}}; int Xmin = 0; int Xmax = 500; int Ymin = 0; int Ymax = 500; pointClipping(points, 6, Xmin, Ymin, Xmax, Ymax); return 0; }

## Output

Points that are removed by Point clipping Algorithm are : (-10,10) (1000,1000) (100,900) (501,311)

- Related Articles
- Flood fill algorithm using C graphics
- Mid-Point Line Generation Algorithm in C++
- bar() function in C graphics
- Shortest Path algorithm in Computer Network
- Discuss the Hardware Algorithm in Computer Architecture?
- Draw a line in C++ graphics
- What is a Routing Algorithm in Computer Network?
- What is Booth Multiplication Algorithm in Computer Architecture?
- What is Token Bucket algorithm in computer networks?
- What is Leaky Bucket algorithm in computer networks?
- What is an Adaptive Routing Algorithm in Computer Network?
- What is Point to Point Protocol (PPP) in Computer Network?
- What is Fixed Point Representation in Computer Architecture?
- What is Floating-Point Representation in Computer Architecture?
- Berkeley’s Algorithm in C/C++