Question: Line Drawing Consider the following simple line drawing code: int Image[10][10]; void draw_line(int x1, int y1, int x2, int y2, int value) { // Calculate

Line Drawing

Consider the following simple line drawing code:

int Image[10][10];

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

{

// Calculate step size

int dx = x2 - x1;

int dy = y2 - y1;

double step = (double)dx / (double)dy;

// Draw points on line

double x = x1 + 0.5;

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

{

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

x += step;

}

}

a) Which pixels are modified when we draw a line from (2,2) to (4,8)?

b) What would happen if the line we draw has dy < dx?

c) What would happen if the line we draw has dy < 0?

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!