Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!