[Tutor] Using trigonometry to draw a circle
David
bouncingcats at gmail.com
Tue May 18 06:06:39 EDT 2021
On Tue, 18 May 2021 at 19:35, Phil <phillor9 at gmail.com> wrote:
> On 18/5/21 6:40 pm, Alan Gauld via Tutor wrote:
> > Also some math plotting libraries will plot a function so you
> > don't have to. But that only helps if you are restricted to drawing
> > graphs, you still need to use the math functions when manipulating data.
> wxPython's addArc function, for example, works well but I cannot see how
> I can set points along the arc. If I plot individual points to generate
> an arc then setting points along the arc is easy.
Depending on why you are doing this, there are different approaches
that might or might not be a good idea. So you will get better advice
if you describe the bigger picture of what you are doing, not the details.
If you are just playing around, the below code might give you some
useful hints. If you are trying to do sophisticated drawing, this code
is probably not a good way to do it.
#!/usr/bin/python3
import matplotlib.pyplot as plt
import math
radius = 60
x_centre = 100
y_centre = 100
degs = list(range(0, 270, 10))
rads = [math.radians(d) for d in degs]
x = [math.cos(a) * radius + x_centre for a in rads]
y = [math.sin(a) * radius + y_centre for a in rads]
plt.plot(x, y, 'ro', x, y)
plt.gca().axis('scaled')
plt.show()
More information about the Tutor
mailing list