Skip to content

Commit

Permalink
Fix reorient code to work in all cases
Browse files Browse the repository at this point in the history
  • Loading branch information
crcollins committed Jul 18, 2013
1 parent 80296c2 commit d736c40
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions @Gaussian/reorient.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d736c40

Please sign in to comment.