How to calculate angle between two vectors? (2024)

22visualizaciones (últimos 30días)

Mostrar comentarios más antiguos

Ors el 7 de Ag. de 2022

  • Enlazar

    Enlace directo a esta pregunta

    https://la.mathworks.com/matlabcentral/answers/1775230-how-to-calculate-angle-between-two-vectors

  • Enlazar

    Enlace directo a esta pregunta

    https://la.mathworks.com/matlabcentral/answers/1775230-how-to-calculate-angle-between-two-vectors

Comentada: Ors el 10 de Ag. de 2022

Respuesta aceptada: William Rose

  • Screenshot_20220807_013216.png

Abrir en MATLAB Online

The attached plot is as you can see an array of points in 3D. The lines link points from the XY plane with points along the Z-axis. They are suppose to be vectors, however when I plot with quiver3 I get a vector facing normal to the XY surface, instead of what I would like it pointing towards the points toward the Z-axis, if that makes sense.

Below you can see a part of the code:

total_p=200;

for i = 1 : nout

for j = 1 : pout

if i == 1

ko = nr1;

r = r1;

elseif i == 2

ko = nr2;

r = r2;

elseif i == 3

ko = nr3;

r = r3;

elseif i == 4

ko = nr4;

r = r4;

end

teta = 2*pi()/ko;

for k = 1 : ko

F{j,i}(k,1) = r*cos(k*teta);

F{j,i}(k,2) = r*sin(k*teta);

F{j,i}(k,3) = 0 - (j-1)*(s+a)*1e3;

for l = 1 : total_p

rout{j,i}(l,1)=sqrt(((F{j,i}(k,1)-calc_area(l,1))^2)+((F{j,i}(k,2)-calc_area(l,2))^2)+((F{j,i}(k,3)-calc_area(l,3))^2));

%teta2{j,i}(l,1)= rad2deg(atan(rout{j,i}(l,1)/0.1));

end

figure(1)

scatter3(F{j,i}(k,1),F{j,i}(k,2),F{j,i}(k,3),'k.')

hold on

daspect([1,1,1])

end

clear r ko teta1

end

end

In the end I wish to calculate the magnitude of vectors between points of F and and calc_area.

where calc_area has points x,y=0 and z=5 to 100; I attempted to calculate the magnitude and saved it in rout cell. Then I have teta2, where I am calculating the angle, however it yields around 90 degrees. For the red line this should be very small... and for the blue line around 30 degrees from visual inspection. What am I doing wrong here?

Thank you for any help.

1 comentario

Mostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

William Rose el 7 de Ag. de 2022

Enlace directo a este comentario

https://la.mathworks.com/matlabcentral/answers/1775230-how-to-calculate-angle-between-two-vectors#comment_2304830

  • Enlazar

    Enlace directo a este comentario

    https://la.mathworks.com/matlabcentral/answers/1775230-how-to-calculate-angle-between-two-vectors#comment_2304830

@Ors, quiver3() automatically scales the lengths of the vectors it draws it an attempt to prevent vectors from overlapping. Turn off the automatic scalling by adding option 'off':

quiver3(X,Y,Z,U,V,W,'off')

where "The vectors X, Y, and Z represent the location of the base of each arrow, and U, V, and W represent the directional components of each arrow. By default, the quiver3 function shortens the arrows so they do not overlap. Call axis equal to use equal data unit lengths along each axis. This makes the arrows point in the correct direction.". quiver3 help

The angle you appear to seek is θ, the complement of the angle between the vector r and the z-axis. Compute this by calculating the dot product of the vector r with How to calculate angle between two vectors? (3).

Recall that How to calculate angle between two vectors? (4), where ϕ is the angle between r and How to calculate angle between two vectors? (5).

Then How to calculate angle between two vectors? (6) (since How to calculate angle between two vectors? (7)).

Finally, How to calculate angle between two vectors? (8).

Iniciar sesión para comentar.

Iniciar sesión para responder a esta pregunta.

Respuesta aceptada

William Rose el 7 de Ag. de 2022

  • Enlazar

    Enlace directo a esta respuesta

    https://la.mathworks.com/matlabcentral/answers/1775230-how-to-calculate-angle-between-two-vectors#answer_1022330

  • Enlazar

    Enlace directo a esta respuesta

    https://la.mathworks.com/matlabcentral/answers/1775230-how-to-calculate-angle-between-two-vectors#answer_1022330

Abrir en MATLAB Online

@Ors, My comment above was intended to be an answer. Please accept this answer if it is satisfactory. Here is some code.

F=[-20,200,0;100,-100,0;-200,20,0]; %points in X-Y plane

calc_area=[0,0,5;0,0,50;0,0,100]; %points on z-axis

r=calc_area-F; %vectors

plot3(calc_area(:,1),calc_area(:,2),calc_area(:,3),'r.') %plot red points on z-axis

hold on; grid on; axis equal; %plot details

xlabel('X'),ylabel('Y');zlabel('Z') %axis labels

