Why isn't my line visible on this graph?

1 visualización (últimos 30 días)
lmhall
lmhall el 14 de Nov. de 2017
Respondida: Edgar Guevara el 14 de Dic. de 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

Respuestas (1)

Edgar Guevara
Edgar Guevara el 14 de Dic. de 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

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by