203 Computer Graphics
203 Computer Graphics
clipping algorithm
Implementation
#include<iostream.h>
#include: Preprocessor directive used to include header files.
• <iostream.h>: This includes the input/output stream library for C++.
The .h extension indicates it’s a header file
#include<conio.h>
• <conio.h>: This includes functions used for console input and output in Turbo C++.
• #include<graphics.h>
• <graphics.h>: This includes the graphics library for Turbo C++, allowing you to create graphical
applications.
Const int INSIDE = 0; // 0000
const int LEFT = 1; // 0001
const int RIGHT = 2; // 0010
const int BOTTOM = 4; // 0100
• const int TOP = 8;
• Similar to the previous line, updates code to include the right region
code
If (y < y_min)
• Similar to the previous line, initializes code2 with the region code of
point (x2, y2).
Int accept = 0; // 0 represents false
• else {
• Executes if none of the above conditions are met.
Double x, y;
Declares variables x and y to store the clipped coordinates.
Int code_out = (code1 != 0) ? Code1 : code2;
• Determines which endpoint to clip based on which one lies outside
the clipping window.
return code;
}
Void cohenSutherlandClip(double x1, double y1, double x2, double y2) {
int code1 = computeCode(x1, y1);
int code2 = computeCode(x2, y2);
int accept = 0; // 0 represents false