필터 지우기
필터 지우기

plotting a spherical segment

조회 수: 46 (최근 30일)
Gilles
Gilles 2016년 11월 24일
편집: isku 2020년 7월 24일
Hi, I need to plot a spherical segment (blue region of the sphere in the attached picture).
Do you have any suggestions?
Gilles

채택된 답변

KSSV
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 ;

추가 답변 (1개)

isku
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])
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

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by