hi, i'm making a code that will plot an ellipsoid with the following equations:
x = a * (cos*phi) * (cos * theta); y = b * (cos*phi) * (sin * theta); z = b * (sin*phi);
and i'm supposed to plot it with a = 2, and b = 1, but it doesn't appear to be working.. help anyone?
a = 2;
b = 1;
x = a * (cos*phi) * (cos * theta);
y = b * (cos*phi) * (sin * theta);
z = b * (sin*phi);
[Xm, Ym] = meshgrid(x,y);
surf(x,y,z)

1 comentario

Rik
Rik el 16 de Nov. de 2017
phi and theta don't exist and you are using them as input to cos and sin.

Iniciar sesión para comentar.

 Respuesta aceptada

Akira Agata
Akira Agata el 17 de Nov. de 2017

2 votos

How about using a fsurf function, like:
a = 2;
b = 1;
funx = @(theta,phi) a*cos(theta).*cos(phi);
funy = @(theta,phi) b*cos(theta).*sin(phi);
funz = @(theta,phi) b*sin(theta);
fsurf(funx,funy,funz,[-pi/2 pi/2 -pi pi])

4 comentarios

Mat Ramada
Mat Ramada el 17 de Nov. de 2017
wow, that fixed it! thank you so much!
Ahmed Karoui
Ahmed Karoui el 27 de Mayo de 2019
Hi,
I´m wondering how I can transform (Rotate) this ellipsoid having already a rotation-matrix for example.
How can I execute the Rotation with the Matrice that I have if I defined my ellipsoid using function handles ?
Akira Agata
Akira Agata el 29 de Mayo de 2019
How about using hgtransform ? The following is an example.
a = 2;
b = 1;
funx = @(theta,phi) a*cos(theta).*cos(phi);
funy = @(theta,phi) b*cos(theta).*sin(phi);
funz = @(theta,phi) b*sin(theta);
% Make rotation matrix (e.g Rotate pi/4 [rad] for y-axis)
M = makehgtform('yrotate',pi/4);
figure
h = fsurf(funx,funy,funz,[-pi/2 pi/2 -pi pi]);
daspect([1 1 1])
% Apply the rotation matrix
t = hgtransform('Parent',gca);
t.Matrix = M;
h.Parent = t;
example.png
DOMENICO GIOFFRE
DOMENICO GIOFFRE el 23 de En. de 2021
Hello. I have a 3x3 matrix describing a tilted ellypsoid. How can i plot this? Besides, is there a way to calculate the distance between its center and a point on the surface in the direction of x, y and z axes?
Thank you!
229.435 1.889 -5.708
1.889 207.544 4.372
-5.708 4.372 184.297
how can I rotate it 'back'

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 16 de Nov. de 2017

Comentada:

el 23 de En. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by