How to plot direction of forces on a body with polar plots or similar?

I'm simulating the forces acting on a stationary object. I have a data sample of a time series that includes Forces, and the direction where the object experiences the force (sample data set is attached).
load("sampleData.mat");
figure;
subplot(2,1,1); grid minor; hold on
plot(data.time, data.force)
ylabel('[N]'); title('Force')
subplot(2,1,2); grid minor; hold on
plot(data.time, data.forceDirection)
ylabel('[deg]'); title('Force Direction')
Now, I want to visualize the force on a polar plot to see the direction in a rather graphical way. Something similar to the following figure (of course, the directions and values are different than the sample data attached).
I could be wrong to assume that this can be done, but if it is possible, how can I do this?

 Akzeptierte Antwort

I can’t figure out what you’re plotting. The data are vectors, so any sort of surface plot isn’t possible, and I don’t understand the reason that the radius units in the surface plot image are in angular units. Does time enter into this?
load('sampleData.mat')
% whos
t = data.time;
force = data.force;
direction = data.forceDirection;
figure
polarplot(deg2rad(direction), force)
Ax = gca;
Ax.ThetaZeroLocation = 'top';
Ax.ThetaDir = 'clockwise';
When it is obvious what the data are, and if matrix data are available (or could be calculated from the existing vectors), then the sort of surface plot you want would be created by first calculating it as a matrix, using angle and radius units for the (x,y) data, then transforming that to polar (cylindrical) coordinates using pol2cart that will then plot it as Cartesian coordinates, however transformed into a polar coordinate surface. (Polar surface plot functions do not currently exist,m however they can be created easily enough using this approach.)
That would likely go something like this —
a = linspace(0, 2*pi*(1+1/250), 250);
r = linspace(0, 10, 100);
z = exp(-(r-5).^2 / 10);
[A,R] = ndgrid(a,r);
Z = repmat(z, numel(a), 1) .* (sin(a(:)+1));
figure
surfc(A, R, Z, 'EdgeColor','none')
colormap(turbo)
xlabel('a (rad)')
ylabel('r (unit)')
title('Original Matrix (angle and radius)')
[Xp,Yp,Zp] = pol2cart(A,R,Z);
figure
surfc(Xp, Yp, Zp, 'EdgeColor','none')
colormap(turbo)
title('Transformed To Cylindrical Coordinates')
Ax = gca;
% Ax.Visible = 'off';
figure
surfc(Xp, Yp, Zp, 'EdgeColor','none')
colormap(turbo)
axis('equal')
view(0,90)
Ax = gca;
Ax.Visible = 'off';
atix = linspace(0, 360, 13);
xv = 11*cosd(atix);
yv = 11*sind(atix);
text(xv(1:end-1), yv(1:end-1), compose('%5.0f°',atix(1:end-1)), 'Horiz','center', 'Vert','middle')
F = scatteredInterpolant(Xp(:), Yp(:), Zp(:));
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
rt = linspace(0, 10, 6).'; % Radius Tick Labels
rx = rt*cosd(15);
ry = rt*sind(15);
rtix = F(rx(:), ry(:));
text(rx, ry, rtix+0.5, compose('%g',rt), 'Horiz','center', 'Vert','middle')
title('Transformed To Cylindrical Coordinates With Added Tick Values For Angles & Radials (Top View)')
% hold on
% plot3(rx(:), ry(:), rtix, 'sk')
% hold off
This does not emulate the posted plot image, however it would likely be straightforward to adapt it to your data. Add a phase offset value to the angle calculations to change the location of the angle origin, and negate the angles to reverse their direction (anti-clockwise to clockwise).
.

4 Kommentare

