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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started