From d736c400b9448c37ad15ccac4d243e4a5c9ac79c Mon Sep 17 00:00:00 2001 From: Christopher Collins Date: Thu, 18 Jul 2013 14:35:03 -0400 Subject: [PATCH] Fix reorient code to work in all cases --- @Gaussian/reorient.m | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/@Gaussian/reorient.m b/@Gaussian/reorient.m index 2652f0e..db312bc 100644 --- a/@Gaussian/reorient.m +++ b/@Gaussian/reorient.m @@ -9,18 +9,17 @@ function reorient(obj) rcart(3,:) = obj.rcart(find(vals == minv),:); obj.rcart = rcart; - for j = 1:2 - bb = obj.boundingBox(); - minpoint = obj.rcart(:,find(obj.rcart(1,:)==bb.minx)); - maxpoint = obj.rcart(:,find(obj.rcart(1,:)==bb.maxx)); - angle = -atan2(maxpoint(2)-minpoint(2),maxpoint(1)-minpoint(1)); - R = [cos(angle),-sin(angle); sin(angle),cos(angle)]; + bb = obj.boundingBox(); + minpoint = obj.rcart(:,find(obj.rcart(1,:)==bb.minx)); + temp = princomp(obj.rcart(1:2,:)'); + angle = atan2(temp(1,2), temp(1,1)); + R = [cos(angle),-sin(angle); sin(angle),cos(angle)]; - sub = ones(size(obj.rcart(1:2,:))); - sub(1,:) = sub(1,:)*minpoint(1); - sub(2,:) = sub(2,:)*minpoint(2); - rcart = R*(obj.rcart(1:2,:)-sub) + sub; - obj.rcart(1:2,:) = rcart; - end + sub = ones(size(obj.rcart(1:2,:))); + sub(1,:) = sub(1,:)*minpoint(1); + sub(2,:) = sub(2,:)*minpoint(2); + + rcartpos = R*(obj.rcart(1:2,:)-sub) + sub; + obj.rcart(1:2,:) = rcartpos; end