Angle between 2 lines
Mostrar comentarios más antiguos
How can i calculate the angle between such two lines.is the dotvector method useful in such case?
line([50 50],[1 10000],'Color','G');
line([newBoxPolygon(1, 1) newBoxPolygon(4, 1)],[newBoxPolygon(1, 2) newBoxPolygon(4, 2)],'Color','G');
i tried this method
u=[newBoxPolygon(1, 1) newBoxPolygon(4, 1),newBoxPolygon(1, 2) newBoxPolygon(4, 2)]
v=[[50 50],[1 10000]]
CosTheta = dot(u,v)/(norm(u)*norm(v));
ThetaInDegrees = acos(CosTheta)*180/pi
but i'm getting an error can you please help
2 comentarios
Jos (10584)
el 19 de Feb. de 2014
What is the exact error you're getting?
Elie
el 19 de Feb. de 2014
Respuestas (1)
Jos (10584)
el 19 de Feb. de 2014
Editada: Jos (10584)
el 19 de Feb. de 2014
You want to enter the direction vectors U and V into the formula
dU = [diffUx diffUy]
dV = [diffVx diffVy]
cosTheta = dot(dU,dV) ./ (norm(dU) * norm(dV))
4 comentarios
Elie
el 19 de Feb. de 2014
Jos (10584)
el 19 de Feb. de 2014
I should have made this more clear.
Your original U is a matrix specifying two points (X1,Y1) and (X2,Y2). These points specify a line for which you need to know the direction vector (dU). dU can be calculated by taking the difference between the X-coordinates of the two points (diffUx) and the difference between the Y-coordinates (diffUy). So,
dU = [(X2-X1) (Y2-Y1)]
Elie
el 21 de Feb. de 2014
Jos (10584)
el 24 de Feb. de 2014
You are setting up the vectors the wrong way: the direction vectors dU and dV should be 2 element arrays. dU is, but dV is not.
If you remove the semi-colons you see what I mean.
Categorías
Más información sobre Author Block Masks en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!