Why isn't my line visible on this graph?

조회 수: 1 (최근 30일)
lmhall
lmhall 2017년 11월 14일
답변: Edgar Guevara 2017년 12월 14일
function main
t = 0:0.5:2*pi;
p = 0:0.5:pi;
[T,P] = meshgrid(t,p);
sphr(1,0,0,0)
hold on
circ(2,0,0)
hold off
function s = sphr(r,a,b,c)
x = r.*cos(T).*sin(P)+a;
y = r.*sin(T).*sin(P)+b;
z = r.*cos(P)+c;
surf(x,y,z)
end
function c = circ(r,a,b)
x = r.*cos(T)+a;
y = r.*sin(T)+b;
line(x,y);
end
end

답변 (1개)

Edgar Guevara
Edgar Guevara 2017년 12월 14일
Hi lmhall,
The circle should be defined as a function of a vector (small t), not the 2-Dgrid (capital T), so, pleace replace the following lines in your code:
x = r.*cos(T)+a;
y = r.*sin(T)+b;
with:
x = r.*cos(t)+a;
y = r.*sin(t)+b;
and you'll see the line.
Hope it helps,
Edgar

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by