0% found this document useful (0 votes)
8 views6 pages

CG 7

The document outlines Experiment 7 for a Computer Graphics course, focusing on evaluating 4-bit region codes for line endpoints to determine their position relative to screen boundaries. It includes a code example in Turbo C++ that demonstrates how to implement line clipping and user input handling. Learning outcomes emphasize understanding line clipping concepts, graphics programming, bitwise operations, and the Cohen-Sutherland line clipping algorithm.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

CG 7

The document outlines Experiment 7 for a Computer Graphics course, focusing on evaluating 4-bit region codes for line endpoints to determine their position relative to screen boundaries. It includes a code example in Turbo C++ that demonstrates how to implement line clipping and user input handling. Learning outcomes emphasize understanding line clipping concepts, graphics programming, bitwise operations, and the Cohen-Sutherland line clipping algorithm.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DEPARTMENT OF

COMPUTER SCIENCE &


ENGINEERING
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment 7

Student Name: Bhumika UID: 22BCS16875


Branch: CSE Section: IOT-626/A
Semester: 6th DOP: 18/03/25
Subject: Computer Graphics Subject Code: 22CSH-352

Aim: Evaluate the 4-bit region code for line endpoints and determine whether the line lies
inside or outside the screen.

Objective: To calculate and display the 4-bit region code for line endpoints and determine
whether the line lies within the screen boundaries.

Code:

#include <iostream.h>

#include <conio.h>

#include <graphics.h>

#include<dos.h>

void main() {

int gd = DETECT, gm;

initgraph(&gd, &gm, "C:\\Turboc3\\BGI");

int xmax = 400, ymax = 300, xmin = 200, ymin = 150;

outtextxy(450,200,"Bhumika_22BCS16875");

// Drawing window boundaries

line(xmin, ymin, xmin, ymax);

line(xmax, ymin, xmax, ymax);


DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
line(xmin, ymax, xmax, ymax);

line(xmin, ymin, xmax, ymin);

cout << "Enter the endpoints of the line (x1, y1, x2, y2): ";

int x[2], y[2], num[2];

cin >> x[0] >> y[0] >> x[1] >> y[1];

// Drawing the user-defined line

line(x[0], y[0], x[1], y[1]);

for (int i = 0; i < 2; i++) {

int bit1 = 0, bit2 = 0, bit3 = 0, bit4 = 0;

if (y[i] < ymin) bit1 = 1;

if (y[i] > ymax) bit2 = 1;

if (x[i] > xmax) bit3 = 1;

if (x[i] < xmin) bit4 = 1;

num[i] = bit1 * 8 + bit2 * 4 + bit3 * 2 + bit4 * 1;

cout << "For " << i << "th endpoint, region code is: "

<< bit1 << bit2 << bit3 << bit4 << endl;

if (!(num[0] | num[1])) {

cout << "Line is completely inside the window" << endl;


DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
} else if (!(num[0] & num[1])) {

cout << "Line is required to be clipped" << endl;

} else {

cout << "Line is completely outside the window" << endl;

delay(7000);

getch();

closegraph();

}
1. Output:
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
Learning Outcomes:
 Understanding Line Clipping Concepts – Learn how to determine if a line is inside,
outside, or needs clipping using region codes.
 Working with Graphics in Turbo C++ – Gain hands-on experience with initgraph(), line(),
and closegraph() functions.
 Bitwise Operations for Region Coding – Learn how to use bitwise operations to categorize
line endpoints efficiently.
 Handling User Input and Decision Making – Understand how to take user inputs and
apply conditional statements to analyze positions.
 Implementation of Cohen-Sutherland Logic – Get an introduction to a basic form of the
Cohen-Sutherland line clipping algorithm.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy