Python language-center of a circle using OOP

前端 未结 3 1659
悲哀的现实
悲哀的现实 2021-01-28 07:33
class Point:

    def __init__(self, initX, initY):
        \"\"\" Create a new point at the given coordinates. \"\"\"
        self.x = initX
        self.y = initY

            


        
3条回答
  •  情话喂你
    2021-01-28 08:03

    You don't need getters or setters in python nor is it pythonic to use them, you should access the attributes directly:

    def cencd(p1, p2, p3):
        """calculating the center of a circle"""
        ma = (p2.y - p1.y) / (p2.x - p1.x)
        mb = (p3.y - p2.y) / (p3.x - p2.x)
        hw = p1.halfway(p2)
        x = (ma * mb * (p1.y - p3.y) + mb * (p1.x + p2.x) - ma * (p2.x + p3.x)) / 2 * (mb - ma)
        ya = -(1 / ma) * ((x - hw.x) + hw.y)
        return x, ya
    

提交回复
热议问题