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