SlideShare a Scribd company logo
Interactive Computer Graphics
(Assignment –II)
Submitted in partial fulfilment of the requirements for the degree of
Master of Technology in Information TechnologyMaster of Technology in Information TechnologyMaster of Technology in Information TechnologyMaster of Technology in Information Technology
by
Vijayananda D Mohire
(Enrolment No.921DMTE0113)
Information Technology Department
Karnataka State Open University
Manasagangotri, Mysore – 570006
Karnataka, India
(2009)
MT-11-II
2
Interactive Computer Graphics
MT-11-II
3
CERTIFICATECERTIFICATECERTIFICATECERTIFICATE
This is to certify that the Assignment-II entitled (Interactive Computer
Graphics, subject code: MT11) submitted by Vijayananda D Mohire having
Roll Number 921DMTE0113 for the partial fulfilment of the requirements of
Master of Technology in Information Technology degree of Karnataka
State Open University, Mysore, embodies the bonafide work done by him
under my supervision.
PlacPlacPlacPlace: ________________e: ________________e: ________________e: ________________ Signature of the Internal SupervisorSignature of the Internal SupervisorSignature of the Internal SupervisorSignature of the Internal Supervisor
NameNameNameName
Date: ________________Date: ________________Date: ________________Date: ________________ DesignationDesignationDesignationDesignation
MT-11-II
4
For EvaluationFor EvaluationFor EvaluationFor Evaluation
QuestionQuestionQuestionQuestion
NumberNumberNumberNumber
Maximum MarksMaximum MarksMaximum MarksMaximum Marks MarksMarksMarksMarks
awardedawardedawardedawarded
Comments, if anyComments, if anyComments, if anyComments, if any
1 5
2 5
TOTALTOTALTOTALTOTAL 10
Evaluator’s Name and Signature Date
MT-11-II
5
PrefacePrefacePrefacePreface
This document has been prepared specially for the assignments of M.Tech – IT I
Semester. This is mainly intended for evaluation of assignment of the academic M.Tech
- IT, I semester. I have made a sincere attempt to gather and study the best answers to
the assignment questions and have attempted the responses to the questions. I am
confident that the evaluator’s will find this submission informative and evaluate based
on the provide content.
For clarity and ease of use there is a Table of contents and Evaluators section to make
easier navigation and recording of the marks. A list of references has been provided in
the last page – Bibliography that provides the source of information both internal and
external. Evaluator’s are welcome to provide the necessary comments against each
response, suitable space has been provided at the end of each response.
I am grateful to the Infysys academy, Koramangala, Bangalore in making this a big
success. Many thanks for the timely help and attention in making this possible within
specified timeframe. Special thanks to Mr. Vivek and Mr. Prakash for their timely help
and guidance.
Candidate’s Name and Signature Date
MT-11-II
6
Table of ContentsTable of ContentsTable of ContentsTable of Contents
FFFFOROROROR EEEEVALUATIONVALUATIONVALUATIONVALUATION.............................................................................................................................................................. 4
PPPPREFACEREFACEREFACEREFACE............................................................................................................................................................................. 5
QQQQUESTIONUESTIONUESTIONUESTION 1111........................................................................................................................................................................ 9
AAAANSWERNSWERNSWERNSWER 1(1(1(1(AAAA)))) ..................................................................................................................................................................... 9
AAAANSWNSWNSWNSWERERERER 1(1(1(1(BBBB)))) ...................................................................................................................................................................10
QQQQUESTIONUESTIONUESTIONUESTION 2222......................................................................................................................................................................12
AAAANSWERNSWERNSWERNSWER 2222.........................................................................................................................................................................12
AAAAPPENDIXPPENDIXPPENDIXPPENDIX COMPLETE CODE .......................................................................................................................................15
DDADDADDADDA LLLLINEINEINEINE AAAALGORITHMLGORITHMLGORITHMLGORITHM..................................................................................................................................................15
BBBBRESENHAMRESENHAMRESENHAMRESENHAM LLLLINEINEINEINE AAAALGORITHMLGORITHMLGORITHMLGORITHM....................................................................................................................................18
DDADDADDADDA CCCCIRCLEIRCLEIRCLEIRCLE AAAALGORITHMLGORITHMLGORITHMLGORITHM............................................................................................................................................19
BBBBIBLIOGRAPHYIBLIOGRAPHYIBLIOGRAPHYIBLIOGRAPHY.................................................................................................................................................................22
MT-11-II
7
Table of FiguresTable of FiguresTable of FiguresTable of Figures
Figure 1Figure 1Figure 1Figure 1 DDA Input for Line (Colin, 1991)........................................................................................................................................9
Figure 2Figure 2Figure 2Figure 2 DDA Output for Line (Colin, 1991)....................................................................................................................................9
Figure 3Figure 3Figure 3Figure 3 DDA Algorithm (Anonymous, C++ > Computer Graphics sample source codes, 2009)..........................10
Figure 4Figure 4Figure 4Figure 4 Bresenham Input for Line (Colin, 1991)........................................................................................................................10
Figure 5Figure 5Figure 5Figure 5 Bresenham Output for Line (Colin, 1991)....................................................................................................................11
Figure 6Figure 6Figure 6Figure 6 Bresenham Algorithm (Anonymous, C > Games and Graphics sample source codes, 2009)..............11
Figure 7Figure 7Figure 7Figure 7 DDA Circle input (Colin, 1991)..........................................................................................................................................12
Figure 8Figure 8Figure 8Figure 8 DDA Circle output (Colin, 1991).......................................................................................................................................13
Figure 9Figure 9Figure 9Figure 9 DDA Algorithm for Circle (Anonymous, C++ > Computer Graphics sample source codes, 2009)......13
MT-11-II
8
INTERACTIVE COMPUTER GRAPHICSINTERACTIVE COMPUTER GRAPHICSINTERACTIVE COMPUTER GRAPHICSINTERACTIVE COMPUTER GRAPHICS
RESPONSRESPONSRESPONSRESPONSE TO ASSIGNMENTE TO ASSIGNMENTE TO ASSIGNMENTE TO ASSIGNMENT –––– IIIIIIII
MT-11-II
9
Question 1Question 1Question 1Question 1 Write any two program in C/C++ for different line drawing
algorithms? Also explain me O/P obtained?
Answer 1(a)Answer 1(a)Answer 1(a)Answer 1(a)
DDA Algorithm for Line drawing
Input:
FigureFigureFigureFigure 1111 DDA Input for Line (Colin, 1991)
Output:
FigureFigureFigureFigure 2222 DDA Output for Line (Colin, 1991)
Explanation:
Below provides the method used to demonstrate the DDA Algorithm. More details
can be obtained from the C++ code provided in Appendix....
MT-11-II
10
FigureFigureFigureFigure 3333 DDA Algorithm (Anonymous, C++ > Computer Graphics sample source
codes, 2009)
From above code it is illustrated that the DDA provides fair amount of LINE drawing.
Answer 1(b)Answer 1(b)Answer 1(b)Answer 1(b)
Bresenham Algorithm for Line drawing:
Input:Input:Input:Input:
FigureFigureFigureFigure 4444 Bresenham Input for Line (Colin, 1991)
MT-11-II
11
Output:Output:Output:Output:
FigureFigureFigureFigure 5555 Bresenham Output for Line (Colin, 1991)
Explanation:
Below provides the method used to demonstrate the Bresenham Algorithm. More
details can
be obtained
from the
C++ code
provided in
Appendix....
FigureFigureFigureFigure 6666
Bresenham
Algorithm
(Anonymou
s, C >
Games and
Graphics
sample
MT-11-II
12
source codes, 2009)
Evaluator’s Comments if any:
Question 2Question 2Question 2Question 2 Write a program in C/C++ for circle generating algorithm?
Answer 2Answer 2Answer 2Answer 2
Input:
FigureFigureFigureFigure 7777 DDA Circle input (Colin, 1991)
Output:
MT-11-II
13
FigureFigureFigureFigure 8888 DDA Circle output (Colin, 1991)
Explanation:
FigureFigureFigureFigure 9999 DDA Algorithm for Circle (Anonymous, C++ > Computer Graphics sample
source codes, 2009)
MT-11-II
14
Evaluator’s Comments if any:
MT-11-II
15
AppendixAppendixAppendixAppendix Complete Code
DDA Line AlgorithmDDA Line AlgorithmDDA Line AlgorithmDDA Line Algorithm
#include "winbgim.h"
#include <iostream>
#include<conio.h>
#include<math.h>
#include<dos.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
class lines
{
private:
int length,x1,y1,x2,y2,x,y,dx,dy,wx,wy,w,width;
public:
lines(); //Constructor
void showline();
int sign(int);
};
int lines::sign(int xx)
{
if(xx<0)
return -1;
if(xx==0)
return 0;
if(xx>0)
return 1;
return 0;
}
lines::lines()
{
x=0;y=0;
MT-11-II
16
cout<<" Enter The Co-Ordinates (x1,y1) :=";
// cout<<" Enter The Co-Ordinates (x1,y1):=";
cin >> x1 >> y1;
cout << " Enter The Co-Ordinates (x2,y2):=";
cin >> x2 >> y2;
cout<<"Enter The Width Of The Line :=";
cin >> width;
}
void lines::showline()
{
char *s,*s1;
int j=0;
if(abs(x2-x1)>=abs(y2-y1))
length=abs(x2-x1);
else
length=abs(y2-y1);
w=width;
float sqrt1 = ((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))/abs(y2-y1);
wx=((w-1)/2)*(sqrt(sqrt1));
float sqrt2 = ((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))/abs(x2-x1);
wy=((w-1)/2)*(sqrt(sqrt2));
dx=(x2-x1)/length;
dy=(y2-y1)/length;
if(dy>dx)
wy=wx;
x=x1+0.5*sign(dx);
y=y1+0.5*sign(dy);
int i=1;
setcolor(0);
while(i<=length)
{
for(j=0;j<wy;j++)
MT-11-II
17
putpixel((x),(y+j),6);
for(j=0;j<wy;j++)
putpixel((x),(y-j),6);
putpixel((x),(y),6);
x+=dx;
y+=dy;
i++;
}
setcolor(15);
outtextxy(800,10,"The Points Are:=");
sprintf(s,"A(%d,%d)",x1,y1);
outtextxy(800,20,s);
sprintf(s,"B(%d,%d)",x2,y2);
outtextxy(800,30,s);
getch();
}
int main()
{
lines a;
initwindow(800,600);
a.showline();
closegraph();
return 0;
}
MT-11-II
18
BresenhamBresenhamBresenhamBresenham Line AlgorithmLine AlgorithmLine AlgorithmLine Algorithm
#include<stdio.h>
#include<conio.h>
#include "winbgim.h"
int main()
{
int gd = DETECT, gm;
int dx, dy, p, end;
float x1, x2, y1, y2, x, y;
// initgraph(&gd, &gm, "c:tcbgi");
initwindow(800,600);
printf("Enter Value of X1: ");
scanf("%f", &x1);
printf("Enter Value of Y1: ");
scanf("%f", &y1);
printf("Enter Value of X2: ");
scanf("%f", &x2);
printf("Enter Value of Y2: ");
scanf("%f", &y2);
dx = abs(x1 - x2);
dy = abs(y1 - y2);
p = 2 * dy - dx;
if(x1 > x2)
{
x = x2;
y = y2;
end = x1;
}
else
{
x = x1;
y = y1;
end = x2;
}
putpixel(x, y, 10);
while(x < end)
{
x = x + 1;
MT-11-II
19
if(p < 0)
{
p = p + 2 * dy;
}
else
{
y = y + 1;
p = p + 2 * (dy - dx);
}
putpixel(x, y, 10);
}
getch();
closegraph();
return 0;
}
DDA Circle AlgorithmDDA Circle AlgorithmDDA Circle AlgorithmDDA Circle Algorithm
//Program to implement DDA Circle Drawing Algorithm
#include<iostream.h>
#include "winbgim.h"
#include<conio.h>
#include<math.h>
#include<dos.h>
#include<stdlib.h>
#include<stdio.h>
class myCircle
{
private:
float x,y,r,d,x1,y1;
public:
myCircle(); //Constructor
MT-11-II
20
void showCircle();
int sign(int);
};
int myCircle::sign(int xx)
{
if(xx<0)
return -1;
if(xx==0)
return 0;
if(xx>0)
return 1;
return 0;
}
myCircle::myCircle()
{
x=0;y=0;
cout << "Enter The Co-Ordinates Of The Circle :=";
cin >> x1 >> y1;
cout << "Enter The Radius Of The Circle :=";
cin >> r;
}
void myCircle::showCircle()
{
char *s;
int s1,s2,ic;
x=x1;y=y1;
float i=0;
while(i<=360)
{
x=x1+r*cos(i);
y=y1+r*sin(i);
putpixel((x),(y),7);
i+=0.5;
}
getch();
}
int main()
MT-11-II
21
{
int i,j,xx=220,xxx=430;
myCircle a;
initwindow(800,600);
a.showCircle();
closegraph();
return 0;
}
MT-11-II
22
BibliographyBibliographyBibliographyBibliography
Anonymous. (2009). C > Games and Graphics sample source codes. Retrieved October 2009, from Happy Codings:
http://www.c.happycodings.com/Games_and_Graphics/code18.html
Anonymous. (2009). C++ > Computer Graphics sample source codes. Retrieved October 2009, from Happy Codings:
http://www.cplusplus.happycodings.com/Computer_Graphics/code18.html
Anonymous. (2009). C++ > Computer Graphics sample source codes. Retrieved October 2009, from Happy Codings:
http://www.cplusplus.happycodings.com/Computer_Graphics/code17.html
Colin, M. ,. (1991). Dev-C++. USA.

