首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >仅使用多边形的顶点列表按比率缩放面

仅使用多边形的顶点列表按比率缩放面
EN

Stack Overflow用户
提问于 2015-06-30 05:02:43
回答 1查看 4K关注 0票数 2

在我的程序中,用户可以在matplotlib图上绘制形状,并对这些形状执行各种操作。我目前正在尝试实现这些形状的缩放,以保持它们在主图中的位置,即使在放大时也是如此。

我的对象由一个顶点列表表示,

代码语言:javascript
复制
obj = [(1, 1), (2, 1), (1, 0), (2, 0)] # represents a 1 unit square

当然,这是多边形表示方式的简化分解,但在这种情况下,它们唯一有用的属性是顶点。

用户可以选择他想要放大的边界框,如下所示

一旦释放鼠标,应用程序将缩放到该位置,唯一的问题是我的多边形不能随之缩放。缩放画布时,多边形将保持在其确切位置,并且现在表示与以前完全不同的区域。这是因为缩放是由matplotlib处理的,matplotlib是实际应用程序的后端。如果用户放大上面选择的位置,我想要做的是沿着下面的图片所示的线:

所以我所知道的是

  • 对象的顶点列表包含在有界缩放中的所有对象的句柄列表,以及通过左上右下坐标(例如zoomboundedbox = [(162, 62), (937, 560)]

)的有界缩放框的位置

我相信我知道关于我的对象的所有必要数据,以正确缩放这些对象,但我不知道能让我实现这一点的算法……

代码语言:javascript
复制
def receive(self, lim):
'''
Calculate new coordinates of polygons visible to screen, this function
is called when the user releases the mouse button on the zoom function,
the parameters of the bounding box are internally stored as (x,y) tuples
in xyf (x,y first) and xyl (x,y last)
'''

    # Grab all item handles to polygons that intersect with the zoom
    # Stored in `targets`

    for shape in self.activePolygonList:         # loop through active polygons on screen
        if shape.handle() in targets:            # if the polygon is a target to be scaled
            print "scaling...."
            # ?                                   
            shape.redrawShape()
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31125511

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档