# Rotating X & Y Data

7 views (last 30 days)
Tania on 20 Sep 2022
Commented: Star Strider on 27 Sep 2022
Hello
I am trying to rotate GPS data, that has been con verted into X & Y coordintes to dsplay lengthwy along the Y axis strting at 0,0
I'm trying to rotate data in a 6135 x 15 table, where the data is layed out as follows 6135 data points of coordintes seperted into X & yXcolumns for each person.
Time I Person 1 x I Person 1 y I Person 2 x I Person 2 y I Person 3 x I Person 3 y .....etc
I would like to rotate this date to run length way along the Y axis. Each line represents data for a different person (7 in total):
Is there a way to rotate a large table of X & Y coordinates.

Star Strider on 20 Sep 2022
See if the rotate function will work.
Star Strider on 27 Sep 2022
As always, my pleasure!

KSSV on 20 Sep 2022
p1 = rand(2,1) ;
p2 = rand(2,1) ;
%%rotation matrix
th = 90*pi/180 ;
R = [cos(th) -sin(th) ;sin(th) cos(th)] ;
%%rotate points
pr2 = R*p2 ;
figure
hold on
plot([p1(1) p2(1)],[p1(2) p2(2)] ,'r') ;
plot([p1(1) pr2(1)],[p1(2) pr2(2)] ,'b') ;
Tania on 23 Sep 2022
As a reference (continued from comment above):
I originally converted the ray Lat/Lon co-ordinates to X & Y coordinates using the following:
[x1,y1]= wgs2utm((data1(:,2)),(data1(:,3))) % I repeated this for each person
I then plotted each converted X & Y data point onto the graph above using the following code:
PlotGPS = scatter(Newdata(:,1),Newdata(:,2)); %Plots all the GPS data in a scatter to select 4 grid coordinates%
hold on
scatter(Newdata(:,3),Newdata(:,4));
scatter(Newdata(:,5),Newdata(:,6));
scatter(Newdata(:,7),Newdata(:,8));
scatter(Newdata(:,9),Newdata(:,10));
scatter(Newdata(:,11),Newdata(:,12));
scatter(Newdata(:,13),Newdata(:,14));
hold off
From here I used:
[PlotGPS] = ginput(4)
To create a boundary around the data points representing an (almost rectangular) field (shown by small light blue circles).
I then used the below code to rotate the boundary
Boundary = PlotGPS([2 4 3 1 2],:);
Boundlong = PlotGPS(4,:) - PlotGPS(2,:); % Length of line - long line
Boundshort = PlotGPS(1,:)- PlotGPS(2,:); % Width of line - short line
%% Rotational Matrix
theta = atan2(Boundlong(2),Boundlong(1)); % theta is in radians
R = [cos(theta) -sin(theta); sin(theta) cos(theta)]; % rotation matrix
BoundR = Boundary*R; %Rotate the field
This worked, (see above).
From my last post I'm now able to rotate, the X & Y dta points, hopwever as you can see in my last post its not rotating correctly.
Is there a way to use the boundary reference information to rotate my X & Y data?