Why isn't my line visible on this graph?

1 view (last 30 days)
lmhall
lmhall on 14 Nov 2017
Answered: Edgar Guevara on 14 Dec 2017
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

Answers (1)

Edgar Guevara
Edgar Guevara on 14 Dec 2017
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

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!