本文整理汇总了Python中karta.vector.geometry.Polygon.apply_affine_transform方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.apply_affine_transform方法的具体用法?Python Polygon.apply_affine_transform怎么用?Python Polygon.apply_affine_transform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类karta.vector.geometry.Polygon
的用法示例。
在下文中一共展示了Polygon.apply_affine_transform方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestAffineTransforms
# 需要导入模块: from karta.vector.geometry import Polygon [as 别名]
# 或者: from karta.vector.geometry.Polygon import apply_affine_transform [as 别名]
class TestAffineTransforms(unittest.TestCase):
def setUp(self):
self.square = Polygon([(0, 0), (0, 1), (1, 1), (1, 0)])
return
def test_translate(self):
M = affine_matrix(Multipoint([(0,0), (1,0), (0,1)]),
Multipoint([(1,0), (2,0), (1,1)]))
Mans = np.array([[1, 0, 1], [0, 1, 0], [0, 0, 1]])
self.assertTrue(np.allclose(M, Mans))
translated_square = self.square.apply_affine_transform(M)
ans = np.array([[1, 0], [1, 1], [2, 1], [2, 0]])
self.assertTrue(np.allclose(translated_square.get_vertices(), ans))
return
def test_rotate(self):
s2 = math.sqrt(0.5)
M = affine_matrix(Multipoint([(0,0), (1,0), (0,1)]),
Multipoint([(0,0), (s2,s2), (-s2,s2)]))
Mans = np.array([[s2, -s2, 0], [s2, s2, 0], [0, 0, 1]])
self.assertTrue(np.allclose(M, Mans))
translated_square = self.square.apply_affine_transform(M)
ans = np.array([[0, 0], [-s2, s2], [0, 2*s2], [s2, s2]])
self.assertTrue(np.allclose(translated_square.get_vertices(), ans))
return
def test_stretch(self):
M = affine_matrix(Multipoint([(0,0), (1,0), (0,1)]),
Multipoint([(0,0), (2,0), (0,2)]))
Mans = np.array([[2, 0, 0], [0, 2, 0], [0, 0, 1]])
self.assertTrue(np.allclose(M, Mans))
translated_square = self.square.apply_affine_transform(M)
ans = np.array([[0, 0], [0, 2], [2, 2], [2, 0]])
self.assertTrue(np.allclose(translated_square.get_vertices(), ans))
return