def test_cartesian_vector_normalize_sphere(): a = (180, 91) r = (0, 89) v = CartesianVector.from_spherical(r=1.0, alpha=d2r(a[0]), delta=d2r(a[1])) x = [r2d(i) for i in v.normalized_angles] assert (round(x[0], 12), round(x[1], 12)) == r a = (180, -91) r = (0, -89) v = CartesianVector.from_spherical(r=1.0, alpha=d2r(a[0]), delta=d2r(a[1])) x = [r2d(i) for i in v.normalized_angles] assert (round(x[0], 12), round(x[1], 12)) == r a = (0, 91) r = (180, 89) v = CartesianVector.from_spherical(r=1.0, alpha=d2r(a[0]), delta=d2r(a[1])) x = [r2d(i) for i in v.normalized_angles] assert (round(x[0], 12), round(x[1], 12)) == r a = (0, -91) r = (180, -89) v = CartesianVector.from_spherical(r=1.0, alpha=d2r(a[0]), delta=d2r(a[1])) x = [r2d(i) for i in v.normalized_angles] assert (round(x[0], 12), round(x[1], 12)) == r a = (120, 280) r = (120, -80) v = CartesianVector.from_spherical(r=1.0, alpha=d2r(a[0]), delta=d2r(a[1])) x = [r2d(i) for i in v.normalized_angles] assert (round(x[0], 12), round(x[1], 12)) == r a = (375, 45) # 25 hours, 45 degrees r = (15, 45) v = CartesianVector.from_spherical(r=1.0, alpha=d2r(a[0]), delta=d2r(a[1])) x = [r2d(i) for i in v.normalized_angles] assert (round(x[0], 12), round(x[1], 12)) == r a = (-375, -45) r = (345, -45) v = CartesianVector.from_spherical(r=1.0, alpha=d2r(a[0]), delta=d2r(a[1])) x = [r2d(i) for i in v.normalized_angles] assert (round(x[0], 12), round(x[1], 12)) == r a = (-375, -91) r = (165, -89) v = CartesianVector.from_spherical(r=1.0, alpha=d2r(a[0]), delta=d2r(a[1])) x = [r2d(i) for i in v.normalized_angles] assert (round(x[0], 12), round(x[1], 12)) == r
def test_cartesian_vector(): v = CartesianVector() assert v.x == 0.0 assert v.y == 0.0 assert v.z == 0.0 v = CartesianVector(x=10, y=10, z=10) assert v.mod == math.sqrt(3 * 10**2) assert v.spherical_coords == (v.mod, math.atan2(10, 10), math.asin(10/v.mod)) a = math.atan2(10, 10) d = math.asin(10/v.mod) v = CartesianVector.from_spherical(r=1.0, alpha=a, delta=d) assert v.mod == 1.0 assert round(v.x, 15) == round(math.cos(d)*math.sin(a), 15) assert round(v.y, 15) == round(math.cos(d)*math.cos(a), 15) assert round(v.z, 15) == round(math.sin(d), 15) r1, a1, d1 = v.spherical_coords assert r1 == 1.0 assert round(a1, 15) == round(a, 15) assert round(d1, 15) == round(d, 15)
def test_cartesian_vector(): v = CartesianVector() assert v.x == 0.0 assert v.y == 0.0 assert v.z == 0.0 v = CartesianVector(x=10, y=10, z=10) assert v.mod == math.sqrt(3 * 10**2) assert v.spherical_coords == (v.mod, math.atan2(10, 10), math.asin(10 / v.mod)) a = math.atan2(10, 10) d = math.asin(10 / v.mod) v = CartesianVector.from_spherical(r=1.0, alpha=a, delta=d) assert v.mod == 1.0 assert round(v.x, 15) == round(math.cos(d) * math.sin(a), 15) assert round(v.y, 15) == round(math.cos(d) * math.cos(a), 15) assert round(v.z, 15) == round(math.sin(d), 15) r1, a1, d1 = v.spherical_coords assert r1 == 1.0 assert round(a1, 15) == round(a, 15) assert round(d1, 15) == round(d, 15)