More Related Content

PDF
MTech - OOSE_Assignment
PDF
BCA Syllabus
PDF
Cse
PDF
Syllabus of BCA Second Year JAMMU University
DOCX
ICT Form 4 MAY 2015 test paper
DOC
Mca 101
DOC
Cad course
PDF
Contact management system
MTech - OOSE_Assignment
BCA Syllabus
Cse
Syllabus of BCA Second Year JAMMU University
ICT Form 4 MAY 2015 test paper
Mca 101
Cad course
Contact management system

Similar to M.Tech : Interactive Computer Graphics Assignment II (20)

PDF
M.Tech : Interactive Computer Graphics Assignment I
PDF
MTech - Algorithm analysis and design assignment
PDF
Computer Science Paper 1 (Theory) - 2017.pdf
PDF
MCA-ASS-Semester V.pdf
PDF
M.Tech: Algorithm Analysis and Design Assignment II
DOC
NET_Solved ans
PDF
UGC NET COMPUTER SCIENCE JUNE 2009 PAPER-II
PDF
Pgcet Computer Science 2015 question paper
PDF
CAPE Computer Science Unit 1 Paper 1 - Practice Paper
DOC
173448987 se3-4-it-2008
DOCX
ECET350 Final Exam Study GuideYOU MAY WANT TO PRINT THIS GUIDE.1.docx
DOCX
DSP_Lab_MAnual_-_Final_Edition[1].docx
PDF
DSP_Lab_MAnual_-_Final_Edition.pdf
PDF
Mmt 001
PDF
famous placement papers
PDF
PGCET Computer science 2017 question paper
PDF
B.Sc.IT: Semester - VI (December - 2017) [IDOL - Revised Course | Question Pa...
PDF
Combinational & Sequential ATPG.pdf
PDF
AP PGECET Computer Science 2016 question paper
PPTX
M.Tech : Interactive Computer Graphics Assignment I
MTech - Algorithm analysis and design assignment
Computer Science Paper 1 (Theory) - 2017.pdf
MCA-ASS-Semester V.pdf
M.Tech: Algorithm Analysis and Design Assignment II
NET_Solved ans
UGC NET COMPUTER SCIENCE JUNE 2009 PAPER-II
Pgcet Computer Science 2015 question paper
CAPE Computer Science Unit 1 Paper 1 - Practice Paper
173448987 se3-4-it-2008
ECET350 Final Exam Study GuideYOU MAY WANT TO PRINT THIS GUIDE.1.docx
DSP_Lab_MAnual_-_Final_Edition[1].docx
DSP_Lab_MAnual_-_Final_Edition.pdf
Mmt 001
famous placement papers
PGCET Computer science 2017 question paper
B.Sc.IT: Semester - VI (December - 2017) [IDOL - Revised Course | Question Pa...
Combinational & Sequential ATPG.pdf
AP PGECET Computer Science 2016 question paper
Ad

More from Vijayananda Mohire (20)

PDF
Bhadale QAI Hub - for multicloud, multitechnology platform
PDF
Practical_Introduction_to_Quantum_Safe_Cryptography
PDF
Progress Report- MIT Course 8.371.3x - VD-Mohire
PDF
Quantum Communications Q&A with Gemini LLM
PDF
Peer Review Certificate for Journal of Engg
PDF
Quantum Algorithms for Electronics - IEEE Certificate
PDF
NexGen Solutions for cloud platforms, powered by GenQAI
PDF
Certificate- Peer Review of Book Chapter on ML
PDF
Key projects Data Science and Engineering
PDF
Key projects Data Science and Engineering
PDF
Bhadale IT Hub-Multi Cloud and Multi QAI
PDF
My key hands-on projects in Quantum, and QAI
PDF
Azure Quantum Workspace for developing Q# based quantum circuits
PDF
Key projects in AI, ML and Generative AI
PDF
My Journey towards Artificial Intelligence
PDF
Bhadale IT Cloud Solutions for Agriculture
PDF
Bhadale IT Cloud Solutions for Agriculture
PDF
Bhadale IT Intel and Azure Cloud Offerings
PDF
GitHub Copilot-vijaymohire
PDF
Practical ChatGPT From Use Cases to Prompt Engineering & Ethical Implications
Bhadale QAI Hub - for multicloud, multitechnology platform
Practical_Introduction_to_Quantum_Safe_Cryptography
Progress Report- MIT Course 8.371.3x - VD-Mohire
Quantum Communications Q&A with Gemini LLM
Peer Review Certificate for Journal of Engg
Quantum Algorithms for Electronics - IEEE Certificate
NexGen Solutions for cloud platforms, powered by GenQAI
Certificate- Peer Review of Book Chapter on ML
Key projects Data Science and Engineering
Key projects Data Science and Engineering
Bhadale IT Hub-Multi Cloud and Multi QAI
My key hands-on projects in Quantum, and QAI
Azure Quantum Workspace for developing Q# based quantum circuits
Key projects in AI, ML and Generative AI
My Journey towards Artificial Intelligence
Bhadale IT Cloud Solutions for Agriculture
Bhadale IT Cloud Solutions for Agriculture
Bhadale IT Intel and Azure Cloud Offerings
GitHub Copilot-vijaymohire
Practical ChatGPT From Use Cases to Prompt Engineering & Ethical Implications
Ad

Recently uploaded (20)

PDF
Designing Intelligence for the Shop Floor.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
System and Network Administration Chapter 2
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
PTS Company Brochure 2025 (1).pdf.......
Designing Intelligence for the Shop Floor.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
Digital Systems & Binary Numbers (comprehensive )
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
System and Network Administration Chapter 2
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Design an Analysis of Algorithms II-SECS-1021-03
Why Generative AI is the Future of Content, Code & Creativity?
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Softaken Excel to vCard Converter Software.pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
iTop VPN Free 5.6.0.5262 Crack latest version 2025
L1 - Introduction to python Backend.pptx
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Upgrade and Innovation Strategies for SAP ERP Customers
Reimagine Home Health with the Power of Agentic AI​
PTS Company Brochure 2025 (1).pdf.......

M.Tech : Interactive Computer Graphics Assignment II

  • 1. Interactive Computer Graphics (Assignment –II) Submitted in partial fulfilment of the requirements for the degree of Master of Technology in Information TechnologyMaster of Technology in Information TechnologyMaster of Technology in Information TechnologyMaster of Technology in Information Technology by Vijayananda D Mohire (Enrolment No.921DMTE0113) Information Technology Department Karnataka State Open University Manasagangotri, Mysore – 570006 Karnataka, India (2009)
  • 3. MT-11-II 3 CERTIFICATECERTIFICATECERTIFICATECERTIFICATE This is to certify that the Assignment-II entitled (Interactive Computer Graphics, subject code: MT11) submitted by Vijayananda D Mohire having Roll Number 921DMTE0113 for the partial fulfilment of the requirements of Master of Technology in Information Technology degree of Karnataka State Open University, Mysore, embodies the bonafide work done by him under my supervision. PlacPlacPlacPlace: ________________e: ________________e: ________________e: ________________ Signature of the Internal SupervisorSignature of the Internal SupervisorSignature of the Internal SupervisorSignature of the Internal Supervisor NameNameNameName Date: ________________Date: ________________Date: ________________Date: ________________ DesignationDesignationDesignationDesignation
  • 4. MT-11-II 4 For EvaluationFor EvaluationFor EvaluationFor Evaluation QuestionQuestionQuestionQuestion NumberNumberNumberNumber Maximum MarksMaximum MarksMaximum MarksMaximum Marks MarksMarksMarksMarks awardedawardedawardedawarded Comments, if anyComments, if anyComments, if anyComments, if any 1 5 2 5 TOTALTOTALTOTALTOTAL 10 Evaluator’s Name and Signature Date
  • 5. MT-11-II 5 PrefacePrefacePrefacePreface This document has been prepared specially for the assignments of M.Tech – IT I Semester. This is mainly intended for evaluation of assignment of the academic M.Tech - IT, I semester. I have made a sincere attempt to gather and study the best answers to the assignment questions and have attempted the responses to the questions. I am confident that the evaluator’s will find this submission informative and evaluate based on the provide content. For clarity and ease of use there is a Table of contents and Evaluators section to make easier navigation and recording of the marks. A list of references has been provided in the last page – Bibliography that provides the source of information both internal and external. Evaluator’s are welcome to provide the necessary comments against each response, suitable space has been provided at the end of each response. I am grateful to the Infysys academy, Koramangala, Bangalore in making this a big success. Many thanks for the timely help and attention in making this possible within specified timeframe. Special thanks to Mr. Vivek and Mr. Prakash for their timely help and guidance. Candidate’s Name and Signature Date
  • 6. MT-11-II 6 Table of ContentsTable of ContentsTable of ContentsTable of Contents FFFFOROROROR EEEEVALUATIONVALUATIONVALUATIONVALUATION.............................................................................................................................................................. 4 PPPPREFACEREFACEREFACEREFACE............................................................................................................................................................................. 5 QQQQUESTIONUESTIONUESTIONUESTION 1111........................................................................................................................................................................ 9 AAAANSWERNSWERNSWERNSWER 1(1(1(1(AAAA)))) ..................................................................................................................................................................... 9 AAAANSWNSWNSWNSWERERERER 1(1(1(1(BBBB)))) ...................................................................................................................................................................10 QQQQUESTIONUESTIONUESTIONUESTION 2222......................................................................................................................................................................12 AAAANSWERNSWERNSWERNSWER 2222.........................................................................................................................................................................12 AAAAPPENDIXPPENDIXPPENDIXPPENDIX COMPLETE CODE .......................................................................................................................................15 DDADDADDADDA LLLLINEINEINEINE AAAALGORITHMLGORITHMLGORITHMLGORITHM..................................................................................................................................................15 BBBBRESENHAMRESENHAMRESENHAMRESENHAM LLLLINEINEINEINE AAAALGORITHMLGORITHMLGORITHMLGORITHM....................................................................................................................................18 DDADDADDADDA CCCCIRCLEIRCLEIRCLEIRCLE AAAALGORITHMLGORITHMLGORITHMLGORITHM............................................................................................................................................19 BBBBIBLIOGRAPHYIBLIOGRAPHYIBLIOGRAPHYIBLIOGRAPHY.................................................................................................................................................................22
  • 7. MT-11-II 7 Table of FiguresTable of FiguresTable of FiguresTable of Figures Figure 1Figure 1Figure 1Figure 1 DDA Input for Line (Colin, 1991)........................................................................................................................................9 Figure 2Figure 2Figure 2Figure 2 DDA Output for Line (Colin, 1991)....................................................................................................................................9 Figure 3Figure 3Figure 3Figure 3 DDA Algorithm (Anonymous, C++ > Computer Graphics sample source codes, 2009)..........................10 Figure 4Figure 4Figure 4Figure 4 Bresenham Input for Line (Colin, 1991)........................................................................................................................10 Figure 5Figure 5Figure 5Figure 5 Bresenham Output for Line (Colin, 1991)....................................................................................................................11 Figure 6Figure 6Figure 6Figure 6 Bresenham Algorithm (Anonymous, C > Games and Graphics sample source codes, 2009)..............11 Figure 7Figure 7Figure 7Figure 7 DDA Circle input (Colin, 1991)..........................................................................................................................................12 Figure 8Figure 8Figure 8Figure 8 DDA Circle output (Colin, 1991).......................................................................................................................................13 Figure 9Figure 9Figure 9Figure 9 DDA Algorithm for Circle (Anonymous, C++ > Computer Graphics sample source codes, 2009)......13
  • 8. MT-11-II 8 INTERACTIVE COMPUTER GRAPHICSINTERACTIVE COMPUTER GRAPHICSINTERACTIVE COMPUTER GRAPHICSINTERACTIVE COMPUTER GRAPHICS RESPONSRESPONSRESPONSRESPONSE TO ASSIGNMENTE TO ASSIGNMENTE TO ASSIGNMENTE TO ASSIGNMENT –––– IIIIIIII
  • 9. MT-11-II 9 Question 1Question 1Question 1Question 1 Write any two program in C/C++ for different line drawing algorithms? Also explain me O/P obtained? Answer 1(a)Answer 1(a)Answer 1(a)Answer 1(a) DDA Algorithm for Line drawing Input: FigureFigureFigureFigure 1111 DDA Input for Line (Colin, 1991) Output: FigureFigureFigureFigure 2222 DDA Output for Line (Colin, 1991) Explanation: Below provides the method used to demonstrate the DDA Algorithm. More details can be obtained from the C++ code provided in Appendix....
  • 10. MT-11-II 10 FigureFigureFigureFigure 3333 DDA Algorithm (Anonymous, C++ > Computer Graphics sample source codes, 2009) From above code it is illustrated that the DDA provides fair amount of LINE drawing. Answer 1(b)Answer 1(b)Answer 1(b)Answer 1(b) Bresenham Algorithm for Line drawing: Input:Input:Input:Input: FigureFigureFigureFigure 4444 Bresenham Input for Line (Colin, 1991)
  • 11. MT-11-II 11 Output:Output:Output:Output: FigureFigureFigureFigure 5555 Bresenham Output for Line (Colin, 1991) Explanation: Below provides the method used to demonstrate the Bresenham Algorithm. More details can be obtained from the C++ code provided in Appendix.... FigureFigureFigureFigure 6666 Bresenham Algorithm (Anonymou s, C > Games and Graphics sample
  • 12. MT-11-II 12 source codes, 2009) Evaluator’s Comments if any: Question 2Question 2Question 2Question 2 Write a program in C/C++ for circle generating algorithm? Answer 2Answer 2Answer 2Answer 2 Input: FigureFigureFigureFigure 7777 DDA Circle input (Colin, 1991) Output:
  • 13. MT-11-II 13 FigureFigureFigureFigure 8888 DDA Circle output (Colin, 1991) Explanation: FigureFigureFigureFigure 9999 DDA Algorithm for Circle (Anonymous, C++ > Computer Graphics sample source codes, 2009)
  • 15. MT-11-II 15 AppendixAppendixAppendixAppendix Complete Code DDA Line AlgorithmDDA Line AlgorithmDDA Line AlgorithmDDA Line Algorithm #include "winbgim.h" #include <iostream> #include<conio.h> #include<math.h> #include<dos.h> #include<stdlib.h> #include<stdio.h> using namespace std; class lines { private: int length,x1,y1,x2,y2,x,y,dx,dy,wx,wy,w,width; public: lines(); //Constructor void showline(); int sign(int); }; int lines::sign(int xx) { if(xx<0) return -1; if(xx==0) return 0; if(xx>0) return 1; return 0; } lines::lines() { x=0;y=0;
  • 16. MT-11-II 16 cout<<" Enter The Co-Ordinates (x1,y1) :="; // cout<<" Enter The Co-Ordinates (x1,y1):="; cin >> x1 >> y1; cout << " Enter The Co-Ordinates (x2,y2):="; cin >> x2 >> y2; cout<<"Enter The Width Of The Line :="; cin >> width; } void lines::showline() { char *s,*s1; int j=0; if(abs(x2-x1)>=abs(y2-y1)) length=abs(x2-x1); else length=abs(y2-y1); w=width; float sqrt1 = ((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))/abs(y2-y1); wx=((w-1)/2)*(sqrt(sqrt1)); float sqrt2 = ((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))/abs(x2-x1); wy=((w-1)/2)*(sqrt(sqrt2)); dx=(x2-x1)/length; dy=(y2-y1)/length; if(dy>dx) wy=wx; x=x1+0.5*sign(dx); y=y1+0.5*sign(dy); int i=1; setcolor(0); while(i<=length) { for(j=0;j<wy;j++)
  • 18. MT-11-II 18 BresenhamBresenhamBresenhamBresenham Line AlgorithmLine AlgorithmLine AlgorithmLine Algorithm #include<stdio.h> #include<conio.h> #include "winbgim.h" int main() { int gd = DETECT, gm; int dx, dy, p, end; float x1, x2, y1, y2, x, y; // initgraph(&gd, &gm, "c:tcbgi"); initwindow(800,600); printf("Enter Value of X1: "); scanf("%f", &x1); printf("Enter Value of Y1: "); scanf("%f", &y1); printf("Enter Value of X2: "); scanf("%f", &x2); printf("Enter Value of Y2: "); scanf("%f", &y2); dx = abs(x1 - x2); dy = abs(y1 - y2); p = 2 * dy - dx; if(x1 > x2) { x = x2; y = y2; end = x1; } else { x = x1; y = y1; end = x2; } putpixel(x, y, 10); while(x < end) { x = x + 1;
  • 19. MT-11-II 19 if(p < 0) { p = p + 2 * dy; } else { y = y + 1; p = p + 2 * (dy - dx); } putpixel(x, y, 10); } getch(); closegraph(); return 0; } DDA Circle AlgorithmDDA Circle AlgorithmDDA Circle AlgorithmDDA Circle Algorithm //Program to implement DDA Circle Drawing Algorithm #include<iostream.h> #include "winbgim.h" #include<conio.h> #include<math.h> #include<dos.h> #include<stdlib.h> #include<stdio.h> class myCircle { private: float x,y,r,d,x1,y1; public: myCircle(); //Constructor
  • 20. MT-11-II 20 void showCircle(); int sign(int); }; int myCircle::sign(int xx) { if(xx<0) return -1; if(xx==0) return 0; if(xx>0) return 1; return 0; } myCircle::myCircle() { x=0;y=0; cout << "Enter The Co-Ordinates Of The Circle :="; cin >> x1 >> y1; cout << "Enter The Radius Of The Circle :="; cin >> r; } void myCircle::showCircle() { char *s; int s1,s2,ic; x=x1;y=y1; float i=0; while(i<=360) { x=x1+r*cos(i); y=y1+r*sin(i); putpixel((x),(y),7); i+=0.5; } getch(); } int main()
  • 22. MT-11-II 22 BibliographyBibliographyBibliographyBibliography Anonymous. (2009). C > Games and Graphics sample source codes. Retrieved October 2009, from Happy Codings: http://www.c.happycodings.com/Games_and_Graphics/code18.html Anonymous. (2009). C++ > Computer Graphics sample source codes. Retrieved October 2009, from Happy Codings: http://www.cplusplus.happycodings.com/Computer_Graphics/code18.html Anonymous. (2009). C++ > Computer Graphics sample source codes. Retrieved October 2009, from Happy Codings: http://www.cplusplus.happycodings.com/Computer_Graphics/code17.html Colin, M. ,. (1991). Dev-C++. USA.