我正在寻找一种合适的方法来计算三角形的矩形边界框,该三角形具有三个角作为点 - (x1,y1)、(x2,y2)、(x3,y3)。
这是我正在使用的数据类型(按照建议,我添加了更多构造函数):
data Shape =
Circle Point Double |
Rectangle Point Point |
Triangle Point Point Point
边界框函数的形式应该是“bounding :: Shape -> Shape”。我还尝试了矩形和圆形的边界框:
bounding :: Shape -> Shape
bounding (Rectangle (Point x y) (Point z z1)) = (Rectangle (Point x y) (Point z z1))
bounding (Circle (Point p w) r) = (Rectangle (Point (p-r) (w-r)) (Point (p+r) (w+r)))
如果应该使用图形坐标系(其中(x,y)坐标应该被视为(x,-y)),这些是否正确?
有人可以帮帮我吗?PS 不需要图形库。