フィルターのクリア

Trouble Understanding Code for a Hemisphere

1 回表示 (過去 30 日間)
Jonathan Bird
Jonathan Bird 2018 年 4 月 22 日
コメント済み: Walter Roberson 2018 年 4 月 22 日
I have used the following code to create a hemisphere with radius 10. Unfortunately I don't really understand what the code does, so if someone could explain this that would be great. Please try to be as detailed as possible, thanks.
figure (1)
[x,y,z]=sphere;
x=x(11:end,:);
y=y(11:end,:);
z=z(11:end,:);
r=10;
hemisphere=surf(r.*x,r.*y,r.*z);
axis equal

採用された回答

Walter Roberson
Walter Roberson 2018 年 4 月 22 日
"sphere generates a sphere consisting of 20-by-20 faces."
so accessing the coordinates from 11 onwards would be only half of a sphere.
"The sphere function generates the x-, y-, and z-coordinates of a unit sphere for use with surf and mesh."
If you multiply coordinates based on the unit sphere by the radius of the sphere, then you get a sphere of that radius.
Then you draw the surface. After that you tell MATLAB that you want the x, y, and z axes to be the same spacing as each other (the default is to stretch the data to whatever the current size of the axes is.)
  3 件のコメント
Jonathan Bird
Jonathan Bird 2018 年 4 月 22 日
Please could you explain what ",:"means in "11:end,:" ?
Walter Roberson
Walter Roberson 2018 年 4 月 22 日
: by itself means the same as 1:end which in turn means the same as 1 : size(TheArray,AppropriateDimensionNumber) .
In short, : by itself in that context means "all columns"

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by