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?

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

1 Kommentar

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.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Weitere Antworten (1)

Matt J
Matt J am 31 Mai 2023
Bearbeitet: Matt J am 31 Mai 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

4 Kommentare

Thanks Matt.
Understanding this code is a bit tough for me. But I will try to trobleshoot this code.
Using slice may be a easier option.
Let me try. I will revert back to you if I dont understand something.
I have come acorss another answer given by you in some other thread in the forum.
The code is as follows:
MATLAB CODE:
A = [104,122,111];
B = [253,122,153];
C = [104,124,111];
normal=normalize( cross(A-B,A-C),'norm'); %calculate plane parameters
P=dot(A,normal);
load mri %set up some volume data
[X,Y,Z]=meshgrid(1:128,1:128,(1:27)-110);
V = single(squeeze(D));
[x,y]=meshgrid(linspace(1,128,512)); %compute sample locations in plane
z=(normal(1)*x+normal(2)*y-P)./normal(3);
h=slice(X,Y,Z,V,x,y,z,'cubic'); %plot
colormap(gray(256));
h.LineStyle='none';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
In this above code, what do the A,B, and C variable represent? Why are we taking the cross product of A-B and A-C? Does it helps in finding the normal vector? Also why do we need the dot product of A and normal vector? Can you please explain the theoretical background behind it.
Also in the above code; V = single(squeeze(D)); Does it represent the function value? Why do we need to squeeze it?
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
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.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 31 Mai 2023

Kommentiert:

am 1 Jun. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by