TriadSemi / triad_openvr

This is an enhanced wrapper for the already excellent pyopenvr library by cmbruns. The goal of this library is to create easy to use python functions for any SteamVR tracked system.
160 stars 54 forks source link

Math error in convert_to_quaternion #2

Closed ekuusi closed 7 years ago

ekuusi commented 7 years ago

If 1+pose_mat[0][0]+pose_mat[1][1]+pose_mat[2][2] produces a value close enough to 0, for example as in my last test run 5.699694156646729e-07, the line

r_w = math.sqrt(1+pose_mat[0][0]+pose_mat[1][1]+pose_mat[2][2])/2

4.76837158203125e-07 Traceback (most recent call last): File "trackingtest.py", line 21, in for each in v.devices["tracker_1"].get_pose_quaternion(): File "F:\Coding\Tracking\triad_openvr.py", line 104, in get_pose_quaternion return convert_to_quaternion(pose[self.index].mDeviceToAbsoluteTracking) File "F:\Coding\Tracking\triad_openvr.py", line 32, in convert_to_quaternion r_w = math.sqrt(1+pose_mat[0][0]+pose_mat[1][1]+pose_mat[2][2])/2 ValueError: math domain error

Returns a math error. Not completely sure why as math.sqrt(0) should work fine

ekuusi commented 7 years ago

Ok so the issue is that 1+pose_mat[0][0]+pose_mat[1][1]+pose_mat[2][2] can return values less than 0. Just add abs to the calculation should fix this, not sure if it messes up quaternion calculation somehow though:

r_w = math.sqrt(abs(1+pose_mat[0][0]+pose_mat[1][1]+pose_mat[2][2]))/2

works

lgbeno commented 7 years ago

Good catch and thank you for suggesting a fix! I committed the change!