def axis(self): """Vector3d : the axis of rotation.""" axis = Vector3d( np.stack((self.b.data, self.c.data, self.d.data), axis=-1)) axis[self.a.data < -1e-6] = -axis[self.a.data < -1e-6] axis[axis.norm.data == 0] = Vector3d.zvector() * np.sign( self.a[axis.norm.data == 0].data) axis.data = axis.data / axis.norm.data[..., np.newaxis] return axis
def __init__(self, theta_grid: S1Grid, rho_grid: S1Grid): self.theta_grid = theta_grid self.rho_grid = rho_grid theta = np.tile(theta_grid.points, rho_grid.points.shape) rho = rho_grid.points v = Vector3d.from_polar(theta, rho) self.points = v
def get_plot_data(self): from texpy.vector import Vector3d theta = np.linspace(0, 2 * np.pi + 1e-9, 361) rho = np.linspace(0, np.pi, 181) theta, rho = np.meshgrid(theta, rho) g = Vector3d.from_polar(rho, theta) n = Rodrigues.from_rotation(self).norm.data[:, np.newaxis, np.newaxis] if n.size == 0: return Rotation.from_neo_euler(AxAngle.from_axes_angles(g, np.pi)) d = (-self.axis).dot_outer(g.unit).data x = n * d x = 2 * np.arctan(x**-1) x[x < 0] = np.pi x = np.min(x, axis=0) r = Rotation.from_neo_euler(AxAngle.from_axes_angles(g.unit, x)) return r
def from_axes_angles(cls, axes, angles): """Create new AxAngle object explicitly from the given axes and angles. Parameters ---------- axes : Vector3d or array_like The axis of rotation. angles : array_like The angle of rotation, in radians. Returns ------- AxAngle """ axes = Vector3d(axes).unit angles = np.array(angles) axangle_data = angles[..., np.newaxis] * axes.data return cls(axangle_data)
def vector(request): return Vector3d(request.param)
] angles = [ -2 * np.pi, -5 * np.pi / 6, -np.pi / 3, 0, np.pi / 12, np.pi / 3, 3 * np.pi / 4, 2 * np.pi, np.pi / 7, ] axangles = [ np.array(angle) * Vector3d(axis).unit for axis in axes for angle in angles ] axangles += [ np.array(angle) * Vector3d(axis).unit for axis in itertools.combinations_with_replacement(axes, 2) for angle in itertools.combinations_with_replacement(angles, 2) ] @pytest.fixture(params=axangles[:100]) def axangle(request): return AxAngle(request.param.data) def test_angle(axangle): assert np.allclose(axangle.angle.data, axangle.norm.data)
def axis(self): """Vector3d : the axis of rotation.""" return Vector3d(self.unit)
def axis(self): return Vector3d(self.unit)
def something(request): return Vector3d(request.param)
def test_perpendicular(vector: Vector3d): assert np.allclose(vector.dot(vector.perpendicular).data, 0)
def test_rotate(vector, rotation, expected): r = Vector3d(vector).rotate(Vector3d.zvector(), rotation) assert isinstance(r, Vector3d) assert np.allclose(r.data, expected)
def test_zero(shape): v = Vector3d.zero(shape) assert v.shape == shape assert v.data.shape[-1] == v.dim
def test_polar(theta, phi, r, expected): assert np.allclose(Vector3d.from_polar(theta, phi, r).data, expected.data, atol=1e-5)
@pytest.fixture(params=singles) def something(request): return Vector3d(request.param) @pytest.fixture(params=numbers) def number(request): return request.param def test_neg(vector): assert np.all((-vector).data == -(vector.data)) @pytest.mark.parametrize('vector, other, expected', [ ([1, 2, 3], Vector3d([[1, 2, 3], [-3, -2, -1]]), [[2, 4, 6], [-2, 0, 2]]), ([1, 2, 3], Scalar([4]), [5, 6, 7]), ([1, 2, 3], 0.5, [1.5, 2.5, 3.5]), ([1, 2, 3], [-1, 2], [[0, 1, 2], [3, 4, 5]]), ([1, 2, 3], np.array([-1, 1]), [[0, 1, 2], [2, 3, 4]]), pytest.param([1, 2, 3], 'dracula', None, marks=pytest.mark.xfail), ], indirect=['vector']) def test_add(vector, other, expected): s1 = vector + other s2 = other + vector assert np.allclose(s1.data, expected) assert np.allclose(s1.data, s2.data) @pytest.mark.parametrize('vector, other, expected', [ ([1, 2, 3], Vector3d([[1, 2, 3], [-3, -2, -1]]), [[0, 0, 0], [4, 4, 4]]),
def test_multiply_vector(quaternion, vector, expected): q = Quaternion(quaternion) v = Vector3d(vector) v_new = q * v assert np.allclose(v_new.data, expected)