plotting a spherical segment
33 ビュー (過去 30 日間)
古いコメントを表示
採用された回答
KSSV
2016 年 11 月 24 日
clc; clear all ;
[X,Y,Z] = sphere(200) ;
surf(X,Y,Z) ;
r = 1; b = 0.9 ; h = 1 ;
%%Get radius
R = sqrt(X.^2+Y.^2) ;
X1 = X ; Y1 = Y ; Z1 = Z ;
X1(Z<r/2) = NaN ; Y1(Z<r/2) = NaN ; Z1(Z<r/2) = NaN ;
X1(Z>b) = NaN ; Y1(Z>b) = NaN ; Z1(Z>b) = NaN ;
surf(X1,Y1,Z1) ;
axis equal
% shading interp ;
0 件のコメント
その他の回答 (1 件)
isku
2020 年 7 月 24 日
編集済み: isku
2020 年 7 月 24 日
My code:
>> clear; syms t x y z real;
r = 1
a = .4*r % 40 pct. of r
b = .6*r % 60 pct. of r
eq = x^2+y^2+z^2 == r^2 % equation of a sphere with center at the origin
% define high by projecting on xz-plane by setting y=0. And then x=0 e,g. the high on z-axe
za = solve( subs( eq, [x^2, y^2,r^2], [0,0, (r^2-a^2)] ), z ) % by Pythagoras, see figure under
za = za(2) % only positive value, upper half of the sphere.
% Similarly
zb = solve( subs( eq, [x^2, y^2,r^2], [0,0, (r^2-b^2)] ), z ) % by Pythagoras
zb = zb(2) % only positive value
h = za - zb
% plotting
>> clear x;
x(t) = sin(t) *r ; % -1<x<1
[X,Y,Z] = sphere;
s = mesh(X,Y,Z, 'edgecolor', 'k', 'FaceAlpha',0.3) ;
hold on
yApos = sqrt( r^2 -x^2-za^2)
yAneg = -yApos
zA(t) = 0*t + za;
fplot3( x, yApos, zA, [-pi, pi], 'red', 'LineWidth', 2 ),
fplot3( x, yAneg, zA, [-pi, pi], 'red', 'LineWidth', 2 )
yBpos = sqrt( r^2 -x^2-zb^2)
yBneg = -yBpos
zB(t) = 0*t+ zb
fplot3( x, yBpos, zB, [-pi, pi], 'red', 'LineWidth', 2 )
fplot3( x, yBneg, zB, [-pi, pi], 'red', 'LineWidth', 2 )
xlabel('x'), ylabel('y'), zlabel('z'), axis equal , grid on
axis( [-1,1, -1,1, -1,1] *r )
campos( [5,5,5])
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/336625/image.gif)
Using Pythagoras to define the hight at given a and b.
The high on z-axe at b:
zb^2 = r^2 - b^2 % b= 0.6*r
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/336646/image.png)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!