@Star Strider "The data are vectors, so any sort of surface plot isn’t possible, and I don’t understand the reason that the radius units in the surface plot image are in angular units. Does time enter into this?"
You're right, the data are from time series, i.e., force and direction vary with time and are results from a time domain simulation. I understand now that the radial units need to be something else other than the angular ones I proposed.
Fowever, a side question I have is that is it possible to have the following polar plot (that you sugegsted) as a surface plot somehow? So, the radial units will be, for example, the force magnitudes?
load('sampleData.mat')
% whos
t = data.time;
force = data.force;
direction = data.forceDirection;
figure
polarplot(deg2rad(direction), force)
Ax = gca;
Ax.ThetaZeroLocation = 'top';
Ax.ThetaDir = 'clockwise';
I wasn't sure about the possiblity of getting a similar plot myself, but thank you so much for explaining the reasons, and giving an alternative approach.
A surface plot requires a matrix for the ‘z’ argument. Your arguments are vectors, and I do not see a way co create a matrix from them. (It might be possible, however I need significantly more information about how to create a matrix from the three vectors provided, or how they might relate to the plot image you posted.) They are not gridded (in that there are no repeating elements in the independent variables that could lend themselves to creating matrices from them), and I do not understand the data to the extent of being able to calculate matrices from the vectors.
load('sampleData.mat')
% whos
t = data.time;
force = data.force;
direction = data.forceDirection;
figure
plot3(direction, force, t)
grid on
zlabel('t')
xlabel('direction')
ylabel('force')
[Xp,Yp,Zp] = pol2cart(direction,force,t); % Angle = 'direction', Radius = 'force', z = 'time'
fmax = max(force);
rv = fmax;
figure
plot3(Xp, Yp, Zp)
grid on
Ax = gca;
Ax.Visible = 'off';
atix = linspace(0, 360, 13);
rvc = rv*1.1;
xv = rvc*cosd(atix);
yv = rvc*sind(atix);
xr = fmax*cosd(atix);
yr = fmax*sind(atix);
hold on
plot3([xr; zeros(size(xv))], [yr; zeros(size(yv))], zeros(2, numel(xv)), '-k')
plot3(rv*cosd(0:360), rv*sind(0:360), zeros(1,361), '-k')
plot3([0 0], [0 0], [min(t) max(t)], '-k')
text(fmax/4, fmax/4, median(t), 'time', 'Rotation',90, 'Vert','middle')
hold off
text(xv(1:end-1), yv(1:end-1), compose('%5.0f°',atix(1:end-1)), 'Horiz','center', 'Vert','middle')
F = scatteredInterpolant(Xp(:), Yp(:), Zp(:));
rt = linspace(0, rv, 6).'; % Radius Tick Labels
rx = rt*cosd(15);
ry = rt*sind(15);
rtix = F(rx(:), ry(:));
text(rx, ry, rtix+0.5, compose('%.1E',rt), 'Horiz','center', 'Vert','middle')
figure
plot3(Xp, Yp, Zp)
grid on
Ax = gca;
Ax.Visible = 'off';
atix = linspace(0, 360, 13);
rvc = rv*1.1;
xv = rvc*cosd(atix);
yv = rvc*sind(atix);
xr = fmax*cosd(atix);
yr = fmax*sind(atix);
hold on
plot3([xr; zeros(size(xv))], [yr; zeros(size(yv))], zeros(2, numel(xv)), '-k')
plot3(fmax*cosd(0:360), fmax*sind(0:360), zeros(1,361), '-k')
hold off
text(xv(1:end-1), yv(1:end-1), compose('%5.0f°',atix(1:end-1)), 'Horiz','center', 'Vert','middle')
F = scatteredInterpolant(Xp(:), Yp(:), Zp(:));
rt = linspace(0, rv, 6).'; % Radius Tick Labels
rx = rt*cosd(15);
ry = rt*sind(15);
rtix = F(rx(:), ry(:));
text(rx, ry, rtix+0.5, compose('%.1E',rt), 'Horiz','center', 'Vert','middle')
axis('equal')
view(0,90)
% title('Transformed To Cylindrical Coordinates With Added Tick Values For Angles & Radials (Top View)')
This does not lend itself to a surface plot. Also, they are still vector quantities, and it is not obvious how to convert them into matrices.
.
@Star Strider I understand. This is a much better explaination than what I had in mind, and this will hopefully be enough for me to go forward.
I will accept this as the answer :) Thank you so much for the patience and the clear explaination.
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Polar Plots finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 10 Mär. 2024

Kommentiert:

am 12 Mär. 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by