微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何生成正方形、五边形等网格形状?

如何解决如何生成正方形、五边形等网格形状?

我发现这个生成六边形网格的代码,我想不通。如果有人可以提供帮助,我需要生成其他类型的网格(正方形、五边形......等)。我应该寻找或学习什么来理解这种代码

class Hexagon(Xshape):
    """A gridded hexagon."""
    @classmethod
    def _make_specification(cls):
        """Return a dict that describes this Xshape."""
        side = 1.0
        h = side * math.sin(math.pi / 3.0)
        # vertex calculations
        # shared horizontal and vertical rails
        top_rail = 0.0
        vmid_rail = h
        bottom_rail = 2.0 * h
        left_rail = -1.5 * side
        midleft_rail = -1.0 * side
        midright_rail = 0.0
        right_rail = 0.5 * side
        # point coordinates
        left_pt = (vmid_rail,left_rail)
        topleft_pt = (top_rail,midleft_rail)
        topright_pt = (top_rail,midright_rail)
        right_pt = (vmid_rail,right_rail)
        bottomright_pt = (bottom_rail,midright_rail)
        bottomleft_pt = (bottom_rail,midleft_rail)
        # build components separately to avoid long lines
        c = {(0,0): {'name': 'hexagon','clockwise_edge_names': ('top','top right','bottom right','bottom','bottom left','top left'),'edges': {(-1,0): {'name': 'top','counter_vertex': topleft_pt},(0,1): {'name': 'top right','counter_vertex': topright_pt},(1,1): {'name': 'bottom right','counter_vertex': right_pt},0): {'name': 'bottom','counter_vertex': bottomright_pt},-1): {'name': 'bottom left','counter_vertex': bottomleft_pt},(-1,-1): {'name': 'top left','counter_vertex': left_pt}}}}
        d = {'name': 'Hexagon','reference_length': side,'graph_offset_per_row': (2.0 * h,0.0),'graph_offset_per_col': (-1.0 * h,1.5 * side),'components': c}
        return d

    @classmethod
    def origin_index(cls,index):
        """Return the equivalent index when the supershape is at the origin."""
        origin_row,origin_col = 0,0  # there's only one shape so always origin
        return origin_row,origin_col

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。