Click here to Skip to main content
15,123,619 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I want to plot slice of pie shape with the help of coordinates but i have only one center point coordinate and radius and angle of pie slice. Is there any equation to calculate pie shape coordinates or any method to plot pie piece with the help of given info.

As i have equation to find coordinates of another point to draw a line with the help of given coordinates and angle of line. Similarly i want to draw pie slice.

Please support

What I have tried:

Still searching
As i have equation to find coordinates of another point to draw a line with the help of given coordinates and angle of line. Similarly i want to draw pie slice.
Posted
Updated 20-Dec-20 11:46am
Comments
Richard MacCutchan 9-Nov-20 4:18am
   
This is simple mathematics rather than programming. You need to use the values to calculate the angle at the centre of the circle. From that you can draw the two radii and the arc that joins them.
sbarnes 20-Dec-20 16:53pm
   
This is really the best, most straight forward answer. A little trig does the rest.

This question was asked under 'Python3.6' and you didn't say you require matplotlib, so here is one way with tkinter:
try:
    from Tkinter import *
except:
    from tkinter import *

root = Tk()
canvas = Canvas(root, width=500, height=300)
canvas.pack()

#center pie chart by using (150,50) as top left corner, (350, 250) as lower right
# square aspect because 350 - 150 = 250 - 50 = 200
# center is at (250, 150), radius is (350 - 150) / 2 = 100

startAngle = 45 # degrees
extentAngle = 90

# draw the wedge using Tkinter instead of MatPlotLib.
canvas.create_arc(150, 50, 350, 250, start=startAngle, extent=extentAngle, style=PIESLICE)

mainloop()
   
Comments
Richard MacCutchan 21-Dec-20 4:06am
   
+5. Sixty years ago I could probably have done the maths, but it's all a vague memory these days. :(
You need 2 angles: the angle of the 2 sides (radii) of the triangle; and the rotation angle of the shape around the "origin" point. In effect, you create and rotate a "triangle" / arc segment (where 0 / 360 degrees would be a vertical pie shape).
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900