Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_general_logarithm_translation(self):
# Check we can reverse translation
for i in range(50):
t = random_euc_mv()
biv = ninf * t /2
R = general_exp(biv).normal()
biv_2 = general_logarithm(R)
np.testing.assert_almost_equal(biv.value, biv_2.value)
def test_general_logarithm_conformal(self):
object_generators = [random_point_pair, random_line, random_circle, random_plane]
# object_generators = [random_sphere]
for obj_gen in object_generators:
print(obj_gen.__name__)
for i in range(10000):
X = obj_gen()
Y = obj_gen()
R = rotor_between_objects(X, Y)
biv = general_logarithm(R)
R_recon = general_exp(biv).normal()
np.testing.assert_almost_equal(R.value, R_recon.value, 4)
def test_general_logarithm_TRS(self):
for i in range(5):
scale = 0.5 + np.random.rand()
S = generate_dilation_rotor(scale)
R = generate_rotation_rotor(0.5, e1, e2)
T = generate_translation_rotor(e3 + 7* e2 - e1)
V = (T * R * S).normal()
biv = general_logarithm(V)
V_rebuilt = general_exp(biv).normal()
biv2 = general_logarithm(V)
C1 = random_point_pair()
C2 = (V * C1 * ~V).normal()
C3 = (V_rebuilt * C1 * ~V_rebuilt).normal()
np.testing.assert_almost_equal(C2.value, C3.value)
def test_general_logarithm_scaling(self):
# Check we can reverse scaling
for i in range(50):
scale = 0.5 + np.random.rand()
biv = -np.log(scale ) *e45 /2
R = general_exp(biv).normal()
biv_2 = general_logarithm(R)
np.testing.assert_almost_equal(biv.value, biv_2.value)
def test_general_logarithm_TS(self):
for i in range(5):
scale = 0.5 +np.random.rand()
t = random_euc_mv()
S = generate_dilation_rotor(scale)
T = generate_translation_rotor(t)
V = ( T *S).normal()
biv = general_logarithm(V)
V_rebuilt = (general_exp(biv)).normal()
C1 = random_point_pair()
C2 = ( V *C1 *~V).normal()
C3 = (V_rebuilt *C1 *~V_rebuilt).normal()
np.testing.assert_almost_equal(C2.value, C3.value, 5)
def full_conformal_biv_params_to_rotor(biv_params):
"""
Converts the bivector parameters for a general conformal rotor into
the rotor
"""
biv = full_conformal_biv_params_to_biv(biv_params)
R = general_exp(biv).normal()
return R
def exp(self) -> 'MultiVector':
return general_exp(self)
def __rpow__(self, other) -> 'MultiVector':
"""Exponentiation of a real by a multivector, :math:`r^{M}`"""
# Let math.log() check that other is a Python number, not something
# else.
# pow(x, y) == exp(y * log(x))
newMV = general_exp(math.log(other) * self)
return newMV
def TRS_biv_params_to_rotor(biv_params):
"""
Converts the bivector parameters for a general TRS rotor into
the rotor
"""
biv = TRS_biv_params_to_biv(biv_params)
R = general_exp(biv).normal()
return R