Question: // Used for onput & output stream #include // Used for round() function #include using namespace std; // Main function int main() { // Variables
// Used for onput & output stream
#include
// Used for round() function
#include
using namespace std;
// Main function
int main()
{
// Variables used to store coordinates of start and end points
int x0, y0, x1, y1;
// Take coordinates of start point
cout
cin >> x0 >> y0;
// Take coordinates of end point
cout
cin >> x1 >> y1;
// Find dx & dy
int dx = x1 - x0;
int dy = y1 - y0;
// Find number of steps required for generating pixels
int steps = abs(dx) > abs(dy) ? abs(dx) : abs(dy);
// Find the increment in x & y for each steps
float Xinc = dx / (float) steps;
float Yinc = dy / (float) steps;
// Varibale store each coordinates of line
float x = x0;
float y = y0;
// Print the table header
cout
// Loop to find the coordinates of line
for (int i = 0; i
{
// Print points
cout
Midpoint Line Drawing Algorithm Example-1: Draw line A(4, 8) and B(10, 12) using midpoint line drawing algorithm Solution: - Here starting point is (4.8) and ending point is (10, 12). We have = dx = X2 - Xi = dy = Y2 - Y = 10 - 4 = 12 - 8 = 6 = 4 = m = dy dx = 4/6 = 0.67 ::m 0 As do > 0, NE is chosen and the next pixel to be plotted will be Y+ 1) = (5,9) SCREENCAST MATICcout
// increment in x
x += Xinc;
// increment in y
y += Yinc;
}
return 0;
}
The above code is written in dda format. I want the same, but in midpoint format, to solve the problem in the image
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
