Question: Consider the following DDA line drawing code: int Image[20][20]; void draw_line(int x1, int y1, int x2, int y2, int value) { // Calculate step size

Consider the following DDA line drawing code:

int Image[20][20]; void draw_line(int x1, int y1, int x2, int y2, int value) {

// Calculate step size double dx = x2 - x1; double dy = y2 - y1;

// Draw points on line double x = x1 + 0.5; for (int y = y1; y <= y2; y++) {

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

x += dx/dy; }

}

a) Trace the draw_line function above to determine which (x,y) locations in the image will be modified when drawing a line from (10,5) to (15,15).

b) How many integer arithmetic operations (+,-,*,/) are needed to draw this line?

c) How many floating point arithmetic operations (+,-,*,/) are needed to draw this line?

d) What would happen with this code 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!