plot3(F(:,1),F(:,2),F(:,3),'k.'); %plot black points in the X-Y plane

xlim([-250,250]); ylim([-250,250]); zlim([0 150]) %set axis limits

X=F(:,1); Y=F(:,2); Z=F(:,3); %starting points for arrows

U=r(:,1); V=r(:,2); W=r(:,3); %arrow lengths in each dimension

quiver3(X,Y,Z,U,V,W,'off') %draw arrows on the plot

How to calculate angle between two vectors? (10)

When you run the code, you will be able to rotate the 3D plot, by clicking onthe 3-D rotation icon above the plot, then clicking and dragging within the plot area.

Compute the angles of the vectors above the X-Y plane:

for i=1:3

phiDeg(i)=acosd(dot(r(i,:),[0,0,1])/norm(r(i,:)));

end

thetaDeg=90-phiDeg

thetaDeg = 1×3

1.4250 19.4712 26.4512

The code for the angles implements the equations I gave in my comment above. I used acosd() to get the angle phi, in degrees.

Good luck.

5 comentarios

Mostrar 3 comentarios más antiguosOcultar 3 comentarios más antiguos

Ors el 7 de Ag. de 2022

Enlace directo a este comentario

https://la.mathworks.com/matlabcentral/answers/1775230-how-to-calculate-angle-between-two-vectors#comment_2305055

  • Enlazar

    Enlace directo a este comentario

    https://la.mathworks.com/matlabcentral/answers/1775230-how-to-calculate-angle-between-two-vectors#comment_2305055

Editada: Ors el 7 de Ag. de 2022

Thank you so much William! :D

Although both, your comment and answer are more than satisfactory I am curious

why my method did not work. This is not urgent though, however I would really appreciate it.

William Rose el 7 de Ag. de 2022

Enlace directo a este comentario

https://la.mathworks.com/matlabcentral/answers/1775230-how-to-calculate-angle-between-two-vectors#comment_2305300

  • Enlazar

    Enlace directo a este comentario

    https://la.mathworks.com/matlabcentral/answers/1775230-how-to-calculate-angle-between-two-vectors#comment_2305300

Abrir en MATLAB Online

@Ors,

In your code fragment, I do not see where you try to calculate the angles between the vectors from F to calc_area and the normal to the X-Y plane. Therefore I cannot comment on why your method did not work.

In my script, the angles between the vectors from F to calc_area is called "theta()". Your "teta" is not analagous to my "theta". Your teta is an angle in the x-y plane, which is used as a multiplier to compute the x-y coordinates of the points F, as seen belwow in this fragment from the code you posted:

teta = 2*pi()/ko;

for k = 1 : ko

F{j,i}(k,1) = r*cos(k*teta);

F{j,i}(k,2) = r*sin(k*teta);

F{j,i}(k,3) = 0 - (j-1)*(s+a)*1e3;

%...

end

The code above creates a set of ko points F{}() which are spaced at angle How to calculate angle between two vectors? (13) in the X-Y plane.

Ors el 7 de Ag. de 2022

Enlace directo a este comentario

https://la.mathworks.com/matlabcentral/answers/1775230-how-to-calculate-angle-between-two-vectors#comment_2305455

  • Enlazar

    Enlace directo a este comentario

    https://la.mathworks.com/matlabcentral/answers/1775230-how-to-calculate-angle-between-two-vectors#comment_2305455

yes, sorry... its commented out and is teta2

should have mentioned that :)

William Rose el 7 de Ag. de 2022

Enlace directo a este comentario

https://la.mathworks.com/matlabcentral/answers/1775230-how-to-calculate-angle-between-two-vectors#comment_2305470

  • Enlazar

    Enlace directo a este comentario

    https://la.mathworks.com/matlabcentral/answers/1775230-how-to-calculate-angle-between-two-vectors#comment_2305470

@Ors,

YOu have

teta2{j,i}(l,1)= rad2deg(atan(rout{j,i}(l,1)/0.1));

It apears that rout is the length of a 3D vector from a point F to a point calc_area.

You could simplify the equation to

teta2=rad2deg(atan(num/den));

This will work IF num=length of the projection of the vector onto the x-y plane, and if den=length of the projection of the vector onto the z axis. Neither of those conditions appear to be true. That is why this method does not give the correct answer.

Ors el 10 de Ag. de 2022

Enlace directo a este comentario

https://la.mathworks.com/matlabcentral/answers/1775230-how-to-calculate-angle-between-two-vectors#comment_2309910

  • Enlazar

    Enlace directo a este comentario

    https://la.mathworks.com/matlabcentral/answers/1775230-how-to-calculate-angle-between-two-vectors#comment_2309910

I see, thank you William :D

Iniciar sesión para comentar.

Más respuestas (0)

Iniciar sesión para responder a esta pregunta.

Ver también

Categorías

MATLABGraphics2-D and 3-D PlotsGeographic Plots

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

Etiquetas

  • vectors
  • angle
  • magnitude
  • 3d

