Question

my subject :Introduction to Computer Graphics Problem #1 You need to write a program which implements...

my subject :Introduction to Computer Graphics

Problem #1

You need to write a program which implements both DDA and Bresenham’s Line Generation Algorithms.

The program should prompt the user to enter tow points coordinate and then compute and display the estimated coordinate of the line segment on the screen.

Example

Please enter your line segment starting point?

10

10

Please enter the coordinate of the line segment end point?

50

30

What algorithm to use

  1. DDA
  2. Bresenham’s

Your program should display he computed coordinates and a graphical image of the plotted line.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

DDA line drawing algorithm

source code:

#include <graphics.h>
#include <math.h>
#include <dos.h>
void main( )
{
float x,y,x1,y1,x2,y2,dx,dy,step;
int i,gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
scanf("%f%f",&x1,&y1);
scanf("%f%f",&x2,&y2);
dx=abs(x2-x1); dy=abs(y2-y1);
if(dx>=dy) step=dx;
else step=dy;
dx=dx/step; dy=dy/step;
x=x1; y=y1; i=1;
outtextxy(x1-5,y1-5,"(x1,y1)");
outtextxy(x2+5,y2+5,"(x2,y2)");
while(i<=step)
{
putpixel(x,y,5); x=x+dx; y=y+dy; i=i+1; delay(60);
}
getch();
}

input:

10

10

50

30

output:

Input :

100

100

500

300

output:

Bresenham’s Line drawing algorithm

source code:

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main() {
int x,y,x1,y1,x2,y2,p,dx,dy;
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");

scanf("%d",&x1);

scanf("%d",&y1);

scanf("%d",&x2);

scanf("%d",&y2);
x=x1;
y=y1;
dx=x2-x1;
dy=y2-y1;
putpixel(x,y,2);
p=(2*dy-dx);
while(x<=x2) {
if(p<0) {
x=x+1;
p=p+2*dy;
}
else {
x=x+1;
y=y+1;
p=p+(2*dy)-(2*dx); }
putpixel(x,y,7); }
getch(); closegraph(); }

input:

10

10

50

30

output:

input:

100

100

500

300

output:

​​​​​​​

Add a comment
Know the answer?
Add Answer to:
my subject :Introduction to Computer Graphics Problem #1 You need to write a program which implements...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help: For this project, you will create a shape drawing program using Turtle graphics. Your...

    Please help: For this project, you will create a shape drawing program using Turtle graphics. Your program will begin by asking the user how many points they would like to enter (# of vertices for the shape). Next, you will use a loop to input each X and Y coordinate and store these coordinates in lists. After inputting all of the coordinates, create a second loop that will draw and fill the shape using the coordinates that were entered. All...

  • help me Problem: Write a simple C program that calculates the corresponding y-coordinate for any x-coordinate...

    help me Problem: Write a simple C program that calculates the corresponding y-coordinate for any x-coordinate onaline defined by two points. These points areinputspecifiedas pairsofxandycoordinates in the two-dimensional Cartesian coordinate system. Youneed to determine the slope ofthe line and they-intercept for the line plotted by these two points and store this data in memory. The programmustpromptthe userforthe coordinates of the first point X1 and then Y1, and then prompt the user for the second point, X2 and then Y2. After...

  • Introduction: In this lab, you will write a MIPS program to read in (up to) 50...

    Introduction: In this lab, you will write a MIPS program to read in (up to) 50 integer values from the user, store them in an array, print out the amay, one number per line, reverse the elements in the array and finally print out the elements in the just-reversed) array. Feel free to do this lab and all assembly programming labs) in Windows. You must use MARS Getting started: l. In MARS, create a new assembly file with the name...

  • Basic C program Problem: In this assignment, you have to read a text file (in.txt) that...

    Basic C program Problem: In this assignment, you have to read a text file (in.txt) that contains a set of point coordinates (x,y). The first line of the file contains the number of points (N) and then each line of the file contains x and y values that are separated by space. The value of x and y are an integer. They can be both negative and positive numbers. You have to sort those points in x-axis major order and...

  • M01 PA C++ Classes and Objects INTRODUCTION: Write a C++ program that implements and utilizes a...

    M01 PA C++ Classes and Objects INTRODUCTION: Write a C++ program that implements and utilizes a Stereo Receiver Class/Object. INCLUDE IN YOUR ASSIGNMENT At the top of each of your C++ programs, you should have at least four lines of documentation: Program name (the C++ file name(s)), Author (your name), Date last updated, and Purpose (a brief description of what the program accomplishes). Here is an example: // Program name: tictactoe.cpp // Author: Rainbow Dash // Date last updated: 5/26/2016...

  • my question is on a java program. i have added all instructions for this homeowrk assignment....

    my question is on a java program. i have added all instructions for this homeowrk assignment. from how the input is entered and what the output should read. im seeing if i can get a psuedo code setup for how the algorithm should be setup. Build an Intersection Check program. User inputs two points as x-y coordinates in twodimension space. Two points represent two end points of a line segment. Then, user can input second two points for the second...

  • Complete the implementation of the point_3d program. This program will help you learn how to use:...

    Complete the implementation of the point_3d program. This program will help you learn how to use: the C language if statement; relational operators; and boolean operators. The program must implement a function which maps real-valued point (x,y) to real value z≥0, as follows: z=2.84898x+1.18569y, when x≥0 and y≥0; z=2.84898x+y2, when x≥0 and y<0; z=x2+1.18569y, when x<0 and y≥0; z=x2+y2, otherwise. To get the values of x and y, display a prompt of the form "Please enter X and Y:" The...

  • Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the...

    Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the user to enter a string. The string will then be displayed back to the user. This is followed by determining the number of alphabetic characters, numeric characters, lower_case letters, upper_case letters, whitespace characters, and then displaying them. The user should be given additional chances to enter additional strings, and each time a string is entered, the above process is to be performed. The inputting...

  • Have been working on this code for awhile and cant get it to work with Glut....

    Have been working on this code for awhile and cant get it to work with Glut. Wondering if there is anything I can fix #include <iostream> #include "graph1.h" using namespace std; //Add Function Prototypes Here int getNoPoints(); void getPoints(int x[], int y[], int no_points); void drawPolyLine(int x[], int y[], int no_points); int main() {    //Variable Declaration/Initialization    int no_points = 0;    const int MAX_POINTS = 10;    int x[MAX_POINTS];    int y[MAX_POINTS];    //Display Graphics Window    displayGraphics();...

  • You must write a C program that prompts the user for two numbers (no command line...

    You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT