Possible bug in ceres::QuaternionRotatePoint

317 views
Skip to first unread message

Zhao Fangda

unread,
Jul 12, 2016, 11:30:54 AM7/12/16
to Ceres Solver
Hi:

I'm trying to minimize the reprojection error with quaternions, however the function ceres::QuaternionRotatePoint gives a wrong result.
Than I checked the following two code snippets and find that they give different result to p[3].
snippet 1:
T p[3];
p[0] = T(X); p[1] = T(Y); p[2] = T(Z);
ceres::QuaternionRotatePoint(quaternion, p, p);

snippet 2:
T p[3], angleaxis[3];;
p[0] = T(X); p[1] = T(Y); p[2] = T(Z);
ceres::QuaternionToAngleAxis(quaternion, angleaxis);
ceres::AngleAxisRotatePoint(angleaxis, p, p);

I checked the code in rotation.h, it looks like that the bug was in ceres::UnitQuaternionRotatePoint, where q[0] * q[0] haven't been used in the calculation.

Is that a bug or I've just missed something?

Best.

Sameer Agarwal

unread,
Jul 12, 2016, 12:43:01 PM7/12/16
to Ceres Solver
can you share the actual numerical values you are using Zhao?
Sameer


--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/032b0b87-e7eb-466f-804b-71d0b4198485%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zhao Fangda

unread,
Jul 12, 2016, 1:51:24 PM7/12/16
to Ceres Solver
OK, here is one of my data.

X = 8.47, Y = 8.47, Z = 0;
q[0] = 0.778, q[1] = -0.628, q[2] = -0.00925, q[3] = -0.0137;

Hope this will help.

在 2016年7月13日星期三 UTC+9上午1:43:01,Sameer Agarwal写道:

Mike Vitus

unread,
Jul 14, 2016, 4:51:47 PM7/14/16
to Ceres Solver
Hi Zhao,

Using your values I compared the result of ceres::UnitQuaternionRotatePoint, and converting the quaternion to a rotation matrix (ceres::QuaternionToRotation) and performing R * p manually. The two results agreed. I also verified that the ceres::UnitQuaternionRotatePoint is unit tested. So the function should be correct.

From your code snippets, I think what is going on is that you are passing in the same pointer as the input and output. After each coordinate of the point is computed, this changes the input for computing the following coordinates.  So you should change:

ceres::QuaternionRotatePoint(quaternion, p, p);

to

T result[3];
ceres::QuaternionRotatePoint(quaternion, p, result);

cheers
Mike

Zhao Fangda

unread,
Jul 15, 2016, 4:03:22 AM7/15/16
to Ceres Solver
That's it! 
Thank you Mike, After I changed to different pointer, it gives correct result now.

Best,
Zhao

在 2016年7月15日星期五 UTC+9上午5:51:47,Mike Vitus写道:
Reply all
Reply to author
Forward
0 new messages