Extract area from elipsoidal/cirle trajectory.
1 view (last 30 days)
Show older comments
Dear all, how are you?
I created the following code to simulate an anticlockwise rotating trajectory forced by an external velocity. Now, I want to calculate the area each time the trajectory makes a closed circle, as described in the attached image. I would appreciate any help in finding the best way to identify the areas inside the circles for each loop/circle in the trajectory.
For circle detection, I used the polyshape function as described in the attached figure. Unfortunately, this requires me to cut the series each time a circular trajectory is identified, and then manually choose the area I need, which takes too much time
Thanks for your time!
clear all,close all;
Fs = 1/0.5;
duration_hours = 25 * 24;
t = 0:1/Fs:duration_hours;
period = 20;
phase = -pi/2;
num_periods = floor(duration_hours / period);
amplitudes = 0.1/2 + 0.1 * rand(1, num_periods); % Random amplitudes between 0.1 and 0.3
y = zeros(size(t));
for i = 1:num_periods
start_idx = (i-1) * period * Fs + 1;
end_idx = i * period * Fs;
uI(start_idx:end_idx) = amplitudes(i) * sin(2*pi*(t(start_idx:end_idx) - t(start_idx))/period);
end
amplitudes = 0.1/2 + 0.1 * rand(1, num_periods); % Random amplitudes between 0.1 and 0.3
for i = 1:num_periods
start_idx = (i-1) * period * Fs + 1;
end_idx = i * period * Fs;
vI(start_idx:end_idx) = amplitudes(i) * sin(2*pi*(t(start_idx:end_idx) - t(start_idx))/period);
end
uI = uI(10:end);
vI = vI(1:length(uI));
cv = complex(uI*100,vI*100);
dt=0.5/24;
dt=dt*3600*24;
cxI=cumsum(cv)*dt;
cxI=cxI/100/1000;
x = real(cxI + complex(cumsum(repmat(0.1,1191,1)),0)' );
y = imag(cxI + complex(cumsum(repmat(0.1,1191,1)),0)' );
clearvars -except x y;
plot(x,y),axis equal;
% for the first circle detected
pgonAll = polyshape(x(1:48),y(1:48),'Simplify',false);
pgonAll = simplify(pgonAll);
pgonEach = regions(pgonAll);
figure
plot(x(1:48),y(1:48))
hold on
plot(pgonEach(3))
0 Comments
Accepted Answer
Matt J
on 28 May 2024
Edited: Matt J
on 28 May 2024
load data
ymin=min(y);
[xx,yy]=deal(x,y);
xx(end+1)=x(end); yy(end+1)=ymin;
p=regions(polyshape(xx,yy));
h=arrayfun(@(P)min(P.Vertices(:,2)), p );
p=p(h>0.001+ymin);
Areas=area(p)'
plot(x,y); hold on
plot(p,'FaceColor','r'); hold off
axis([50,100,-5,5]); daspect([1,1,1])
0 Comments
More Answers (0)
See Also
Categories
Find more on Time Series Events in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!