Skip to content

Commit

Permalink
u vector simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDouillet committed Apr 10, 2023
1 parent dfdace1 commit c7d1e99
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 33 deletions.
2 changes: 1 addition & 1 deletion doc.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
%
% Function to compute the rotation of a vector in 2D and / or 3D spaces.
%
% Author & support : nicolas.douillet (at) free.fr, 2017-2020.
% Author & support : nicolas.douillet (at) free.fr, 2017-2023.
%
%% Syntax
% R = rotate_3D(V, mode, theta);
Expand Down
38 changes: 10 additions & 28 deletions html/doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!--
This HTML was auto-generated from MATLAB code.
To make changes, update the MATLAB code and republish this document.
--><title>rotate_3D</title><meta name="generator" content="MATLAB 9.7"><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/"><meta name="DC.date" content="2020-06-29"><meta name="DC.source" content="doc.m"><style type="text/css">
--><title>rotate_3D</title><meta name="generator" content="MATLAB 9.7"><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/"><meta name="DC.date" content="2023-04-10"><meta name="DC.source" content="doc.m"><style type="text/css">
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outine:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0}

html { min-height:100%; margin-bottom:1px; }
Expand Down Expand Up @@ -66,7 +66,7 @@



</style></head><body><div class="content"><h1>rotate_3D</h1><!--introduction--><p>Function to compute the rotation of a vector in 2D and / or 3D spaces.</p><p>Author &amp; support : nicolas.douillet (at) free.fr, 2017-2020.</p><!--/introduction--><h2>Contents</h2><div><ul><li><a href="#1">Syntax</a></li><li><a href="#2">Description</a></li><li><a href="#3">Input arguments</a></li><li><a href="#4">Output arguments</a></li><li><a href="#5">3D Example #1</a></li><li><a href="#6">3D Example #2</a></li><li><a href="#7">3D Example #3</a></li><li><a href="#8">2D Example #1</a></li><li><a href="#9">2D Example #2</a></li><li><a href="#10">2D Example #3</a></li></ul></div><h2 id="1">Syntax</h2><p>R = rotate_3D(V, mode, theta);</p><p>R = rotate_3D(V, mode, theta, u);</p><p>R = rotate_3D(V, mode, theta, u, angle_unit);</p><p>[R,Rm] = rotate_3D(V, mode, theta, u, angle_unit);</p><h2 id="2">Description</h2><p>R = rotate_3D(V, mode, theta) computes the vector R, which results from the rotation of V vector around one of the the basis vectors, which is choosen in the mode : 'x', 'y', or 'z'.</p><p>R = rotate_3D(V, mode, theta, u) computes the vector R, which results from the rotation of V vector around u vector and of theta angle in radian.</p><p>R = rotate_3D(V, mode, theta, u, angle_unit) uses angle_unit for theta unit (radian or degree).</p><p>[R,Rm] = rotate_3D(V, mode, theta, u, angle_unit) also returns the rotation matrix.</p><p>Important NB : in 2D -(xOy) plan- mandatory rotation axis is 'z'. It will be set as so by default if input different. Also in 2D, in case u is missing it is automatically set to the origin [0,0]' by default.</p><h2 id="3">Input arguments</h2><pre> [ -Vx- ]
</style></head><body><div class="content"><h1>rotate_3D</h1><!--introduction--><p>Function to compute the rotation of a vector in 2D and / or 3D spaces.</p><p>Author &amp; support : nicolas.douillet (at) free.fr, 2017-2023.</p><!--/introduction--><h2>Contents</h2><div><ul><li><a href="#1">Syntax</a></li><li><a href="#2">Description</a></li><li><a href="#3">Input arguments</a></li><li><a href="#4">Output arguments</a></li><li><a href="#5">3D Example #1</a></li><li><a href="#6">3D Example #2</a></li><li><a href="#7">3D Example #3</a></li><li><a href="#8">2D Example #1</a></li><li><a href="#9">2D Example #2</a></li><li><a href="#10">2D Example #3</a></li></ul></div><h2 id="1">Syntax</h2><p>R = rotate_3D(V, mode, theta);</p><p>R = rotate_3D(V, mode, theta, u);</p><p>R = rotate_3D(V, mode, theta, u, angle_unit);</p><p>[R,Rm] = rotate_3D(V, mode, theta, u, angle_unit);</p><h2 id="2">Description</h2><p>R = rotate_3D(V, mode, theta) computes the vector R, which results from the rotation of V vector around one of the the basis vectors, which is choosen in the mode : 'x', 'y', or 'z'.</p><p>R = rotate_3D(V, mode, theta, u) computes the vector R, which results from the rotation of V vector around u vector and of theta angle in radian.</p><p>R = rotate_3D(V, mode, theta, u, angle_unit) uses angle_unit for theta unit (radian or degree).</p><p>[R,Rm] = rotate_3D(V, mode, theta, u, angle_unit) also returns the rotation matrix.</p><p>Important NB : in 2D -(xOy) plan- mandatory rotation axis is 'z'. It will be set as so by default if input is different. Also in 2D, in case u is missing it is automatically set to the origin [0,0]' by default.</p><h2 id="3">Input arguments</h2><pre> [ -Vx- ]
- V = [ -Vy- ], real (array of) vector(s) double, the vector(s) to rotate. Size(V) = [3,vector_nb].
[ -Vz- ]</pre><p>- mode : character string in the set {'x', 'X', 'y', 'Y', 'z', 'Z', 'any', 'ANY'}.</p><p>- theta : real scalar double, the rotation angle in radian.</p><pre> [ux]
- u : = [uy], real column vector double, the rotation axis.
Expand All @@ -78,75 +78,57 @@
theta = 2*pi/3;
R = rotate_3D(V, mode, theta, u)
<span class="comment">%</span>
</pre><pre class="codeoutput">
R =

</pre><pre class="codeoutput">R =
0.0000
1.0000
-0.0000

</pre><h2 id="6">3D Example #2</h2><p>2*pi/3 rotation of basis vector i around [0 0 1]' / z axis. u argument is optional in this case.</p><pre class="codeinput">mode = <span class="string">'z'</span>;
R = rotate_3D(V, mode, theta) <span class="comment">% equivalent to rotate_3D([1 0]', mode, theta) here</span>
<span class="comment">%</span>
</pre><pre class="codeoutput">
R =

</pre><pre class="codeoutput">R =
-0.5000
0.8660
0

</pre><h2 id="7">3D Example #3</h2><p>Array example 2*pi/3 rotation of (i,j,k) basis vectors around [1 1 1]' is its permutation (j,k,i).</p><pre class="codeinput">V = eye(3);
u = ones(3,1);
mode = <span class="string">'any'</span>;
R = rotate_3D(V, mode, theta, u)
<span class="comment">%</span>
</pre><pre class="codeoutput">
R =

</pre><pre class="codeoutput">R =
0.0000 -0.0000 1.0000
1.0000 0.0000 -0.0000
-0.0000 1.0000 0.0000

</pre><h2 id="8">2D Example #1</h2><p>3*pi/2 rotation of basis vector j around basis vector z is basis vector i.</p><pre class="codeinput">V = [0 1]';
mode = <span class="string">'z'</span>;
theta = 3*pi/2;
R = rotate_3D(V, mode, theta)
<span class="comment">%</span>
</pre><pre class="codeoutput">
R =

</pre><pre class="codeoutput">R =
1.0000
-0.0000

</pre><h2 id="9">2D Example #2</h2><p>pi/6 rotation of unitary vector [0.5 sqrt(3)/2]' around the origin is basis vector j. (default)</p><pre class="codeinput">V = [0.5 sqrt(3)/2]';
mode = <span class="string">'z'</span>;
theta = pi/6;
R = rotate_3D(V, mode, theta)
<span class="comment">%</span>
</pre><pre class="codeoutput">
R =

</pre><pre class="codeoutput">R =
0.0000
1.0000

</pre><h2 id="10">2D Example #3</h2><p>45&deg; rotation of basis vector i around -0.5*[sqrt(2) sqrt(2)]' is basis vector j.</p><pre class="codeinput">V = [1 0]';
u = -0.5*[sqrt(2) sqrt(2)]';
mode = <span class="string">'x'</span>; <span class="comment">% 2D mode automatically set back to 'z' in case of mistake.</span>
theta = 45; <span class="comment">% unit i=in degree</span>
R = rotate_3D(V, mode, theta, u, <span class="string">'degree'</span>)
</pre><pre class="codeoutput">
R =

</pre><pre class="codeoutput">R =
-0.0000
1.0000

</pre><p class="footer"><br><a href="https://www.mathworks.com/products/matlab/">Published with MATLAB&reg; R2019b</a><br></p></div><!--
##### SOURCE BEGIN #####
%% rotate_3D
%
% Function to compute the rotation of a vector in 2D and / or 3D spaces.
%
% Author & support : nicolas.douillet (at) free.fr, 2017-2020.
% Author & support : nicolas.douillet (at) free.fr, 2017-2023.
%
%% Syntax
% R = rotate_3D(V, mode, theta);
Expand All @@ -172,7 +154,7 @@
% rotation matrix.
%
% Important NB : in 2D -(xOy) plan- mandatory rotation axis is 'z'. It will
% be set as so by default if input different. Also in 2D, in case u is missing it
% be set as so by default if input is different. Also in 2D, in case u is missing it
% is automatically set to the origin [0,0]' by default.
%
%% Input arguments
Expand Down
8 changes: 4 additions & 4 deletions rotate_3D.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function [R, Rm] = rotate_3D(V, mode, theta, u, angle_unit)
%% rotate_3D : function to compute the rotation of a vector or an array of vectors in 2D or 3D space.
%
% Author && support : nicolas.douillet (at) free.fr, 2017-2020.
% Author && support : nicolas.douillet (at) free.fr, 2017-2023.
%
%
% Syntax
Expand Down Expand Up @@ -207,9 +207,9 @@

u = u/norm(u);

Rm = [u(1,1)^2+cos(theta)*(1-u(1,1)^2) (1-cos(theta))*u(1,1)*u(2,1)-u(3,1)*sin(theta) (1-cos(theta))*u(1,1)*u(3,1)+u(2,1)*sin(theta);
(1-cos(theta))*u(1,1)*u(2,1)+u(3,1)*sin(theta) u(2,1)^2+cos(theta)*(1-u(2,1)^2) (1-cos(theta))*u(2,1)*u(3,1)-u(1,1)*sin(theta);
(1-cos(theta))*u(1,1)*u(3,1)-u(2,1)*sin(theta) (1-cos(theta))*u(2,1)*u(3,1)+u(1,1)*sin(theta) u(3,1)^2+cos(theta)*(1-u(3,1)^2)];
Rm = [u(1)^2+cos(theta)*(1-u(1)^2) (1-cos(theta))*u(1)*u(2)-u(3)*sin(theta) (1-cos(theta))*u(1)*u(3)+u(2)*sin(theta);
(1-cos(theta))*u(1)*u(2)+u(3)*sin(theta) u(2)^2+cos(theta)*(1-u(2)^2) (1-cos(theta))*u(2)*u(3)-u(1)*sin(theta);
(1-cos(theta))*u(1)*u(3)-u(2)*sin(theta) (1-cos(theta))*u(2)*u(3)+u(1)*sin(theta) u(3)^2+cos(theta)*(1-u(3)^2)];
otherwise

error('Bad mode argument : mode must be a string in the set {''x'',''X'',''y'',''Y'',''z'',''Z'',''any'',''ANY''}.');
Expand Down

0 comments on commit c7d1e99

Please sign in to comment.