- # Mid-Point Ellipse Drawing Algorithm
- from matplotlib import pyplot as plt
- def midptellipse(rx, ry, xc, yc):
- xcoordinates = []
- ycoordinates = []
- x = 0;
- y = ry; # it represent minor axis b
- xcoordinates.append(x)
- ycoordinates.append(y)
- # Here, ry = b and rx = a
- # Initial decision parameter of region 1
- d1 = ((ry * ry) - (rx * rx * ry) +
- (0.25 * rx * rx));
- # dstart1= b*b - (a*a)b + (a*a)/4
- dx = 2 * ry * ry * x; # dx = 2 *(b*b)x OR i component
- dy = 2 * rx * rx * y; # dy = 2 *(a*a)y OR j component
- # First Quddrant
- # For region 1
- while (dx < dy):
- xcoordinates.append(x)
- ycoordinates.append(y)
- # Checking and updating value of
- # decision parameter based on algorithm
- if (d1 < 0): # if E is selected
- x += 1;
- dx = dx + (2 * ry * ry);
- d1 = d1 + dx + (ry * ry);
- xcoordinates.append(x)
- ycoordinates.append(y)
- else: # if SE is selected
- x += 1;
- y -= 1;
- dx = dx + (2 * ry * ry);
- dy = dy - (2 * rx * rx);
- d1 = d1 + dx - dy + (ry * ry);
- xcoordinates.append(x)
- ycoordinates.append(y)
- # Decision parameter of region 2
- d2 = (((ry * ry) * ((x + 0.5) * (x + 0.5))) +
- ((rx * rx) * ((y - 1) * (y - 1))) -
- (rx * rx * ry * ry));
- # Plotting points of region 2
- while (y >= 0):
- xcoordinates.append(x)
- ycoordinates.append(y)
- # Checking and updating parameter
- # value based on algorithm
- if (d2 > 0):
- y -= 1;
- dy = dy - (2 * rx * rx);
- d2 = d2 + (rx * rx) - dy;
- xcoordinates.append(x)
- ycoordinates.append(y)
- else:
- y -= 1;
- x += 1;
- dx = dx + (2 * ry * ry);
- dy = dy - (2 * rx * rx);
- d2 = d2 + dx - dy + (rx * rx);
- xcoordinates.append(x)
- ycoordinates.append(y)
- plt.plot(xcoordinates, ycoordinates, marker='o', markersize=3,
- markerfacecolor="red")
- plt.show()
- # draw an ellipse of major and minor radius and centered at (0, 0)
- midptellipse(1000, 950, 0, 0);
- # Mid-Point Ellipse Drawing Algorithm
- from matplotlib import pyplot as plt
- def midptellipse(rx, ry, xc, yc):
- xcoordinates = []
- ycoordinates = []
- x = 0;
- y = ry; # it represent minor axis b
- xcoordinates.append(-x)
- ycoordinates.append(y)
- # Here, ry = b and rx = a
- # Initial decision parameter of region 1
- d1 = ((ry * ry) - (rx * rx * ry) +
- (0.25 * rx * rx));
- # dstart1= b*b - (a*a)b + (a*a)/4
- dx = 2 * ry * ry * x; # dx = 2 *(b*b)x OR i component
- dy = 2 * rx * rx * y; # dy = 2 *(a*a)y OR j component
- # First Quddrant
- # For region 1
- while (dx < dy):
- xcoordinates.append(-x)
- ycoordinates.append(y)
- # Checking and updating value of
- # decision parameter based on algorithm
- if (d1 < 0): # if E is selected
- x += 1;
- dx = dx + (2 * ry * ry);
- d1 = d1 + dx + (ry * ry);
- xcoordinates.append(-x)
- ycoordinates.append(y)
- else: # if SE is selected
- x += 1;
- y -= 1;
- dx = dx + (2 * ry * ry);
- dy = dy - (2 * rx * rx);
- d1 = d1 + dx - dy + (ry * ry);
- xcoordinates.append(-x)
- ycoordinates.append(y)
- # Decision parameter of region 2
- d2 = (((ry * ry) * ((x + 0.5) * (x + 0.5))) +
- ((rx * rx) * ((y - 1) * (y - 1))) -
- (rx * rx * ry * ry));
- # Plotting points of region 2
- while (y >= 0):
- xcoordinates.append(-x)
- ycoordinates.append(y)
- # Checking and updating parameter
- # value based on algorithm
- if (d2 > 0):
- y -= 1;
- dy = dy - (2 * rx * rx);
- d2 = d2 + (rx * rx) - dy;
- xcoordinates.append(-x)
- ycoordinates.append(y)
- else:
- y -= 1;
- x += 1;
- dx = dx + (2 * ry * ry);
- dy = dy - (2 * rx * rx);
- d2 = d2 + dx - dy + (rx * rx);
- xcoordinates.append(-x)
- ycoordinates.append(y)
- plt.plot(xcoordinates, ycoordinates, marker='o', markersize=3,
- markerfacecolor="red")
- plt.show()
- # draw an ellipse of major and minor radius and centered at (0, 0)
- # Mid-Point Ellipse Drawing Algorithm
- from matplotlib import pyplot as plt
- def midptellipse(rx, ry, xc, yc):
- xcoordinates = []
- ycoordinates = []
- x = 0;
- y = ry; # it represent minor axis b
- xcoordinates.append(-x)
- ycoordinates.append(-y)
- # Here, ry = b and rx = a
- # Initial decision parameter of region 1
- d1 = ((ry * ry) - (rx * rx * ry) +
- (0.25 * rx * rx));
- # dstart1= b*b - (a*a)b + (a*a)/4
- dx = 2 * ry * ry * x; # dx = 2 *(b*b)x OR i component
- dy = 2 * rx * rx * y; # dy = 2 *(a*a)y OR j component
- # First Quddrant
- # For region 1
- while (dx < dy):
- xcoordinates.append(-x)
- ycoordinates.append(-y)
- # Checking and updating value of
- # decision parameter based on algorithm
- if (d1 < 0): # if E is selected
- x += 1;
- dx = dx + (2 * ry * ry);
- d1 = d1 + dx + (ry * ry);
- xcoordinates.append(-x)
- ycoordinates.append(-y)
- else: # if SE is selected
- x += 1;
- y -= 1;
- dx = dx + (2 * ry * ry);
- dy = dy - (2 * rx * rx);
- d1 = d1 + dx - dy + (ry * ry);
- xcoordinates.append(-x)
- ycoordinates.append(-y)
- # Decision parameter of region 2
- d2 = (((ry * ry) * ((x + 0.5) * (x + 0.5))) +
- ((rx * rx) * ((y - 1) * (y - 1))) -
- (rx * rx * ry * ry));
- # Plotting points of region 2
- while (y >= 0):
- xcoordinates.append(-x)
- ycoordinates.append(-y)
- # Checking and updating parameter
- # value based on algorithm
- if (d2 > 0):
- y -= 1;
- dy = dy - (2 * rx * rx);
- d2 = d2 + (rx * rx) - dy;
- xcoordinates.append(-x)
- ycoordinates.append(-y)
- else:
- y -= 1;
- x += 1;
- dx = dx + (2 * ry * ry);
- dy = dy - (2 * rx * rx);
- d2 = d2 + dx - dy + (rx * rx);
- xcoordinates.append(-x)
- ycoordinates.append(-y)
- plt.plot(xcoordinates, ycoordinates, marker='o', markersize=3,
- markerfacecolor="red")
- plt.show()
- # draw an ellipse of major and minor radius and centered at (0, 0)
- midptellipse(1000, 950, 0, 0);
- # Mid-Point Ellipse Drawing Algorithm
- from matplotlib import pyplot as plt
- def midptellipse(rx, ry, xc, yc):
- xcoordinates = []
- ycoordinates = []
- x = 0;
- y = ry; # it represent minor axis b
- xcoordinates.append(x)
- ycoordinates.append(-y)
- # Here, ry = b and rx = a
- # Initial decision parameter of region 1
- d1 = ((ry * ry) - (rx * rx * ry) +
- (0.25 * rx * rx));
- # dstart1= b*b - (a*a)b + (a*a)/4
- dx = 2 * ry * ry * x; # dx = 2 *(b*b)x OR i component
- dy = 2 * rx * rx * y; # dy = 2 *(a*a)y OR j component
- # First Quddrant
- # For region 1
- while (dx < dy):
- xcoordinates.append(x)
- ycoordinates.append(-y)
- # Checking and updating value of
- # decision parameter based on algorithm
- if (d1 < 0): # if E is selected
- x += 1;
- dx = dx + (2 * ry * ry);
- d1 = d1 + dx + (ry * ry);
- xcoordinates.append(x)
- ycoordinates.append(-y)
- else: # if SE is selected
- x += 1;
- y -= 1;
- dx = dx + (2 * ry * ry);
- dy = dy - (2 * rx * rx);
- d1 = d1 + dx - dy + (ry * ry);
- xcoordinates.append(-x)
- ycoordinates.append(-y)
- # Decision parameter of region 2
- d2 = (((ry * ry) * ((x + 0.5) * (x + 0.5))) +
- ((rx * rx) * ((y - 1) * (y - 1))) -
- (rx * rx * ry * ry));
- # Plotting points of region 2
- while (y >= 0):
- xcoordinates.append(x)
- ycoordinates.append(-y)
- # Checking and updating parameter
- # value based on algorithm
- if (d2 > 0):
- y -= 1;
- dy = dy - (2 * rx * rx);
- d2 = d2 + (rx * rx) - dy;
- xcoordinates.append(x)
- ycoordinates.append(-y)
- else:
- y -= 1;
- x += 1;
- dx = dx + (2 * ry * ry);
- dy = dy - (2 * rx * rx);
- d2 = d2 + dx - dy + (rx * rx);
- xcoordinates.append(x)
- ycoordinates.append(-y)
- plt.plot(xcoordinates, ycoordinates, marker='o', markersize=3,
- markerfacecolor="red")
- plt.show()
- # draw an ellipse of major and minor radius and centered at (0, 0)
- midptellipse(1000, 950, 0, 0);
- midptellipse(1000, 950, 0, 0);
[text] erre
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: