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

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 % E-mail: N/A
0026 % Created: 2017-08-07
0027 % Copyright 2017-2024
0028 
0029 P = reshape(P,3,1);
0030 
0031 % Translation from P to origin
0032 invtrans = [eye(3),-P; [0 0 0 1]];
0033 
0034 % Rotation from A to B
0035 rot = createRotationVector3d(A, B);
0036 
0037 % Translation from origin to P
0038 trans = [eye(3),P; [0 0 0 1]];
0039 
0040 % Combine
0041 TFM = trans*rot*invtrans;
0042 
0043 end

Generated on Thu 21-Nov-2024 11:30:22 by m2html © 2003-2022