File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 534534 [varargout{1 : nargout }] = tr2angvec(obj .R , varargin{: });
535535 end
536536
537+
538+ function d = angdist(R1 , R2 , method )
539+ % SO3.angdist Distance metric
540+ %
541+ % R1.angdist(R2) is a distance metric between two SO(3) rotation
542+ % matrices.
543+ %
544+ % R1.angdist(R2, M) as above but uses the method specified by M
545+ %
546+ % M = 1 (default): || I - R1 R2' || in [0,2]
547+ % M = 2: || log R1 R2' || in [0,pi]
548+ %
549+ %
550+ % See also: trlog, UnitQuaternion.angdist
551+ if ~isa(R2 , ' SO3' )
552+ error(' SMTB:SO3:badarg' , ' angdist: incorrect operand' );
553+ end
554+ if nargin == 2
555+ method = 1
556+ end
557+
558+ switch method
559+ case 1
560+ d = norm(eye(3 ) - R1 .R * R2 .R ' )
561+ case 2
562+ d = norm(trlog(R1 .R * R2 .R ' ))
563+ end
564+ end
537565
538566
539567 function s = SE3(obj )
Original file line number Diff line number Diff line change @@ -950,6 +950,37 @@ function animate(Q, varargin)
950950 error(' SMTB:UnitQuaternion:eq: badargs' );
951951 end
952952 end
953+
954+
955+ function d = angdist(q1 , q2 , method )
956+ % UnitQuaternion.angdist Distance metric
957+ %
958+ % Q1.angdist(Q2) is a distance metric between two unit quaternions.
959+ %
960+ % Q1.angdist(Q2, M) as above but uses the method specified by M
961+ %
962+ % M = 1 (default): 1 - | < q1, q2> | in [0,pi/2]
963+ % M = 2: acos | <q1, q2> | in [0,1]
964+ %
965+ %
966+ % Note::
967+ % - angdist(q, -q) is equal to zero due to double mapping
968+ %
969+ % See also: SO3.angdist
970+ if ~isa(q2 , ' UnitQuaternion' )
971+ error(' SMTB:UnitQuaternion:badarg' , ' angdist: incorrect operand' );
972+ end
973+ if nargin == 2
974+ method = 1
975+ end
976+
977+ switch method
978+ case 1
979+ d = 1 - abs(q1 .inner(q2 ))
980+ case 2
981+ d = acos(abs(q1 .inner(q2 )))
982+ end
983+ end
953984
954985 end % methods
955986
You can’t perform that action at this time.
0 commit comments