Per ragionare più profondamente sul contenuto riguardante la rotazione della funzione seno con codice matlab, di cui sotto si faccia riferimento a quanto precedentemente discusso: Sistema di riferimento ruotato
Per ruotare la funzione seno si deve tenere in considerazione che essa deve mantenersi uguale a se stessa quando ruotata e quindi deve essere rigidamente ruotata.
Ottenendo un effetto di questo tipo si deve determinare intanto la direzione sulla quale si vuole ruotare la funzione seno.
Se si vuole ricavare il coefficiente angolare della direzione su cui si vuole ruotare la funzione seno si deve cercare di capire quale è l’angolo di rotazione che vogliamo ottenere. Per poterlo fare si considera la seguente:
\( m_{dir}=\frac{y_2-y_1}{x_2-x_1}\)
In cui:
- \((x_2;y_2)\)è un punto della retta, la quale rappresenta la direzione su cui si vuole ruotare la funzione seno
- \( (x_1;y_1)\) è un altro punto della retta, la quale rappresenta la direzione su cui si vuole ruotare la funzione seno
Una volta stabilita la direzione si considera che:
\( \theta ={\mathrm{arctan} \left(m_{dir}\right)\ }={\mathrm{arctan} \left(\frac{y_2-y_1}{x_2-x_1}\right)\ }\)
Calcolato è ora possibile stabilire la matrice di rotazione:
\( R_{\theta }=\left[ \begin{array}{cc}
cos\theta & -sin\theta \\
sin\theta & cos\theta \end{array}
\right]\)
Ovvero:
\({\boldsymbol{R}}_{\boldsymbol{\theta }}=\left[ \begin{array}{cc}
{\mathrm{cos} {\mathrm{(arctan} \left(m_{dir}\right))\ }\ } & -{\mathrm{sin} {\mathrm{(arctan} \left(m_{dir}\right))\ }\ } \\
{\mathrm{sin} {\mathrm{(arctan} \left(m_{dir}\right))\ }\ } & {\mathrm{cos} {\mathrm{(arctan} \left(m_{dir}\right))\ }\ } \end{array}
\right]\)
O anche:
\( {\boldsymbol{R}}_{\boldsymbol{\theta }}=\left[ \begin{array}{cc}
{\mathrm{cos} \left({\mathrm{arctan} \left(\frac{y_2-y_1}{x_2-x_1}\right)\ }\right)\ } & -{\mathrm{sin} \left({\mathrm{arctan} \left(\frac{y_2-y_1}{x_2-x_1}\right)\ }\right)\ } \\
{\mathrm{sin} \left({\mathrm{arctan} \left(\frac{y_2-y_1}{x_2-x_1}\right)\ }\right)\ } & {\mathrm{cos} \left({\mathrm{arctan} \left(\frac{y_2-y_1}{x_2-x_1}\right)\ }\right)\ } \end{array}
\right]\)
Sull’asse non ruotato la funzione seno è definita dalla relazione \( y={\mathrm{sin} x\ }\).
Volendo riscrivere nella forma parametrizzata si ha:
\( \left\{ \begin{array}{c}
x=t \\
y=sint \end{array}
\right.\)
La precedente può essere ruotata, per una qualunque direzione, in questo modo:
\( {\boldsymbol{R}}_{\boldsymbol{\theta }}\cdot \overrightarrow{t}=\left[ \begin{array}{cc}
cos\theta & -sin\theta \\
sin\theta & cos\theta \end{array}
\right]\left[ \begin{array}{c}
t \\
\mathrm{sin}\mathrm{}(t) \end{array}
\right]\)
Riscrivibile anche come:
\( {\boldsymbol{R}}_{\boldsymbol{\theta }}\cdot \overrightarrow{t}=\left[ \begin{array}{cc}
{\mathrm{cos} {\mathrm{(arctan} \left(m_{dir}\right))\ }\ } & -{\mathrm{sin} {\mathrm{(arctan} \left(m_{dir}\right))\ }\ } \\
{\mathrm{sin} {\mathrm{(arctan} \left(m_{dir}\right))\ }\ } & {\mathrm{cos} {\mathrm{(arctan} \left(m_{dir}\right))\ }\ } \end{array}
\right]\left[ \begin{array}{c}
t \\
\mathrm{sin}\mathrm{}(t) \end{array}
\right]\)
Oppure anche:
\( {\boldsymbol{R}}_{\boldsymbol{\theta }}\cdot \overrightarrow{t}=\left[ \begin{array}{cc}
{\mathrm{cos} \left({\mathrm{arctan} \left(\frac{y_2-y_1}{x_2-x_1}\right)\ }\right)\ } & -{\mathrm{sin} \left({\mathrm{arctan} \left(\frac{y_2-y_1}{x_2-x_1}\right)\ }\right)\ } \\
{\mathrm{sin} \left({\mathrm{arctan} \left(\frac{y_2-y_1}{x_2-x_1}\right)\ }\right)\ } & {\mathrm{cos} \left({\mathrm{arctan} \left(\frac{y_2-y_1}{x_2-x_1}\right)\ }\right)\ } \end{array}
\right]\left[ \begin{array}{c}
t \\
\mathrm{sin}\mathrm{}(t) \end{array}
\right]\)
Con questa rotazione \( x_{rot}\) e \( y_{rot}\) si calcolano come segue:
\( \left\{ \begin{array}{c}
x_{rot}=t\cdot cos\theta -sint\cdot sin\theta \\
y_{rot}=t\cdot sin\theta +sint\cdot cos\theta \end{array}
\right.\)
In questo modo abbiamo ottenuto una rotazione della funzione seno passando per una forma parametrizzata.
Possiamo anche decidere di non sfruttare la parametrizzata e, in tal caso, la rotazione della funzione seno è la seguente:
\( \left\{ \begin{array}{c}
x_{game,pert}=x_{game}\cdot cos\theta -y_{game}\cdot sin\theta \\
y_{game,pert}=x_{game}\cdot sin\theta +y_{game}\cdot cos\theta \end{array}
\right.\)
Nell’immagine seguente viene mostrata una rotazione di 60° (con programma matlab).

Appendice
Di seguito viene mostrato un codice Matlab che mostra la rotazione di 60° di una funzione seno.
%% Sin not rotated % Time specifications Fs = 8000;                % samples per second dt = 1/Fs;                % seconds per sample StopTime = 10;            % seconds x = (0:dt:StopTime-dt)';  % seconds xr = x;                   % rotated % Sin wave Fc = 1;                   % hertz y = sin(2*pi*Fc*x); yr = y; ydir = 0*x; % Plotting the sin not rotated figure; plot(x,y); xlabel('x'); ylabel('y'); hold on; plot(x,ydir); title('Comparing sin and sin rotated'); %% Applying rotation % Imposing rotation specs theta = pi/3; ydir_rot = sqrt(3)*x; rot_mtr =[cos(theta) -sin(theta); sin(theta) cos(theta)]; %Applying rotation to the function for i = 1:length(x) tmp = rot_mtr * [x(i) ; y(i)]; xr(i) = tmp(1); yr(i) = tmp(2); end % Plotting the sin rotated hold on; plot(xr,yr); hold on; plot(x,ydir_rot);
Qui di seguito puoi scaricare il documento relativo a questo post:
Come effettuare la rotazione della funzione seno (in codice matlab)
Devi effettuare l'accesso per postare un commento.