ROTATEVECTOR Rotate a vector by a given angle. VR = rotateVector(V, THETA) Rotate the vector V by an angle THETA, given in radians. Example rotateVector([1 0], pi/2) ans = 0 1 See also vectors2d, transformVector, createRotation ------ Author: David Legland e-mail: david.legland@grignon.inra.fr Created: 2011-04-14, using Matlab 7.9.0.529 (R2009b) Copyright 2011 INRA - Cepia Software Platform.
0001 function vr = rotateVector(v, angle) 0002 %ROTATEVECTOR Rotate a vector by a given angle. 0003 % 0004 % VR = rotateVector(V, THETA) 0005 % Rotate the vector V by an angle THETA, given in radians. 0006 % 0007 % Example 0008 % rotateVector([1 0], pi/2) 0009 % ans = 0010 % 0 1 0011 % 0012 % See also 0013 % vectors2d, transformVector, createRotation 0014 % 0015 % ------ 0016 % Author: David Legland 0017 % e-mail: david.legland@grignon.inra.fr 0018 % Created: 2011-04-14, using Matlab 7.9.0.529 (R2009b) 0019 % Copyright 2011 INRA - Cepia Software Platform. 0020 0021 % precomputes angles 0022 cot = cos(angle); 0023 sit = sin(angle); 0024 0025 % compute rotated coordinates 0026 vr = [cot * v(:,1) - sit * v(:,2) , sit * v(:,1) + cot * v(:,2)];