3d surface plotting of spherical coordinates which i have in csv
7 views (last 30 days)
Show older comments
My csv file have columns (rho,theta,phi) in spherical coordinates (in degrees)
rho theta phi
20 0 0
30 10 0
5 20 0
39 30 0
52 60 0
40 140 0
20 197 0
20 200 10
97 300 10
39 211 10
60 173 10
.... ..... ....
and so on rho (in range of 1 to 1200), theta(in range of 0 to 360 deg), phi(in range of 0 to 90 deg). Like this i have around 5000 spherical coordinate points which are the points of a closed surface like a cylinder, or a cuboid. Now I want to plot these surfaces with coordinates i have.
To read the csv file and converting degrees to radians:
%m = csvread('test.csv');
%rho = m(:,1)';
%theta = (m(:,2)*0.01745329)';
%phi = (m(:,3)*0.01745329)';
Now it will look like
rho=[20 30 5 30 52 40 20 20 57 97 39 60 ....]
theta =[0 10 20 30 60 140 197 200 300 211 173 ....]
phi = [0 0 0 0 0 0 0 10 10 10 10 ....]
rho=[20 30 5 30 52 40 20 20 57 97 39 60];
theta =[0 10 20 30 60 140 197 200 300 211 173 123];
phi = [0 0 0 0 0 0 0 10 10 10 10 10];
Converting shperical coordinates to cartesian coordinates:
[x,y,z] = sph2cart(theta,phi,rho);
Plotting:
xq = linspace(min(x), max (x));
yq = linspace(min(y), max (y));
[X,Y] = meshgrid(xq,yq);
Z = griddata(x,y,z, X, Y);
figure;
mesh(X,Y,Z);
xlabel('x-axis');
ylabel('y-axis');
zlabel('z-axis');
grid on;
box on;
I want an output like this (not exactly same, similar to it)
But I am getting this for 5000 coordinates i have in my csvfile. I am using malab R2015a
0 Comments
Answers (1)
Star Strider
on 15 May 2022
Apparently, the angles sent to sph2cart were in degres, not radians.
Try this with the complete file —
M = [20 0 0
30 10 0
5 20 0
39 30 0
52 60 0
40 140 0
20 197 0
20 200 10
97 300 10
39 211 10
60 173 10];
M(:,[2 3]) = deg2rad(M(:,[2 3]));
T1 = array2table(M, 'VariableNames',{'rho','theta','phi'})
[x,y,z] = sph2cart(T1.theta,T1.phi,T1.rho);
xq = linspace(min(x), max (x));
yq = linspace(min(y), max (y));
[X,Y] = meshgrid(xq,yq);
Z = griddata(x,y,z, X, Y);
figure;
mesh(X,Y,Z);
xlabel('x-axis');
ylabel('y-axis');
zlabel('z-axis');
grid on;
box on;
.
0 Comments
See Also
Categories
Find more on Annotations 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!