# how to find cosine angle known the end points of 2 linesegments

1 visualización (últimos 30 días)
krishnasri el 28 de Abr. de 2015
Comentada: krishnasri el 5 de Mayo de 2015
There are 2 line segments, known their end points, how can i find angle between them
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Guillaume el 29 de Abr. de 2015
Note: you calculate the dot product of two vectors with dot and the norm with norm.

Iniciar sesión para comentar.

Guillaume el 29 de Abr. de 2015
The arguments you pass to dot and norm must be vectors not scalars
v1 = [1 1]
v2 = [0 3]
D = [v1;v2]; %possibly you have something like this
costheta = dot(D(1, :), D(2, :)) / (norm(D(1, :)) * norm(D(2, :)));
thetaindegrees = acosd(costheta)
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Más respuestas (1)

Roger Stafford el 29 de Abr. de 2015
Editada: Roger Stafford el 29 de Abr. de 2015
Using 'atan2' or 'atan2d' and cross product is more accurate for angles that are near zero or near pi (180 degrees.)
a = atan2(norm(cross(D1,D2)),dot(D1,D2)); % Angle in radians
or
a = atan2d(norm(cross(D1,D2)),dot(D1,D2)); % Angle in degrees
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
krishnasri el 5 de Mayo de 2015
I've around 60 such values in excel sheet and I need to calculate angle between all these points. How can I put the same in a loop for calculating it for 60 values?
for i=1:60
CosTheta = dot(D(i,:),D(i+1,:))/(norm(D(i,:))*norm(D(i+1,:)));
ThetaInDegrees = acosd(CosTheta);
end
xslwrite('result',ThetaInDegrees);
but there is some error in the values. can u please help me

Iniciar sesión para comentar.

### Categorías

Más información sobre Particle & Nuclear Physics 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