How to plot Vector in 3d using two angles and initial point
32 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Aknur
el 13 de Dic. de 2022
Comentada: Aknur
el 22 de Dic. de 2022
Hi! Could you please help me
How to put 3d vector if i know initial point coordinates and two angles
I tries this one, but still could not understand where is my phi and theta on 3d according to matlab plotting
x0=1.5; %initial x position
y0=1.5; %initial y position
z0=3.0;
r = sqrt(x0^2 + y0^2 + z0^2);
x1 = r * sin(Phi0) * cos(Theta0);
y1 = r * sin(Phi0) * sin(Theta0);
z1 = r * cos(Phi0);
line([x0 x1],[y0,y1],[z0,z1]);
xlabel X; ylabel Y; zlabel Z
grid on;
axis equal
%I also have tried this one
%x1 =r * sind(theta) * cosd(phi); % !!!convert to cart mine last one
%y1 = r* sind(theta) * sind(phi);
%z1 = r* cosd(theta);
Here his how my angles should be
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1229182/image.png)
0 comentarios
Respuesta aceptada
Askic V
el 13 de Dic. de 2022
Editada: Askic V
el 13 de Dic. de 2022
I must admit something is confusing me in your post.
If you have a point in 3D space and the second point is in origin, then you have all you need to represent a vector (two points are enough to determine its length and direction). So you can plot it just by using these two points (quiver3)
On the other hand, if you have az and el angles measured exactly the same way you posted on the picture then, you can calculate a vector axis components in the following way (assuming vector starts in origin and ends in points marked with star, with length of r).
The vector has there parts vx*i + vy*j + vz*k, where i, j and k are unit axis vectors.From your picture it is clear that projection to the xy plane is: r*sin(theta), because, prjection to the z axis is r*cos(theta).
In the xy plane, the x (i) component is r*sin(theta)*sin(phi), and y component is r*sin(theta)*cos(phi).
To me, much sense has to find a components of a vector given vector length and these two angles, for example:
[vx,vy,vz] = find_vector(2, pi/6, pi/30)
function [vx,vy,vz] = find_vector(vec_length, azim, el)
phi = azim;
theta = el;
r = vec_length;
vx = r * sin(phi) * sin(theta);
vy = r * cos(phi) * sin(theta);
vz = r * cos(theta);
quiver3(0,0,0,vx,vy,vz,'off');
view(45,20)
end
6 comentarios
Más respuestas (1)
Walter Roberson
el 13 de Dic. de 2022
You have initial coordinates, and you calculate radius based on those coordinates. That is equivalent to saying that the initial point is on the surface of the sphere around the origin.
Then you calculate coordinates based on that radius and two angles. That is like asking "what point at the same radius as the initial point, is at this particular angle on that implied sphere?"
That is a valid thing to calculate, but is that what you want to calculate?
I suspect that what you are looking for is to find a vector at a particular spatial angle, that goes through the given point, and to sketch a segment of that vector,
Ver también
Categorías
Más información sobre Assembly 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!