⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 circlem.py

📁 three Point to circle Python sample - "interactive"
💻 PY
字号:
#!/usr/bin/env python
from Tkinter import *
import math

class Appn(Frame):
    def calc_circlemiddle(self,coord):
        asq = ( coord[1][0] - coord[0][0] ) * ( coord[1][0] - coord[0][0] ) + ( coord[1][1] - coord[0][1] ) * ( coord[1][1] - coord[0][1] )
        csq = ( coord[2][0] - coord[0][0] ) * ( coord[2][0] - coord[0][0] ) + ( coord[2][1] - coord[0][1] ) * ( coord[2][1] - coord[0][1] )
        top1 =   ( coord[1][1] - coord[0][1] ) * csq - ( coord[2][1] - coord[0][1] ) * asq
        top2 = - ( coord[1][0] - coord[0][0] ) * csq + ( coord[2][0] - coord[0][0] ) * asq
        bot  =  ( coord[1][1] - coord[0][1] ) * ( coord[2][0] - coord[0][0] ) - ( coord[2][1] - coord[0][1] ) * ( coord[1][0] - coord[0][0] )
        xm = coord[0][0] + 0.5 * top1 / bot
        ym = coord[0][1] + 0.5 * top2 / bot
        return [xm,ym]
    
    def clear(self):
        u=self.b.find_all()  
        for u2 in u:
            self.b.delete(u2)
        self.n=0
        self.points=list()
            
    def drawtriangle(self,coord):
        print "HERE"
        print coord[0][0]
        self.b.create_line(coord[0][0],coord[0][1],coord[1][0],coord[1][1],width=2,fill="blue")
        self.b.create_line(coord[2][0],coord[2][1],coord[1][0],coord[1][1],width=2,fill="blue")
        self.b.create_line(coord[2][0],coord[2][1],coord[0][0],coord[0][1],width=2,fill="blue")
        m=self.calc_circlemiddle(coord)
        k=4
        self.b.create_oval(m[0]-k,m[1]-k,m[0]+k,m[1]+k,fill="red")
        r=math.sqrt((coord[0][0]-m[0])**2+(coord[0][1]-m[1])**2)
        self.b.create_oval(m[0]-r,m[1]-r,m[0]+r,m[1]+r,outline="green")
    
    def drawdot(self,event):
        k=4
        print "RISE drawgreen"
        self.b.create_oval(event.x-k,event.y-k,event.x+k,event.y+k,fill="orange")
        self.n+=1
        self.points.append([event.x,event.y])

        if self.n==3:
            self.drawtriangle(self.points)
            self.n=0
            self.points=list()
        
    def createwidget(self):
        self.b=Canvas(self,width=800,height=600,background="white")
        self.b.pack({"side":"top"})
        self.bu=Button(self,text="CLEAR",command=self.clear)
        self.bu.pack({"side":"bottom"})
        self.b.bind("<Button-1>",self.drawdot)
        self.points=list()
        self.n=0
        
    def __init__(self,master=None):
        Frame.__init__(self,master)
        self.pack()
        self.createwidget()

root=Tk()
root.attributes("-topmost",1)
app=Appn(master=root)
app.mainloop()



  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -