Re: find angle
- From: "Roger Stafford" <ellieandrogerxyzzy@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 4 Mar 2008 19:56:01 +0000 (UTC)
Pierre Nouvellet <pierrenouvellet@xxxxxxxxxxx> wrote in message
<d673120a-7aab-4eed-9fca-92647d760f01@xxxxxxxxxxxxxxxxxxxxxxxxxx
om>...
Hi,-------
This might sound very stupid question:
i have an object (and its coordinate) travelling from point A to B and
then from B to C
the direction between the line AB is different from the one of BC
I would like to determine the angle, alpha, between ABC
I also would like it to be positive if clockwise, and negative if anti-
clockwise
So far i use a generalised pythagore theorem:
||AC||^2=||AB||^2 + ||BC||^2 - 2* ||AB|| * ||BC|| * cos (alpha)
and after it get messy for the angle...
Any suggestion to calculate the angle? (other than this formulae
above...)
any function in matlab for the sign of the angle?
Cheers...
Pierre
If your points are in three-dimensional space, the concept of "clockwise"
and "anti-clockwise" would have no significance, so I'll assume your points
are two-dimensional. I assume you want the magnitude of alpha to be the
interior angle in triangle ABC at point B, and further that it is to be considered
positive if traveling from A to B to C is a clockwise direction around triangle
ABC and that alpha is to be negative otherwise.
Consider that points A, B, and C are represented by three two-element
column vectors, A, B, C, containing their respective x-y coordinate locations.
The angle in radians you request can be obtained with the single line:
alpha = atan2(det([A-B,C-B]),dot(A-B,C-B));
To get alpha in degrees, multiply by 180/pi. (If A,B,C are row vectors, then
det([A-B;C-B]) would be used here.)
In the three-dimensional case, det([A-B,C-B]) is replaced by norm(cross(A-
B,C-B)) and alpha would then always be the positive interior angle.
Roger Stafford
.
- References:
- find angle
- From: Pierre Nouvellet
- find angle
- Prev by Date: Re: file name string specification
- Next by Date: Re: plot pdf function
- Previous by thread: Re: find angle
- Next by thread: Re: How to display text & variables in one line of output
- Index(es):
Relevant Pages
|