Productos

  • MATLAB

Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Se ha producido un error

No se puede completar la acción debido a los cambios realizados en la página. Vuelva a cargar la página para ver el estado actualizado.


Translated by How to calculate angle between two vectors? (17)

How to calculate angle between two vectors? (18)

Seleccione un país/idioma

Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .

También puede seleccionar uno de estos países/idiomas:

América

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europa

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia-Pacífico

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Comuníquese con su oficina local

How to calculate angle between two vectors? (2024)

FAQs

How to calculate angle between two vectors? ›

The angle between vectors formula for two vectors a and b is θ = cos-1 [ (a. b) / (|a| |b|) ]. If the two vectors are equal, then substitute b = a in this formula, then we get θ = cos-1 [ (a. a) / (|a| |a|) ] = cos-1 (|a|2/|a|2) = cos-11 = 0°.

How to get angle between two vectors calculator? ›

To calculate the angle between two vectors in a 2D space: Mathematically, angle α between two vectors [xa, ya] and [xb, yb] can be written as: α = arccos[(xa xb + ya yb) / (√(xa² + ya²) × √(xb² + yb²))].

What is the angle between the vectors 2,5,7 and 3,2,3? ›

Question: Question 1 (1 point)What is the angle between the vectorsvec(v)=(:2,5,7:) and vec(w)=(:3,2,-3:)? The angle is between 90 and 180 degrees. They are perpendicular (90 degrees).

What is the formula for the acute angle between two vectors? ›

In case the angle between the vector →a and →b is acute cosθ>0, where θ is the angle between vectors →a and →b. So, we have →a. →b=|→a||→b|cosθ>0.

How to find the angle of a resultant vector? ›

The direction of a two-dimensional resultant vector, i.e., the angle of the resultant vector with the positive x-axis, can be found by taking the inverse tangent of the slope of the resultant: θ = t a n − 1 ( y x ) when the x-component of the resultant is positive, or θ = t a n − 1 ( y x ) ± 180 ∘ when the x-component ...

What should be the angle between two equal vectors? ›

Complete answer:

Both the vectors have the same magnitude. Let the resultant have magnitude equal to vector A. Hence, the angle between the two vectors is 120°.

What is the angle when two vectors are parallel? ›

Two vectors are said to be parallel if and only if the angle between them is 0 degrees. Parallel vectors are also known as collinear vectors. i.e., two parallel vectors will be always parallel to the same line but they can be either in the same direction or in the exact opposite direction.

How do you find the angle between two equations? ›

Formulas For Angle Between Two Lines

If one of the lines of the angle between two lines is ax + by + c = 0 and the other line is the x-axis, then θ= Tan-1(a/b). If one of the lines of the angle between two lines is y= mx + c and the other lime is the x-axis, then θ= Tan-1 m.

How to find the angle between three vectors? ›

If the vetors are linearly independent there is not a single angle between three vector but separate angles between each pair of the vectors. The cosine of the angle can be obtained from the dot product of each pair of vectors divided by the product of the norms of the vectors in each pair.

How to calculate angle between two coordinates? ›

The angle between two lines, of which, one of the line is ax + by + c = 0, and the other line is the x-axis, is θ = tan-1(-a/b). The angle between two lines, of which one of the line is y = mx + c and the other line is the x-axis, is θ = tan-1m.

What is the angle between two vectors planes? ›

The angle between two planes is equal to the angle between the normal vectors to the two planes and is called the dihedral angle.

How to find the angle between two vectors? ›

The angle (θ) between two vectors a and b is found with the formula θ = cos-1 [ (a. b) / (|a| |b|) ].

What is the angle between two vectors is 180? ›

Two unit vectors A and B having an angle ß have a dot product = —1. We are required to find the angle between the two vectors A and B. => ß = arc cos (—1) = 180°. When the dot product of two unit vectors is —1, the two vectors are antiparallel to each other ie the angle between them is 180°.

How to find the resultant of two vectors? ›

The formula for finding the resultant vector when vectors are inclined to each other is: R 2 =A 2 +B 2 +2AB×cosØ, where A and B are the magnitudes and Ø is the angle between the vectors.

What is the angle between axb and bxa? ›

(b) (A×B)and(B×A) are parallel and opposite to each other . So the angle will be π.

What is the formula for angle between two lines? ›

The angle between two lines whose slopes are m1 and m2 is given by the formula tan-1|(m1 - m2)/(1 + m1 m2)|.

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Margart Wisoky

Last Updated:

Views: 5872

Rating: 4.8 / 5 (58 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Margart Wisoky

Birthday: 1993-05-13

Address: 2113 Abernathy Knoll, New Tamerafurt, CT 66893-2169

Phone: +25815234346805

Job: Central Developer

Hobby: Machining, Pottery, Rafting, Cosplaying, Jogging, Taekwondo, Scouting

Introduction: My name is Margart Wisoky, I am a gorgeous, shiny, successful, beautiful, adventurous, excited, pleasant person who loves writing and wants to share my knowledge and understanding with you.