def test_VelocityPoint(): x = Variable("x") R0 = FrameReference() R1 = FrameReference(R0, translation=(x, 0, 0)) point = Object(R1) np.testing.assert_almost_equal(point.get(R1, "v"), (0, 0, 0)) np.testing.assert_array_equal(point.get(R0, "v"), (x.dt, 0, 0))
def test_BuildRotatedFrame_random(): R0 = FrameReference() Ntests = 100 for i in range(Ntests): angle = np.random.rand(1) direction = getRandomUnit3DVector() rotation = (angle, direction) Ri = FrameReference(R0, rotation=rotation)
def test_RotationedPosition(): R0 = FrameReference() R1 = FrameReference(R0, rotation=(np.pi / 2, (0, 0, 1))) R2 = FrameReference(R1, translation=(1, 0, 0)) point = Object(R2) np.testing.assert_almost_equal(point.get(R2, "p"), (0, 0, 0)) np.testing.assert_almost_equal(point.get(R1, "p"), (1, 0, 0)) np.testing.assert_almost_equal(point.get(R0, "p"), (0, 1, 0))
def test_CompositionTranslation(): R0 = FrameReference() R1 = FrameReference(R0, translation=(1, 0, 0)) R2 = FrameReference(R1, translation=(0, 1, 0)) R3 = FrameReference(R2, translation=(0, 0, 1)) point = Object(R3) np.testing.assert_almost_equal(point.get(R3, "p"), (0, 0, 0)) np.testing.assert_almost_equal(point.get(R2, "p"), (0, 0, 1)) np.testing.assert_almost_equal(point.get(R1, "p"), (0, 1, 1)) np.testing.assert_almost_equal(point.get(R0, "p"), (1, 1, 1))
def test_CompositionRotationsZ(): a, b, c = np.random.rand(3) R0 = FrameReference() R1 = FrameReference(R0, rotation=(np.pi / 2, "z")) R2 = FrameReference(R1, rotation=(np.pi / 2, "z")) R3 = FrameReference(R2, translation=(a, b, c)) point = Object(R3) np.testing.assert_almost_equal(point.get(R3, "p"), (0, 0, 0)) np.testing.assert_almost_equal(point.get(R2, "p"), (a, b, c)) np.testing.assert_almost_equal(point.get(R1, "p"), (-b, a, c)) np.testing.assert_almost_equal(point.get(R0, "p"), (-a, -b, c))
def test_TranslatedPosition(): R0 = FrameReference() R1 = FrameReference(R0, translation=(1, 0, 0)) R2 = FrameReference(R0, translation=(0, 1, 0)) R3 = FrameReference(R0, translation=(0, 0, 1)) point1 = Object(R1) point2 = Object(R2) point3 = Object(R3) np.testing.assert_almost_equal(point1.get(R1, "p"), (0, 0, 0)) np.testing.assert_almost_equal(point1.get(R0, "p"), (1, 0, 0)) np.testing.assert_almost_equal(point2.get(R2, "p"), (0, 0, 0)) np.testing.assert_almost_equal(point2.get(R0, "p"), (0, 1, 0)) np.testing.assert_almost_equal(point3.get(R3, "p"), (0, 0, 0)) np.testing.assert_almost_equal(point3.get(R0, "p"), (0, 0, 1))
def test_KineticEnergy(): m = 1 x = Variable("x") R0 = FrameReference() R1 = FrameReference(R0, translation=(x, 0, 0)) point = Object(R1) point.mass = m v = point.get(R1, "v") E = point.KineticEnergy(R1) assert E == m * np.dot(v, v) / 2 v = point.get(R0, "v") E = point.KineticEnergy(R0) assert E == m * np.dot(v, v) / 2
def test_BuildTranslatedFrame_standard(): R0 = FrameReference() R1 = FrameReference(R0, translation=(0, 0, 0)) R2 = FrameReference(R0, translation=(1, 0, 0)) R3 = FrameReference(R0, translation=(0, 1, 0)) R4 = FrameReference(R0, translation=(0, 0, 1)) R5 = FrameReference(R0, translation=(1, 0, 1)) R6 = FrameReference(R0, translation=(2, 1, 2)) R7 = FrameReference(R0, translation=(0, 1, 1))
def test_CompositionRotationsXYZ(): a, b, c = np.random.rand(3) d, e, f = np.random.rand(3) R0 = FrameReference() R1 = FrameReference(R0, translation=(a, b, c)) R2 = FrameReference(R1, rotation=(np.pi / 2, "x")) R3 = FrameReference(R2, rotation=(np.pi / 2, "y")) R4 = FrameReference(R3, rotation=(np.pi / 2, "z")) R5 = FrameReference(R4, translation=(d, e, f)) point = Object(R5) np.testing.assert_almost_equal(point.get(R5, "p"), (0, 0, 0)) np.testing.assert_almost_equal(point.get(R4, "p"), (d, e, f)) np.testing.assert_almost_equal(point.get(R3, "p"), (-e, d, f)) np.testing.assert_almost_equal(point.get(R2, "p"), (f, d, e)) np.testing.assert_almost_equal(point.get(R1, "p"), (f, -e, d)) np.testing.assert_almost_equal(point.get(R0, "p"), (a + f, b - e, c + d))
def test_BuildInertialFrame(): R0 = FrameReference() # Inertial Frame of Reference
def test_BuildTranslatedFrame_random(): R0 = FrameReference() Ntests = 100 for i in range(Ntests): translation = np.random.rand(3) Ri = FrameReference(R0, translation=translation)
def test_BuildRotatedFrame_standard(): R0 = FrameReference() R1 = FrameReference(R0, rotation=(0, "x")) R2 = FrameReference(R0, rotation=(0, "y")) R3 = FrameReference(R0, rotation=(0, "z")) R4 = FrameReference(R0, rotation=(np.pi / 2, "x")) R5 = FrameReference(R0, rotation=(np.pi / 2, "y")) R6 = FrameReference(R0, rotation=(np.pi / 2, "z")) R7 = FrameReference(R0, rotation=(2 * np.pi, "x")) R8 = FrameReference(R0, rotation=(2 * np.pi, "y")) R9 = FrameReference(R0, rotation=(2 * np.pi, "z")) R1 = FrameReference(R0, rotation=(0, (1, 0, 0))) R2 = FrameReference(R0, rotation=(0, (0, 1, 0))) R3 = FrameReference(R0, rotation=(0, (0, 0, 1))) R4 = FrameReference(R0, rotation=(np.pi / 2, (1, 0, 0))) R5 = FrameReference(R0, rotation=(np.pi / 2, (0, 1, 0))) R6 = FrameReference(R0, rotation=(np.pi / 2, (0, 0, 1))) R7 = FrameReference(R0, rotation=(2 * np.pi, (1, 0, 0))) R8 = FrameReference(R0, rotation=(2 * np.pi, (0, 1, 0))) R9 = FrameReference(R0, rotation=(2 * np.pi, (0, 0, 1)))
def test_SetInertia(): R0 = FrameReference() bar = Object(R0) bar.II = ((1, 0, 0), (0, 1, 0), (0, 0, 1))
def test_SetCenterMass(): R0 = FrameReference() bar = Object(R0) bar.CM = (1, 2, 3)
def test_SetMass(): R0 = FrameReference() bar = Object(R0) bar.mass = 3
def test_BuildWithName(): R0 = FrameReference() bar = Object(R0, "bar") plate = Object(R0, name="plate")
def test_BuildSecondFrame(): R0 = FrameReference() R1 = FrameReference(R0)
def test_Build(): R0 = FrameReference() bar = Object(R0)