From: Benjamin McCrite on
Greg Heath <heath(a)alumni.brown.edu> wrote in message <1184052626.324470.175540(a)n2g2000hse.googlegroups.com>...
> On Jul 9, 5:16 pm, "y Mehta" <mehtayogesh(a)gmail.(DOT).com> wrote:
> > How do I find the angle between two unit vectors a and b? I know I
> > can find cosine theta by the following formula:
> >
> > theta = acos(dot(a,b));
> >
>
> Invalid since it is possible that abs(dot(a,b)) > 1.
>
> costheta = dot(a,b)/(norm(a)*norm(b));
> theta = acos(costheta);
>
> will give you the anser in the interval [0,pi].
>
> > However, how do I know whether the angle is
> > actually theta, or -theta or pi-theta or pi+theta??
>
> Angles between vectors only lie in the interval [0,pi].
>
> > Notice that the vectors are in three dimension (3d).
>
> Dimensionality of the original space is irrelevant. As long as
> norm(a)*norm(b) > 0, the vectors uniquely define a 2-d space when
> dot(a,b) ~= 0 and a unique 1-d space otherwise.
>
> Hope this helps.
>
> Greg
>


Can you tell me what norm(),cross() and dot() do?
From: Nathan on
On Feb 23, 4:41 pm, "Benjamin McCrite" <dragonmast...(a)hotmail.com>
wrote:
>  Greg Heath <he...(a)alumni.brown.edu> wrote in message <1184052626.324470.175...(a)n2g2000hse.googlegroups.com>...
>
>
>
> > On Jul 9, 5:16 pm, "y Mehta" <mehtayogesh(a)gmail.(DOT).com> wrote:
> > > How do I find the angle between two unit vectors a and b? I know I
> > > can find cosine theta by the following formula:
>
> > > theta = acos(dot(a,b));
>
> > Invalid since it is possible that abs(dot(a,b)) > 1.
>
> > costheta = dot(a,b)/(norm(a)*norm(b));
> > theta = acos(costheta);
>
> > will give you the anser in the interval [0,pi].
>
> > > However, how do I know whether the angle is
> > > actually theta, or -theta or pi-theta or pi+theta??
>
> > Angles between vectors only lie in the interval [0,pi].
>
> > > Notice that the vectors are in three dimension (3d).
>
> > Dimensionality of the original space is irrelevant. As long as
> > norm(a)*norm(b) > 0, the vectors uniquely define a 2-d space when
> > dot(a,b) ~= 0 and a unique 1-d space otherwise.
>
> > Hope this helps.
>
> > Greg
>
> Can you tell me what norm(),cross() and dot() do?

Can you read the documentation?
Norm:
The norm of a matrix is a scalar that gives some measure of the
magnitude of the elements of the matrix. The norm function calculates
several different types of matrix norms:

n = norm(A) returns the largest singular value of A, max(svd(A)).

n = norm(A,p) returns a different kind of norm, depending on the value
of p.
....


Cross:
C = cross(A,B) returns the cross product of the vectors A and B. That
is, C = A x B. A and B must be 3-element vectors. If A and B are
multidimensional arrays, cross returns the cross product of A and B
along the first dimension of length 3.

C = cross(A,B,dim) where A and B are multidimensional arrays, returns
the cross product of A and B in dimension dim. A and B must have the
same size, and both size(A,dim) and size(B,dim) must be 3.
....


Dot:
C = dot(A,B) returns the scalar product of the vectors A and B. A and
B must be vectors of the same length. When A and B are both column
vectors, dot(A,B) is the same as A'*B.

For multidimensional arrays A and B, dot returns the scalar product
along the first non-singleton dimension of A and B. A and B must have
the same size.

C = dot(A,B,dim) returns the scalar product of A and B in the
dimension dim.
....


Before asking what functions do, try to read and understand the
documentation for them. To view the documentation, you can type:
doc FUNCTIONNAME

Where, in this case, FUNCTIONNAME is either cross, dot, or norm

-Nathan
From: Jorian on
"salih tuna" <salihtuna(a)gmail.com> wrote in message <fjlrpl$gii$1(a)fred.mathworks.com>...
> Hi,
> thanks a lot for your reply. yes they are in 2d, sorry i
> forgot to mention.
> i tried to apply the formula but i am getting wrong result.
> for example i want to calculate the angle between a = [1 1]
> and b = [0 -1] which is 225 degrees. with this formulae i
> got 243.4. i couldn't see where i am doing the mistake.
> thanks a lot in advance
> salih
>
> http://www.musicpa.com
> "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid>
> wrote in message <fjk0tg$jli$1(a)fred.mathworks.com>...
> > "salih tuna" <salihtuna(a)gmail.com> wrote in message
> <fjj9nj$fia
> > $1(a)fred.mathworks.com>...
> > > hello,
> > > how can i calculate the angles so that they are in the
> range 0-360 degrees?
> > > thanks
> > > salih
> > >
> > > "y Mehta" <mehtayogesh(a)gmail.(DOT).com> wrote in message
> > > <ef5ce9c.-1(a)webcrossing.raydaftYaTP>...
> > > > How do I find the angle between two unit vectors a and
> b? I know I
> > > > can find cosine theta by the following formula:
> > > >
> > > > theta = acos(dot(a,b));
> > > >
> > > > However, how do I know whether the angle is actually
> theta, or -theta
> > > > or pi-theta or pi+theta??
> > > >
> > > > Notice that the vectors are in three dimension (3d).
> > > >
> > > > Thanks,
> > > > -YM
> > --------
> > Y Mehta's question involved angles between vectors in
> three-dimensional
> > space. I can think of no reasonable definition for a
> canonical angle between
> > such vectors which ranges from 0 to 360 degrees (0 to 2*pi
> radians.)
> >
> > However, if you are in two-dimensional space, then you
> can speak of the
> > non-negative angle measured counterclockwise from vector a
> to vector b,
> > and this would give the range you have requested. If a =
> [x1,y1] and b =
> > [x2,y2], then such an angle is given in matlab by:
> >
> > angle = mod(atan2(y2-y1,x2-x1),2*pi); % Range: 0 to 2*pi
> radians
> >
> > (Multiply this answer by 180/pi to get degrees.)
> >
> > Roger Stafford

Thanks!
Best regards, Jorian Seokaner!

http://www.mathworks.com/matlabcentral/newsreader/author/126323
>