import random
import math
import matplotlib.pyplot as plt
def circle():
x = []
y = []
for i in range(0,1000):
angle = random.uniform(0,1)*(math.pi*2)
x.append(math.cos(angle));
y.append(math.sin(angle));
plt.scatter(x,y)
plt.show()
circle()
I've written the above code to draw 1000 points randomly on a unit circle. However, when I run this code, it draws an oval for some reason. Why is this?
Thus a circle which has radius r will have 2 * pi * r "points" on its circumference. The total number of points is pi * R^2. Thus you should give the circle r a probability equal to (2 * pi * r) / (pi * R^2) = 2 * r/R^2.
r = R*sqrt(rand(n,1)); x = x0 + r. *cos(t);
Distance Formula for a Point and the Center of a Circle: d=√(x−h)2+(y−k)2 d = ( x − h ) 2 + ( y − k ) 2 , where (x, y) is the point and (h,k) is the center of the circle. This formula is derived from the Pythagorean Theorem.
Three points uniquely define a circle. If you circumscribe a circle around a triangle, the circumcenter of that triangle will also be the center of that circle.
It is a circle -- The problem is that the aspect ratio of your axes is not 1 so it looks like an oval when you plot it. To get an aspect ratio of 1, you can use:
plt.axes().set_aspect('equal', 'datalim') # before `plt.show()`
This is highlighted in a demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With