Skip to content

Commit 72e9a22

Browse files
committed
enforce scalar part is non-negative
1 parent f222bec commit 72e9a22

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

UnitQuaternion.m

+10
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@
195195
v = formula(v);
196196
end
197197
n = norm([s; v(:)]);
198+
if s < 0
199+
% enforce non-negative scalar
200+
s = -s;
201+
v = -v;
202+
end
198203
uq.s = s/n;
199204
uq.v = v/n;
200205
elseif isvec(s,4)
@@ -203,6 +208,10 @@
203208
if ~isa(s, 'sym')
204209
s = unit(s);
205210
end
211+
if s(1) < 0
212+
% enforce non-negative scalar
213+
s = -s;
214+
end
206215
uq.s = s(1);
207216
uq.v = s(2:4);
208217
else
@@ -1189,6 +1198,7 @@ function animate(Q, varargin)
11891198
uq = UnitQuaternion(s, qv);
11901199
end
11911200

1201+
11921202
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11931203
%%%% OTHER STATIC METHODS, ALTERNATIVE CONSTRUCTORS
11941204
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

0 commit comments

Comments
 (0)