def test_st_transform(): # Check that STTransform maps exactly like AffineTransform pts = np.random.normal(size=(10, 4)) scale = (1, 7.5, -4e-8) translate = (1e6, 0.2, 0) st = tr.STTransform(scale=scale, translate=translate) at = tr.AffineTransform() at.scale(scale) at.translate(translate) assert np.allclose(st.map(pts), at.map(pts)) assert np.allclose(st.inverse.map(pts), at.inverse.map(pts))
def __init__(self): app.Canvas.__init__(self, 'Cube', keys='interactive', size=(400, 400)) self.cube = CubeVisual((1.0, 0.5, 0.25), color='red', edge_color='black') self.quaternion = Quaternion() # Create a TransformSystem that will tell the visual how to draw self.cube_transform = transforms.AffineTransform() self.cube_transform.scale((100, 100, 0.001)) self.cube_transform.translate((200, 200)) self.tr_sys = transforms.TransformSystem(self) self.tr_sys.visual_to_document = self.cube_transform self.show()
def __init__(self): app.Canvas.__init__(self, 'Cube', keys='interactive', size=(400, 400)) self.cube = CubeVisual((1.0, 0.5, 0.25), color='red', edge_color='black') self.theta = 0 self.phi = 0 # Create a TransformSystem that will tell the visual how to draw self.cube_transform = transforms.AffineTransform() self.tr_sys = transforms.TransformSystem(self) self.tr_sys.visual_to_document = self.cube_transform self._timer = app.Timer('auto', connect=self.on_timer, start=True) self.show()
def test_affine_mapping(): t = tr.AffineTransform() p1 = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]]) # test pure translation p2 = p1 + 5.5 t.set_mapping(p1, p2) assert np.allclose(t.map(p1)[:, :p2.shape[1]], p2) # test pure scaling p2 = p1 * 5.5 t.set_mapping(p1, p2) assert np.allclose(t.map(p1)[:, :p2.shape[1]], p2) # test scale + translate p2 = (p1 * 5.5) + 3.5 t.set_mapping(p1, p2) assert np.allclose(t.map(p1)[:, :p2.shape[1]], p2) # test SRT p2 = np.array([[10, 5, 3], [10, 15, 3], [30, 5, 3], [10, 5, 3.5]]) t.set_mapping(p1, p2) assert np.allclose(t.map(p1)[:, :p2.shape[1]], p2)