本文整理匯總了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