Home > matGeom > geom3d > createRotationVectorPoint3d.m

createRotationVectorPoint3d

PURPOSE ^

CREATEROTATIONVECTORPOINT3D Calculates the rotation between two vectors.

SYNOPSIS ^

function TFM = createRotationVectorPoint3d(A,B,P)

DESCRIPTION ^

CREATEROTATIONVECTORPOINT3D Calculates the rotation between two vectors.
   around a point
   
   TFM = createRotationVectorPoint3d(A,B,P) returns the transformation 
   to rotate the vector A in the direction of vector B around point P
   
   Example
     A=-5+10.*rand(1,3);
     B=-10+20.*rand(1,3);
     P=-50+100.*rand(1,3);
     ROT = createRotationVectorPoint3d(A,B,P);
     C = transformVector3d(A,ROT);
     figure('color','w'); hold on; view(3)
     drawPoint3d(P,'k')
     drawVector3d(P, A,'r')
     drawVector3d(P, B,'g')
     drawVector3d(P, C,'r')

   See also
   transformPoint3d, createRotationVector3d

 ---------
 Author: oqilipo
 Created: 2017-08-07
 Copyright 2017

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function TFM = createRotationVectorPoint3d(A,B,P)
0002 %CREATEROTATIONVECTORPOINT3D Calculates the rotation between two vectors.
0003 %   around a point
0004 %
0005 %   TFM = createRotationVectorPoint3d(A,B,P) returns the transformation
0006 %   to rotate the vector A in the direction of vector B around point P
0007 %
0008 %   Example
0009 %     A=-5+10.*rand(1,3);
0010 %     B=-10+20.*rand(1,3);
0011 %     P=-50+100.*rand(1,3);
0012 %     ROT = createRotationVectorPoint3d(A,B,P);
0013 %     C = transformVector3d(A,ROT);
0014 %     figure('color','w'); hold on; view(3)
0015 %     drawPoint3d(P,'k')
0016 %     drawVector3d(P, A,'r')
0017 %     drawVector3d(P, B,'g')
0018 %     drawVector3d(P, C,'r')
0019 %
0020 %   See also
0021 %   transformPoint3d, createRotationVector3d
0022 %
0023 % ---------
0024 % Author: oqilipo
0025 % Created: 2017-08-07
0026 % Copyright 2017
0027 
0028 P = reshape(P,3,1);
0029 
0030 % Translation from P to origin
0031 invtrans = [eye(3),-P; [0 0 0 1]];
0032 
0033 % Rotation from A to B
0034 rot = createRotationVector3d(A, B);
0035 
0036 % Translation from origin to P
0037 trans = [eye(3),P; [0 0 0 1]];
0038 
0039 % Combine
0040 TFM = trans*rot*invtrans;
0041 
0042 end

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019