diff --git a/+mystica/+rbm/getQuatGivenRotm.m b/+mystica/+rbm/getQuatGivenRotm.m index ef9c71c..2857486 100644 --- a/+mystica/+rbm/getQuatGivenRotm.m +++ b/+mystica/+rbm/getQuatGivenRotm.m @@ -59,3 +59,21 @@ quat = [qw;qx;qy;qz] / quaternionNorm; end + +%% alternative implementation +% +% function quat = getQuatGivenRotm2(rotm) +% +% qw = 0.5 * 1 * sqrt(rotm(1,1) + rotm(2,2) + rotm(3,3) + 1); +% qx = 0.5 * sign0(rotm(3,2) - rotm(2,3)) * sqrt(rotm(1,1) - rotm(2,2) - rotm(3,3) + 1); +% qy = 0.5 * sign0(rotm(1,3) - rotm(3,1)) * sqrt(rotm(2,2) - rotm(3,3) - rotm(1,1) + 1); +% qz = 0.5 * sign0(rotm(2,1) - rotm(1,2)) * sqrt(rotm(3,3) - rotm(1,1) - rotm(2,2) + 1); +% +% quat = [qw;qx;qy;qz]; +% +% end +% +% function s = sign0(x) +% s = 2*(x>=0)-1; +% end + diff --git a/+mystica/+rbm/getRotmGivenQuat.m b/+mystica/+rbm/getRotmGivenQuat.m index 7c38a33..0041d10 100644 --- a/+mystica/+rbm/getRotmGivenQuat.m +++ b/+mystica/+rbm/getRotmGivenQuat.m @@ -1,8 +1,8 @@ function rotm = getRotmGivenQuat(quat) - + qw = quat(1); qxyz = quat(2:4); - + rotm = eye(3)+2*qw*mystica.utils.skew(qxyz)+2*mystica.utils.skew(qxyz)^2; - + end diff --git a/+mystica/+rbm/invQuat.m b/+mystica/+rbm/invQuat.m new file mode 100644 index 0000000..5d0b5a7 --- /dev/null +++ b/+mystica/+rbm/invQuat.m @@ -0,0 +1,6 @@ +function quat_b_a = invQuat(quat_a_b) + + qw = quat_a_b(1); qxyz = quat_a_b(2:4); + quat_b_a = [qw;-qxyz]/(norm(quat_a_b)^2); + +end diff --git a/+mystica/+rbm/logQuat.m b/+mystica/+rbm/logQuat.m new file mode 100644 index 0000000..1fd98b1 --- /dev/null +++ b/+mystica/+rbm/logQuat.m @@ -0,0 +1,19 @@ +function theta = logQuat(quat,input) + arguments + quat + input.selectQuat char {mustBeMember(input.selectQuat,{'positive','minDistance','normal'})} = 'normal' + end + qw = quat(1); qxyz = quat(2:4); + switch input.selectQuat + case 'normal' + normV = norm(qxyz,2)+eps; + theta = 2 * qxyz * atan2(normV,qw)/normV; + case 'positive' + quat = -quat*(qw<0)+quat*(qw>=0); + theta = mystica.rbm.logQuat(quat,'selectQuat','normal'); + case 'minDistance' + theta1 = mystica.rbm.logQuat( quat,'selectQuat','normal'); n1 = norm(theta1,2); + theta2 = mystica.rbm.logQuat(-quat,'selectQuat','normal'); n2 = norm(theta2,2); + theta = theta1*(n1<=n2)+theta2*(n2