# How to plot a function on a user defined plane when using spherical coordinate system by specifying elevation and azimuth values at a given radial distance?

10 views (last 30 days)
Biplob on 31 May 2023
Commented: Biplob on 1 Jun 2023
Hi,
I want to plot a surface plot on plane defined by, (say: theta = 45 degree, phi = 25 degree, radial distance = 1 m).
Suppose I am using mesh grid to define X,Y,Z cordinates for a cartesian coordinate system.
Currently if I want to plot my function (f) on x-y plane at z = 10, I can use surf(x, y, f(:, :, 100))
Then by using coordinate transformation I define r,theta, and phi.
How do I plot the surface plot on (theta = 45 degree, phi = 25 degree, r = 1 m)
MATLAB CODE:
x = linspace(0,10,100)
y = linspace(0,10,100)
z = linspace(0,10,100)
[X,Y,Z] = meshgrid(x,y,z); % Defining mesh grid
r = sqrt(X.^2+Y.^2+Z.^2); % Define r vector
tht = acos(Z./r); % Define theta
phi = atan(y./x); % Define phi
Thank You.
Biplob Biswas
PhD Research Scholar
Matt J on 31 May 2023
Edited: Matt J on 31 May 2023
How do I plot the surface plot on (theta = 45 degree, phi = 25 degree, r = 1 m)
The three spherical coordinates theta, phi, and r are not enough to specify a grid of sample points in an oblique plane. You must also define coordinate axes vectors b1 and b2 within the plane.

Matt J on 31 May 2023
See slice.
Biplob on 31 May 2023
Thanks Matt.

Matt J on 31 May 2023
Edited: Matt J on 31 May 2023
The three spherical coordinates theta, phi, and r are not enough to define the sampling of a plane. You must also define coordinate axes vectors b1 and b2 within the plane.
And one way of doing so is by using this FEX download,
with particular attention to the Examples section Post-Sampling a Plane Fit.
[x0,y0,z0] = sph2cart(theta,phi,r);
plane = planarFit.groundtruth([],[x0,y0,z0],r);
b0=[1,0,0];
b1=cross([0,1,0],plane.normal); %Make one sampling direction parallel to x-z plane
b2=[]; %Make the other direction orthogonal to b1
t=linspace(___);
xyz=plane.sample(b0,b1,b2,2*t,t); %grid points in the plane
and then evaluate your function at those points.
F=arrayfun(f,xyz{:}); %function samples in plane
Matt J on 31 May 2023
Edited: Matt J on 31 May 2023
I do not remember the thread you extracted this from, and you haven't referenced a link to it. However, my impression is that A,B,C are three points lying in a plane of interest. Note that 3 points are needed to specify a plane. From these 3 points, the code determines the equation for the plane, which is of the form,
n1*x+n2*y+n3*z=P
Here [n1,n2,n3] is the normal to the plane. From the plane's equation, you can then solve for z as a function of x and y, provided that n3~=0:
z=(P-(n1*x+n2*y))/n3
Biplob on 1 Jun 2023
Thanks Matt. I understood your point.
Also I have successfully used the slice function mentioned by you to plot my function on a desired plane.
Thank a lot for you help.
Biplob.