markaren / DualQuaternion

DualQuaternion implementation
MIT License
0 stars 0 forks source link

normalize() is wrong #1

Closed stefnotch closed 7 years ago

stefnotch commented 7 years ago

https://github.com/markaren/DualQuaternion/blob/master/src/main/java/info/laht/dualquat/DualQuaternion.java#L89

This seems to be quite wrong. Normalizing a dual quaternion (or a quaternion) is being done by dividing it by the length. Not the length^2. (Which is the same as the dot product of itself: dot(real, real))

Why is it wrong? Well, here is a unit dual quaternion: 0,0,0,1, 0,0,0,0 And here is another dual quaternion: 0,0,0,2, 0,0,0,0 This one should turn into the unit one, when passed to the normalize function. What actually happens is this: normalize(0,0,0,2, 0,0,0,0) --> divides everything by 2^2 --> 0,0,0,0.5, 0,0,0,0 Wrong! Now, just for fun, let's try normalizing the result: normalize(0,0,0,0.5, 0,0,0,0) --> divides everything by 0.5^2 --> 0,0,0,2, 0,0,0,0 And, you end up with the starting one. That's just wrong.

markaren commented 7 years ago

Thanks you for you interests in this repository, as far I can you're the first one.

About your issue, I can't say I know the maths very well, but it worked when I used it at least. If what your saying is correct, would that mean that the code presented in this paper: http://dualquaternions.weebly.com/uploads/1/3/1/5/13150194/dual_quaternions_wscg_paper_pub.pdf is wrong as well?

stefnotch commented 7 years ago

Exactly! I also made that mistake when writing my own little dual quat library. (I also am not amazing when it comes to the maths.)

By the way, here is the normalize() function in another dual quaternion library: https://github.com/mosra/magnum/blob/master/src/Magnum/Math/DualQuaternion.h#L364 (Which most likely is correct. That library seems to have been written by guys who know their maths.)