Mar 27, 2018 #1 S sadra Newbie Joined Feb 26, 2018 Messages 4 Helped 0 Reputation 0 Reaction score 0 Trophy points 1 Activity points 23 I want to know how to plot for example 1 (unit sphere) in theta=-pi/2 i/2 & phi=0:2×pi Tnx
Mar 28, 2018 #2 W weetabixharry Full Member level 4 Joined Oct 9, 2013 Messages 232 Helped 69 Reputation 142 Reaction score 73 Trophy points 1,318 Location Sweden Activity points 3,462 sadra said: I want to know how to plot for example 1 (unit sphere) in theta=-pi/2 i/2 & phi=0:2×pi Tnx Click to expand... This may sound like a joke, but it really is as simple as this: Code Matlab M - [expand]1 sphere If you click on the code, it will take you to the reference page for Matlab's sphere function.
sadra said: I want to know how to plot for example 1 (unit sphere) in theta=-pi/2 i/2 & phi=0:2×pi Tnx Click to expand... This may sound like a joke, but it really is as simple as this: Code Matlab M - [expand]1 sphere If you click on the code, it will take you to the reference page for Matlab's sphere function.
Mar 30, 2018 #3 W weetabixharry Full Member level 4 Joined Oct 9, 2013 Messages 232 Helped 69 Reputation 142 Reaction score 73 Trophy points 1,318 Location Sweden Activity points 3,462 If that doesn't give the insight you want, then you could write some code at a lower level. For example: Code Matlab M - [expand]1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 close all; clear all; clc; % Numbers of azimuth and elevation points Ntheta = 100; Nphi = 100; % Azimuth and elevation grids theta = linspace(0,2*pi,Ntheta); phi = linspace(-pi/2,pi/2,Nphi); % Compute (x,y,z) coordinates x = zeros(Ntheta,Nphi); y = zeros(Ntheta,Nphi); z = zeros(Ntheta,Nphi); for itheta = 1:Ntheta for iphi = 1:Nphi x(itheta,iphi) = cos(theta(itheta)).*cos(phi(iphi)); y(itheta,iphi) = sin(theta(itheta)).*cos(phi(iphi)); z(itheta,iphi) = sin(phi(iphi)); end end % Plot figure(); grid on; surf(x,y,z); shading interp; axis equal;
If that doesn't give the insight you want, then you could write some code at a lower level. For example: Code Matlab M - [expand]1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 close all; clear all; clc; % Numbers of azimuth and elevation points Ntheta = 100; Nphi = 100; % Azimuth and elevation grids theta = linspace(0,2*pi,Ntheta); phi = linspace(-pi/2,pi/2,Nphi); % Compute (x,y,z) coordinates x = zeros(Ntheta,Nphi); y = zeros(Ntheta,Nphi); z = zeros(Ntheta,Nphi); for itheta = 1:Ntheta for iphi = 1:Nphi x(itheta,iphi) = cos(theta(itheta)).*cos(phi(iphi)); y(itheta,iphi) = sin(theta(itheta)).*cos(phi(iphi)); z(itheta,iphi) = sin(phi(iphi)); end end % Plot figure(); grid on; surf(x,y,z); shading interp; axis equal;