3d surface plotting of spherical coordinates which i have in csv

조회 수: 7 (최근 30일)
Sri Ram
Sri Ram 2022년 5월 15일
답변: Star Strider 2022년 5월 15일
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

답변 (1개)

Star Strider
Star Strider 2022년 5월 15일
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'})
T1 = 11×3 table
rho theta phi ___ _______ _______ 20 0 0 30 0.17453 0 5 0.34907 0 39 0.5236 0 52 1.0472 0 40 2.4435 0 20 3.4383 0 20 3.4907 0.17453 97 5.236 0.17453 39 3.6826 0.17453 60 3.0194 0.17453
[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;
.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by