function [rx,ry] = partiviewangles (from,to) % PARTIVIEWANGLES computes rx and ry for Partiview % % from and to are 3-dim vectors of x y z positions % e.g. if your camera is at (x1,y1,z1) looking at (x2,y2,z2) then % from = [x1 y1 z1] and to=[x2 y2 z2] % % You can then say "jump x1 y1 z1 rx ry 0" % % rz is the rotation around the z axis, we can keep it fixed for now % % dinoj@cs.uchicago.edu Sun Jul 17 03:31:43 CEST 2005 % % The basic idea is to rotate the vector from 0,0,0 to 0,0,-1 % first around the y-axis, % then round the x-axis, % till it becomes the vector V from 0,0,0 to x2-x1,y2-y1,z2-z1 % % There can be multiple solutions for the same angle. abc = to-from; n = norm(abc); rx = 0; ry = 0; if n abc=abc/n; else return; end a=abc(1); b=abc(2); c=abc(3); % rem n = 1 now anglefromy = acos(abs(b)); % angle from V to the y-axis anglefromx = acos(abs(a)); % angle from V to the x-axis if (a==0 & b==0) if c>0 rx = pi; end elseif c==0 rx = sign(b) * anglefromx ; % equiv to sign(b) * (pi/2 - anglefromy) ry = -sign(a) * pi/2; % if c==0 and b==0 then rx=0 and ry=same % note that this case, at least for b~=0, would be covered by the base case if sign(c) was % taken to be -1. elseif b == 0 ry = -sign(a) * (pi/2 + sign(c)*anglefromx); else rx = sign(b)* (pi/2 + sign(c)*anglefromy) ; ry = sign(c) * sign(a)*atan(abs(a)/abs(c)) ; end rx = rx*180/pi; ry = ry*180/pi;