直角坐标的三角形

问题描述 投票:0回答:2

我是新手。谁能帮我。

class Triangle():
    def __init__(self, a, b, c):
        """
        Constructor for Vec4
        Expects points as arrays in the form of [x, y].
        All coordinates are given as cartesian coordinates.
        """
        self.a = a
        self.b = b
        self.c = c


    def __str__(self):
        """
        Returns a string representation of the triangle. The string is formatted as follows:

        Point A: 0.00 0.00
        Point B: 0.00 0.00
        Point C: 0.00 0.00

        """
        return ""
python coordinates point cartesian
2个回答
0
投票
您需要提出一个具体问题。查看这些guidelines

0
投票
这是我的实现以及如何实现。您可以返回字符串,并记住将整数转换为字符串。

class Triangle(): def __init__(self, a, b, c): """ Constructor for Vec4 Expects points as arrays in the form of [x, y]. All coordinates are given as cartesian coordinates. """ self.a = a self.b = b self.c = c def __str__(self): """ Returns a string representation of the triangle. The string is formatted as follows: Point A: 0.00 0.00 Point B: 0.00 0.00 Point C: 0.00 0.00 """ return "Point A: " + str(self.a[0]) + " " + str(self.a[1]) + "\nPoint B: " + str(self.b[0]) + " " + str(self.b[1]) + "\nPoint C: " + str(self.c[0]) + " " + str(self.c[1]) t = Triangle([5,4], [1,2], [7,9]) print(t)

输出:

Point A: 5 4 Point B: 1 2 Point C: 7 9


0
投票
假设点是一个类似(1.5,6.7)的元组

这里是代码:

class Triangle(): def __init__(self, a, b, c): """ Constructor for Vec4 Expects points as arrays in the form of [x, y]. All coordinates are given as cartesian coordinates. """ self.a = a self.b = b self.c = c def __str__(self): """ Returns a string representation of the triangle. The string is formatted as follows: Point A: 0.00 0.00 Point B: 0.00 0.00 Point C: 0.00 0.00 """ return f"Point A: {self.a[0]} {self.a[1]}\nPoint B: {self.b[0]} {self.b[1]}\nPoint C: {self.c[0]} {self.c[1]}"

您可以使用以下方法来检查:

t = Triangle((2.34,4.62), (6.7,8.52), (9.34,3.32)) print(t)

© www.soinside.com 2019 - 2024. All rights reserved.