在我的程序中,用户可以在matplotlib图上绘制形状,并对这些形状执行各种操作。我目前正在尝试实现这些形状的缩放,以保持它们在主图中的位置,即使在放大时也是如此。
我的对象由一个顶点列表表示,
obj = [(1, 1), (2, 1), (1, 0), (2, 0)] # represents a 1 unit square
当然,这是多边形表示方式的简化分解,但在这种情况下,它们唯一有用的属性是顶点。
用户可以选择他想要放大的边界框,如下所示
一旦释放鼠标,应用程序将缩放到该位置,唯一的问题是我的多边形不能随之缩放。缩放画布时,多边形将保持在其确切位置,并且现在表示与以前完全不同的区域。这是因为缩放是由matplotlib处理的,matplotlib是实际应用程序的后端。如果用户放大上面选择的位置,我想要做的是沿着下面的图片所示的线:
所以我所知道的是
zoomboundedbox = [(162, 62), (937, 560)]
)的有界缩放框的位置
我相信我知道关于我的对象的所有必要数据,以正确缩放这些对象,但我不知道能让我实现这一点的算法……
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()
https://stackoverflow.com/questions/31125511
复制相似问题