Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following line drawing code: int Image[10][10]; void draw_line(int x1, int y1, int x2, int y2, int value) { double dx = x2 -

Consider the following line drawing code:

int Image[10][10];

void draw_line(int x1, int y1, int x2, int y2, int value)

{

double dx = x2 - x1;

double dy = y2 - y1;

2

if (dx < dy)

{

double x = x1 + 0.5;

for (int y = y1; y <= y2; y++)

{

Image[y][(int)x] = value;

x += dx/dy;

}

}

else

{

double y = y1 + 0.5;

for (int x = x1; x <= x2; x++)

{

Image[(int)y][x] = value;

y += dy/dx;

}

}

}

a) Consider what happens if we call draw_line(3,2, 7,7, 1) from the main program. What will the values of dx and dy be? Show the resulting line in the image above.

b) Consider what happens if we call draw_line(2,9, 4,1, 2) from the main program. What will the values of dx and dy be? Show the resulting line in the image above.

c) What is the primary advantage of the Bresenham line drawing algorithm compared to the simple DDA approach above?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago