Пример #1
0
def test_center():
    """Test getting and setting the center."""
    ellipse = Ellipse(1, 2)
    assert all(ellipse.center == (0, 0, 0))

    center = (1, 1, 1)
    ellipse.center = center
    assert all(ellipse.center == center)
Пример #2
0
def test_moment_inertia(a, b, center):
    ellipse = Ellipse(a, b)
    assert np.all(np.asarray(ellipse.planar_moments_inertia) >= 0)

    # We must set the center after construction so that the inertia tensor
    # calculation is not shifted away from the origin.
    ellipse.center = center
    area = ellipse.area
    expected = [np.pi / 4 * a * b**3, np.pi / 4 * a**3 * b, 0]
    expected[0] += area * center[0]**2
    expected[1] += area * center[1]**2
    expected[2] = area * center[0] * center[1]
    np.testing.assert_allclose(ellipse.planar_moments_inertia[:2],
                               expected[:2])
    np.testing.assert_allclose(ellipse.planar_moments_inertia[2], expected[2])
    assert ellipse.polar_moment_inertia == pytest.approx(sum(expected[:2]))
Пример #3
0
def test_inertia_tensor():
    """Test the inertia tensor calculation."""
    ellipse = Ellipse(1, 2)
    ellipse.center = (0, 0, 0)
    assert np.sum(ellipse.inertia_tensor > 1e-6) == 1
    assert ellipse.inertia_tensor[2, 2] == 5 * np.pi / 2