What are the obs values in this spherical surface equation?

3 views (last 30 days)
Hi all
I have this code for a spherical surface generation. One thing I do not understand is that I don't get what the obs values do in the equation of the sphere. Then why should we multiply the X by R ? The other question is what is the axis equal ?
obs = [-0.025;-0.55;0.8];
plot3(points(1,:),points(2,:),points(3,:), 'o','Color','r','MarkerSize',5);
[X,Y,Z] = sphere;
R = 0.35;
X = R*X;
Y = R*Y;
Z = R*Z;
surf(X+obs(1),Y+obs(2),Z+obs(3));
axis equal;

Accepted Answer

Karim
Karim on 12 Nov 2022
I added some comments in the code below.
% define the center of the sphere (i.e. the location of the centroid of the sphere)
cog = [-0.025;-0.55;0.8];
% create a set of points, lying on a sphere with unit radius
[X,Y,Z] = sphere;
% define the desired radius of the sphere
R = 0.35;
% scale the points to the desired radius
X = R*X;
Y = R*Y;
Z = R*Z;
% offset the points to the desired center
X = X+cog(1);
Y = Y+cog(2);
Z = Z+cog(3);
% create a new figure
figure
% enable the hold function to plot multiple opjects
hold on
% plot the sphere points, make the surface 50% transparant
surf(X,Y,Z,'FaceAlpha',0.5)
% plot the center of the sphere (in red)
plot3(cog(1),cog(2),cog(3),'o','Color','red','MarkerSize',5,'MarkerFaceColor','red')
axis equal
grid on
view(3)
xlabel('X');ylabel('Y');zlabel('Z')
  1 Comment
John D'Errico
John D'Errico on 12 Nov 2022
Edited: John D'Errico on 12 Nov 2022
You left out the meaning of the axis equal command.
The point of axis equal is if you do not force MATLAB to use the same units on each axis, then for example, a circle can tend to look like an ellipse. For example:
theta = linspace(0,2*pi);
r = 3;
X = r*cos(theta); % without the R, this is just a circle of radius 1.
Y = r*sin(theta);
plot(X,Y)
Do you see that even though we KNOW this is a circle, if MATLAB is not told to make the units the same on both axes, it does not care. It just tries to fill up the rectangular figure window as well as possible. The result looks like an ellipse.
plot(X,Y)
axis equal
axis equal resolves that problem, and the result now looks like a circle.
axis equal applies to 3-d problems also. Had it not been used on the sphere plot, the result would look like an ellipsoid, not a sphere. And so without the axis equal command, then you would have been asking why a true sphere was not plotted. (Believe me, that question has indeed been asked before.)

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 12 Nov 2022
obs is the center of the sphere.
sphere() returns coordinates for a unit sphere. You then scale them by the radius of the sphere, R.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by