コード例 #1
0
 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
コード例 #2
0
    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)
コード例 #3
0
def vector(request):
    return Vector3d(request.param)
コード例 #4
0
]

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)
コード例 #5
0
 def axis(self):
     """Vector3d : the axis of rotation."""
     return Vector3d(self.unit)
コード例 #6
0
 def axis(self):
     return Vector3d(self.unit)
コード例 #7
0
ファイル: test_vector3d.py プロジェクト: clark-tan1/texpy
def something(request):
    return Vector3d(request.param)
コード例 #8
0
ファイル: test_vector3d.py プロジェクト: clark-tan1/texpy
def test_rotate(vector, rotation, expected):
    r = Vector3d(vector).rotate(Vector3d.zvector(), rotation)
    assert isinstance(r, Vector3d)
    assert np.allclose(r.data, expected)
コード例 #9
0
ファイル: test_vector3d.py プロジェクト: clark-tan1/texpy
@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]]),
コード例 #10
0
def test_multiply_vector(quaternion, vector, expected):
    q = Quaternion(quaternion)
    v = Vector3d(vector)
    v_new = q * v
    assert np.allclose(v_new.data, expected)