Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_normalized() not working #12

Open
RubensBenevides opened this issue Sep 12, 2024 · 1 comment
Open

is_normalized() not working #12

RubensBenevides opened this issue Sep 12, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@RubensBenevides
Copy link
Contributor

I have tested the is_normalized() function with two normalized dual quaternions, dq1 and dq2, but it only returns False. The two dual quaternions:

dq1 = DualQuaternion(-0.19846574648301676, -0.003727645110356892, 0.019714514040105935, 0.9799024390575996) + (-0.26885821157532125, 20.377681310377717, -3.2778468461642998, 0.0890116940545257)e>

dq2 = DualQuaternion(-0.19815311910261352, -0.004011949502977785, 0.019765922709431866, 0.9799635472559859) + (-0.2819718824973357, 20.36564434954993, -3.2589343810704126, 0.09209339883505874)e>

dq1 and dq2 are normalized, if we use the function below in dq1 and dq2, it returns:
'Rotation part is normalized'
'The dual part is normalized'

def is_dual_quaternion_normalized(dual_quaternion):
    tolerance = 1e-15
    # Check the rotation part
    if abs(dual_quaternion.q_r.norm - 1) > tolerance:
        print("Rotation part is not normalized")
    else:
        print("Rotation part is normalized")
    # Check the dual part
    part1 = dual_quaternion.q_r * dual_quaternion.q_d.conjugate
    part2 = dual_quaternion.q_d*dual_quaternion.q_r.conjugate
    if abs(sum(part1 + part2)) > tolerance:
        print("Dual part is not normalized")
    else:
        print("Dual part is normalized")
@Achllle
Copy link
Owner

Achllle commented Sep 24, 2024

Thanks for reporting this!
I just tested this in #10 where the is_normalized function works as follows:

return np.isclose(self.q_r.norm, 1.0) and np.isclose(self.q_r.w * self.q_d.w + np.dot(self.q_r.vector, self.q_d.vector), 0)

The function docstrings describe why this works.

Testing it on your dual quaternions:

from dual_quaternions import DualQuaternion as DQ
import numpy as np
dq1 = DQ.from_dq_array(np.array([-0.19846574648301676, -0.003727645110356892, 0.019714514040105935, 0.9799024390575996, -0.26885821157532125, 20.377681310377717, -3.2778468461642998, 0.0890116940545257]))
dq2 = DQ.from_dq_array(np.array([-0.19815311910261352, -0.004011949502977785, 0.019765922709431866, 0.9799635472559859, -0.2819718824973357, 20.36564434954993, -3.2589343810704126, 0.09209339883505874]))

print(dq1.is_normalized)
print(dq2.is_normalized)

yields

True
True

I will revisit that PR and make sure the fix gets in.

@Achllle Achllle self-assigned this Sep 24, 2024
@Achllle Achllle added the bug Something isn't working label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants