What are the obs values in this spherical surface equation?

4 Ansichten (letzte 30 Tage)
Farzad Torabi
Farzad Torabi am 12 Nov. 2022
Bearbeitet: John D'Errico am 12 Nov. 2022
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;
axis equal;

Akzeptierte Antwort

Karim am 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
% enable the hold function to plot multiple opjects
hold on
% plot the sphere points, make the surface 50% transparant
% plot the center of the sphere (in red)
axis equal
grid on
  1 Kommentar
John D'Errico
John D'Errico am 12 Nov. 2022
Bearbeitet: John D'Errico am 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);
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.
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.)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 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.




Community Treasure Hunt

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

Start Hunting!

Translated by