This example shows how to plot a point in spherical coordinates and its projection to Cartesian coordinates.
In spherical coordinates, the location of a point can be characterized by three coordinates:
the radial distance
the azimuthal angle
the polar angle
The relationship between the Cartesian coordinates of the point and its spherical coordinates are:
Plot the point using plot3
. You can adjust the location of the point by changing the values of rho
, theta
, and phi
.
rho =0.8; theta =
1.2; phi =
0.75; x = rho*sin(phi)*cos(theta); y = rho*sin(phi)*sin(theta); z = rho*cos(phi); plot3(x,y,z,'ko','MarkerSize',10,'MarkerFaceColor','k') hold on
Plot the line projection of the point onto the -axis and the -plane using fplot3
.
syms r s xr = r*sin(phi)*cos(theta); yr = r*sin(phi)*sin(theta); zr = r*cos(phi); fplot3(xr,yr,zr,[0 rho],'k') fplot3(xr,yr,sym(0),[0 rho],'k') fplot3(xr,yr,sym(z),[0 rho],'k--') fplot3(sym(x),sym(y),rho*sin(s),[0 pi/2-phi],'k')
Plot the planes that show the span of the azimuthal angle and the polar angle .
syms s t xa = rho*sin(s)*cos(t); ya = rho*sin(s)*sin(t); fsurf(xa,ya,0,[0 phi 0 theta],'FaceColor','b','EdgeColor','none') syms u v xp = u*sin(v)*cos(theta); yp = u*sin(v)*sin(theta); zp = u*cos(v); fsurf(xp,yp,zp,[0 rho 0 phi],'FaceColor','g','EdgeColor','none') xlabel('x') ylabel('y') zlabel('z') view(115,30) axis equal; hold off