[text] erre

Viewer

  1. # Mid-Point Ellipse Drawing Algorithm
  2. from matplotlib import pyplot as plt
  3.  
  4. def midptellipse(rx, ry, xc, yc):
  5.  
  6.   xcoordinates = []
  7.   ycoordinates = []
  8.   x = 0;
  9.   y = ry; # it represent minor axis b
  10.  
  11.  
  12.   xcoordinates.append(x)
  13.   ycoordinates.append(y)
  14.  
  15.   # Here, ry = b and rx = a
  16.         # Initial decision parameter of region 1
  17.   d1 = ((ry * ry) - (rx * rx * ry) +
  18.                                         (0.25 * rx * rx));
  19.   # dstart1= b*b - (a*a)b + (a*a)/4
  20.   dx = 2 * ry * ry * x; # dx = 2 *(b*b)x OR i component
  21.   dy = 2 * rx * rx * y; # dy = 2 *(a*a)y OR j component
  22.  
  23.   # First Quddrant
  24.         # For region 1
  25.   while (dx < dy):
  26.  
  27.  
  28.  
  29.     xcoordinates.append(x)
  30.     ycoordinates.append(y)
  31.  
  32.                 # Checking and updating value of
  33.                 # decision parameter based on algorithm
  34.     if (d1 < 0):  # if E is selected
  35.       x += 1;
  36.       dx = dx + (2 * ry * ry);
  37.       d1 = d1 + dx + (ry * ry);
  38.       xcoordinates.append(x)
  39.       ycoordinates.append(y)
  40.     else:  # if SE is selected
  41.       x += 1;
  42.       y -= 1;
  43.       dx = dx + (2 * ry * ry);
  44.       dy = dy - (2 * rx * rx);
  45.       d1 = d1 + dx - dy + (ry * ry);
  46.       xcoordinates.append(x)
  47.       ycoordinates.append(y)
  48.  
  49.         # Decision parameter of region 2
  50.   d2 = (((ry * ry) * ((x + 0.5) * (x + 0.5))) +
  51.                 ((rx * rx) * ((y - 1) * (y - 1))) -
  52.                 (rx * rx * ry * ry));
  53.  
  54.         # Plotting points of region 2
  55.   while (y >= 0):
  56.  
  57.  
  58.  
  59.     xcoordinates.append(x)
  60.     ycoordinates.append(y)
  61.  
  62.                 # Checking and updating parameter
  63.                 # value based on algorithm
  64.     if (d2 > 0):
  65.       y -= 1;
  66.       dy = dy - (2 * rx * rx);
  67.       d2 = d2 + (rx * rx) - dy;
  68.       xcoordinates.append(x)
  69.       ycoordinates.append(y)
  70.     else:
  71.       y -= 1;
  72.       x += 1;
  73.       dx = dx + (2 * ry * ry);
  74.       dy = dy - (2 * rx * rx);
  75.       d2 = d2 + dx - dy + (rx * rx);
  76.       xcoordinates.append(x)
  77.  
  78.       ycoordinates.append(y)
  79.   plt.plot(xcoordinates, ycoordinates, marker='o', markersize=3,
  80.            markerfacecolor="red")
  81.  
  82.  
  83.  
  84.  
  85.   plt.show()
  86.  
  87.  
  88.  
  89. # draw an ellipse of major and minor radius and centered at (0, 0)
  90. midptellipse(1000, 950, 0, 0);
  91.  
  92.  
  93.  
  94.  
  95. # Mid-Point Ellipse Drawing Algorithm
  96. from matplotlib import pyplot as plt
  97.  
  98. def midptellipse(rx, ry, xc, yc):
  99.  
  100.   xcoordinates = []
  101.   ycoordinates = []
  102.   x = 0;
  103.   y = ry; # it represent minor axis b
  104.  
  105.  
  106.   xcoordinates.append(-x)
  107.   ycoordinates.append(y)
  108.  
  109.   # Here, ry = b and rx = a
  110.         # Initial decision parameter of region 1
  111.   d1 = ((ry * ry) - (rx * rx * ry) +
  112.                                         (0.25 * rx * rx));
  113.   # dstart1= b*b - (a*a)b + (a*a)/4
  114.   dx = 2 * ry * ry * x; # dx = 2 *(b*b)x OR i component
  115.   dy = 2 * rx * rx * y; # dy = 2 *(a*a)y OR j component
  116.  
  117.   # First Quddrant
  118.         # For region 1
  119.   while (dx < dy):
  120.  
  121.  
  122.  
  123.     xcoordinates.append(-x)
  124.     ycoordinates.append(y)
  125.  
  126.                 # Checking and updating value of
  127.                 # decision parameter based on algorithm
  128.     if (d1 < 0):  # if E is selected
  129.       x += 1;
  130.       dx = dx + (2 * ry * ry);
  131.       d1 = d1 + dx + (ry * ry);
  132.       xcoordinates.append(-x)
  133.       ycoordinates.append(y)
  134.     else:  # if SE is selected
  135.       x += 1;
  136.       y -= 1;
  137.       dx = dx + (2 * ry * ry);
  138.       dy = dy - (2 * rx * rx);
  139.       d1 = d1 + dx - dy + (ry * ry);
  140.       xcoordinates.append(-x)
  141.       ycoordinates.append(y)
  142.  
  143.         # Decision parameter of region 2
  144.   d2 = (((ry * ry) * ((x + 0.5) * (x + 0.5))) +
  145.                 ((rx * rx) * ((y - 1) * (y - 1))) -
  146.                 (rx * rx * ry * ry));
  147.  
  148.         # Plotting points of region 2
  149.   while (y >= 0):
  150.  
  151.  
  152.  
  153.     xcoordinates.append(-x)
  154.     ycoordinates.append(y)
  155.  
  156.                 # Checking and updating parameter
  157.                 # value based on algorithm
  158.     if (d2 > 0):
  159.       y -= 1;
  160.       dy = dy - (2 * rx * rx);
  161.       d2 = d2 + (rx * rx) - dy;
  162.       xcoordinates.append(-x)
  163.       ycoordinates.append(y)
  164.     else:
  165.       y -= 1;
  166.       x += 1;
  167.       dx = dx + (2 * ry * ry);
  168.       dy = dy - (2 * rx * rx);
  169.       d2 = d2 + dx - dy + (rx * rx);
  170.       xcoordinates.append(-x)
  171.  
  172.       ycoordinates.append(y)
  173.   plt.plot(xcoordinates, ycoordinates, marker='o', markersize=3,
  174.            markerfacecolor="red")
  175.  
  176.  
  177.  
  178.  
  179.   plt.show()
  180.  
  181.  
  182.  
  183. # draw an ellipse of major and minor radius and centered at (0, 0)
  184.  
  185.  
  186.  
  187.  
  188. # Mid-Point Ellipse Drawing Algorithm
  189. from matplotlib import pyplot as plt
  190.  
  191. def midptellipse(rx, ry, xc, yc):
  192.  
  193.   xcoordinates = []
  194.   ycoordinates = []
  195.   x = 0;
  196.   y = ry; # it represent minor axis b
  197.  
  198.  
  199.   xcoordinates.append(-x)
  200.   ycoordinates.append(-y)
  201.  
  202.   # Here, ry = b and rx = a
  203.         # Initial decision parameter of region 1
  204.   d1 = ((ry * ry) - (rx * rx * ry) +
  205.                                         (0.25 * rx * rx));
  206.   # dstart1= b*b - (a*a)b + (a*a)/4
  207.   dx = 2 * ry * ry * x; # dx = 2 *(b*b)x OR i component
  208.   dy = 2 * rx * rx * y; # dy = 2 *(a*a)y OR j component
  209.  
  210.   # First Quddrant
  211.         # For region 1
  212.   while (dx < dy):
  213.  
  214.  
  215.  
  216.     xcoordinates.append(-x)
  217.     ycoordinates.append(-y)
  218.  
  219.                 # Checking and updating value of
  220.                 # decision parameter based on algorithm
  221.     if (d1 < 0):  # if E is selected
  222.       x += 1;
  223.       dx = dx + (2 * ry * ry);
  224.       d1 = d1 + dx + (ry * ry);
  225.       xcoordinates.append(-x)
  226.       ycoordinates.append(-y)
  227.     else:  # if SE is selected
  228.       x += 1;
  229.       y -= 1;
  230.       dx = dx + (2 * ry * ry);
  231.       dy = dy - (2 * rx * rx);
  232.       d1 = d1 + dx - dy + (ry * ry);
  233.       xcoordinates.append(-x)
  234.       ycoordinates.append(-y)
  235.  
  236.         # Decision parameter of region 2
  237.   d2 = (((ry * ry) * ((x + 0.5) * (x + 0.5))) +
  238.                 ((rx * rx) * ((y - 1) * (y - 1))) -
  239.                 (rx * rx * ry * ry));
  240.  
  241.         # Plotting points of region 2
  242.   while (y >= 0):
  243.  
  244.  
  245.  
  246.     xcoordinates.append(-x)
  247.     ycoordinates.append(-y)
  248.  
  249.                 # Checking and updating parameter
  250.                 # value based on algorithm
  251.     if (d2 > 0):
  252.       y -= 1;
  253.       dy = dy - (2 * rx * rx);
  254.       d2 = d2 + (rx * rx) - dy;
  255.       xcoordinates.append(-x)
  256.       ycoordinates.append(-y)
  257.     else:
  258.       y -= 1;
  259.       x += 1;
  260.       dx = dx + (2 * ry * ry);
  261.       dy = dy - (2 * rx * rx);
  262.       d2 = d2 + dx - dy + (rx * rx);
  263.       xcoordinates.append(-x)
  264.  
  265.       ycoordinates.append(-y)
  266.   plt.plot(xcoordinates, ycoordinates, marker='o', markersize=3,
  267.            markerfacecolor="red")
  268.  
  269.  
  270.  
  271.  
  272.   plt.show()
  273.  
  274.  
  275.  
  276. # draw an ellipse of major and minor radius and centered at (0, 0)
  277. midptellipse(1000, 950, 0, 0);
  278.  
  279.  
  280. # Mid-Point Ellipse Drawing Algorithm
  281. from matplotlib import pyplot as plt
  282.  
  283. def midptellipse(rx, ry, xc, yc):
  284.  
  285.   xcoordinates = []
  286.   ycoordinates = []
  287.   x = 0;
  288.   y = ry; # it represent minor axis b
  289.  
  290.  
  291.   xcoordinates.append(x)
  292.   ycoordinates.append(-y)
  293.  
  294.   # Here, ry = b and rx = a
  295.         # Initial decision parameter of region 1
  296.   d1 = ((ry * ry) - (rx * rx * ry) +
  297.                                         (0.25 * rx * rx));
  298.   # dstart1= b*b - (a*a)b + (a*a)/4
  299.   dx = 2 * ry * ry * x; # dx = 2 *(b*b)x OR i component
  300.   dy = 2 * rx * rx * y; # dy = 2 *(a*a)y OR j component
  301.  
  302.   # First Quddrant
  303.         # For region 1
  304.   while (dx < dy):
  305.  
  306.  
  307.  
  308.     xcoordinates.append(x)
  309.     ycoordinates.append(-y)
  310.  
  311.                 # Checking and updating value of
  312.                 # decision parameter based on algorithm
  313.     if (d1 < 0):  # if E is selected
  314.       x += 1;
  315.       dx = dx + (2 * ry * ry);
  316.       d1 = d1 + dx + (ry * ry);
  317.       xcoordinates.append(x)
  318.       ycoordinates.append(-y)
  319.     else:  # if SE is selected
  320.       x += 1;
  321.       y -= 1;
  322.       dx = dx + (2 * ry * ry);
  323.       dy = dy - (2 * rx * rx);
  324.       d1 = d1 + dx - dy + (ry * ry);
  325.       xcoordinates.append(-x)
  326.       ycoordinates.append(-y)
  327.  
  328.         # Decision parameter of region 2
  329.   d2 = (((ry * ry) * ((x + 0.5) * (x + 0.5))) +
  330.                 ((rx * rx) * ((y - 1) * (y - 1))) -
  331.                 (rx * rx * ry * ry));
  332.  
  333.         # Plotting points of region 2
  334.   while (y >= 0):
  335.  
  336.  
  337.  
  338.     xcoordinates.append(x)
  339.     ycoordinates.append(-y)
  340.  
  341.                 # Checking and updating parameter
  342.                 # value based on algorithm
  343.     if (d2 > 0):
  344.       y -= 1;
  345.       dy = dy - (2 * rx * rx);
  346.       d2 = d2 + (rx * rx) - dy;
  347.       xcoordinates.append(x)
  348.       ycoordinates.append(-y)
  349.     else:
  350.       y -= 1;
  351.       x += 1;
  352.       dx = dx + (2 * ry * ry);
  353.       dy = dy - (2 * rx * rx);
  354.       d2 = d2 + dx - dy + (rx * rx);
  355.       xcoordinates.append(x)
  356.  
  357.       ycoordinates.append(-y)
  358.   plt.plot(xcoordinates, ycoordinates, marker='o', markersize=3,
  359.            markerfacecolor="red")
  360.  
  361.  
  362.  
  363.  
  364.   plt.show()
  365.  
  366.  
  367.  
  368. # draw an ellipse of major and minor radius and centered at (0, 0)
  369. midptellipse(1000, 950, 0, 0);
  370. midptellipse(1000, 950, 0, 0);

Editor

You can edit this paste and save as new:


File Description
  • erre
  • Paste Code
  • 28 Mar-2024
  • 8.17 Kb
You can Share it: