
How do I rotate a radial vector around a unit circle and plot each position?
    7 views (last 30 days)
  
       Show older comments
    
    MathWorks Support Team
    
 on 23 Mar 2023
  
    
    
    
    
    Answered: MathWorks Support Team
    
 on 5 Apr 2023
            I have a vector consisting of m points, or three (x, y)-coordinate pairs. For instance, the x-coordinate are all zero, so the vector points in the y-direction. I want to rotate this vector n times around the unit circle and store each result in a new matrix of size (mxn)x2 matrix. This is what I have so far, but I have hard-coded m = 3:
clear
clc
clf
n=10;
AngRot=-360/n;
Am=[cosd(AngRot) sind(AngRot);...
          -sind(AngRot) cosd(AngRot)];%rotation matrix
x1=[0 0 0]';
y1=[1 1.1 1.2]';
xy1=[x1 y1]
xy2=xy1*Am
x2=xy2(:,1);
y2=xy2(:,2);
xy3=xy2*Am
x3=xy3(:,1);
y3=xy3(:,2);
ang=linspace(0,360,100);
xc=cosd(ang);
yc=sind(ang);
plot(x1,y1,x2,y2,x3, y3,xc,yc)
grid on
axis equal;
Here is what it generates. I'm not sure how to automate it to fill in all the rotations or save the results.

Accepted Answer
  MathWorks Support Team
    
 on 23 Mar 2023
        Below is a full demo of how to do so in MATLAB, where m is the size of the vector and n is the number of rotations. The rotated vectors are saved in the matrix XY.
%% This is a demo to rotate your mx2 vector n times and generate a (mxn)x2
% matrix full of these resulting data points.
clear
clc
close all
%% Start with your values for m and n and calculate rotation matrix.
m = 6;
n = 50;
theta = 360/n;
R = [cosd(theta) -sind(theta);
    sind(theta) cosd(theta)]';
%% Allocate space for the end matrix.
XY = zeros(m*n, 2);
%% Generate the first vector.
x = zeros(m, 1);
y = linspace(1, 1.5, m)';
xy = [x y];
XY(1:m, :) = xy;
%% Loop through and calculate rotated matrcies.
for i = 1+m:m:m*n
    xy = xy*R;
    XY(i:i+m-1, :) = xy;
end
%% Plot the results.
hold on
grid on
axis equal
ang = linspace(0,360,100);
xc = cosd(ang);
yc = sind(ang);
plot(xc, yc)
for k = 1:m:m*n
    x = XY(k:k+m-1, 1);
    y = XY(k:k+m-1, 2);
    plot(x, y);
end
The result is the following:

0 Comments
More Answers (0)
See Also
Categories
				Find more on Surface and Mesh Plots in Help Center and File Exchange
			
	Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!