0

I need to create moving point using matplotlib.animations library, also I need to show the center of the ellipse. Can someone edit my code and help me with this project? enter image description here

1 Answers1

0
 import math 
import numpy as np 
import matplotlib.pyplot as plt  #importing libraries 

img=np.ones((200,150,3)) 
rx=float(input ("radius of x axis : "))

ry=float(input ("radius of y-axis : "))

 def DrawEllipse(xc, yc, rx, ry):

xk=0
yk=ry

pk=ry**2-rx**2*ry+1/4*rx**2 

img[xc+xk, yc+yk]=0 
img[xc-xk, yc+yk]=0
img[xc+xk, yc-yk]=0
img[xc-xk, yc-yk]=0

while ry**2*xk<rx**2*yk:
    xk +=1 
    if pk>0:
        yk -=1 
        pk=pk+2*ry**2*xk+ry**2-2*rx**2*yk
    else: 
        pk=pk+2*ry**2*xk+ry**2
        
    img[xc+xk, yc+yk]=0 
    img[xc-xk, yc+yk]=0
    img[xc+xk, yc-yk]=0
    img[xc-xk, yc-yk]=0   


pk=ry**2*(xk+1/2)**2+rx**2*(yk-1)**2-(rx**2*ry**2) 

img[xc+xk, yc+yk]=0 
img[xc-xk, yc+yk]=0
img[xc+xk, yc-yk]=0
img[xc-xk, yc-yk]=0

while yk>0:
    yk -=1
    if pk>0:
        pk=pk-2*rx**2*yk+rx**2
    else:
        xk += 1
        pk=pk-2*rx**2*yk+rx**2+2*ry**2*xk
    img[xc+xk, yc+yk]=0 
    img[xc-xk, yc+yk]=0
    img[xc+xk, yc-yk]=0
    img[xc-xk, yc-yk]=0  


    
    
return
DrawEllipse(100, 70, 50, 25) # ellipse coordinates





plt.figure(figsize=(10,8), dpi=100, facecolor='w')
plt.imshow(img) # outputing result
plt.show()
  • Is this the code you want to change? If so, please post it in your question and delete this "answer". Also, describe what you want to change, how the actual behavior differs from the expected, and the full error message, if any. – Mr. T Jan 17 '21 at 12:56