[Model.py 03]Modification for creating terrain matrix3.

Other 2 function.

get_rectangle_coordinates函数

    def get_rectangle_coordinates(self, x1, y1, x2, y2):
        '''
        获得由(x1,y1)(x2,y2)所围成的矩阵边上的坐标列表
        '''
        # Ensure (x1, y1) is the bottom-left corner and (x2, y2) is the top-right corner
        x_min = min(x1, x2)
        x_max = max(x1, x2)
        y_min = min(y1, y2)
        y_max = max(y1, y2)

        # Calculate coordinates of the four corners
        bottom_left = (x_min, y_min)
        bottom_right = (x_max, y_min)
        top_left = (x_min, y_max)
        top_right = (x_max, y_max)

        # Generate points along each edge
        left_edge = [(x_min, y) for y in range(y_min, y_max + 1)]
        right_edge = [(x_max, y) for y in range(y_min, y_max + 1)]
        bottom_edge = [(x, y_min) for x in range(x_min, x_max + 1)]
        top_edge = [(x, y_max) for x in range(x_min, x_max + 1)]

        # Combine all the points
        all_points = [bottom_left, bottom_right, top_left, top_right]
        all_points.extend(left_edge)
        all_points.extend(right_edge)
        all_points.extend(bottom_edge)
        all_points.extend(top_edge)

        return list(set(all_points))

get_coordinates_in_range函数

def get_coordinates_in_range(self, bottom_left, top_right):
    '''
    获得沟渠内所有的坐标
    '''
    coordinates = []
    for x in range(bottom_left[0], top_right[0] + 1):
        for y in range(bottom_left[1], top_right[1] + 1):
            coordinates.append((x, y))
    return coordinates
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值