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 Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by