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?

조회 수: 9 (최근 30일)
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
Matt J
Matt J 2023년 5월 31일
편집: Matt J 2023년 5월 31일
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
Matt J 2023년 5월 31일
See slice.

추가 답변 (1개)

Matt J
Matt J 2023년 5월 31일
편집: Matt J 2023년 5월 31일
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
Matt J
Matt J 2023년 5월 31일
편집: Matt J 2023년 5월 31일
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
Biplob 2023년 6월 1일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by