Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!o16g2000prh.googlegroups.com!not-for-mail From: Nathan <ngreco32@gmail.com> Newsgroups: comp.soft-sys.matlab Subject: Re: Angle between two vectors Date: Tue, 23 Feb 2010 16:46:13 -0800 (PST) Organization: http://groups.google.com Lines: 83 Message-ID: <8db784bf-a96e-431b-b5c6-d6836905d350@o16g2000prh.googlegroups.com> References: <ef5ce9c.-1@webcrossing.raydaftYaTP> <1184052626.324470.175540@n2g2000hse.googlegroups.com> <hm1sj1$pop$1@fred.mathworks.com> NNTP-Posting-Host: 198.206.219.33 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1266972373 19596 127.0.0.1 (24 Feb 2010 00:46:13 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 24 Feb 2010 00:46:13 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: o16g2000prh.googlegroups.com; posting-host=198.206.219.33; posting-account=_KeVcAoAAAB7j3xn35ujaQ0BoQhuzwJP User-Agent: G2/1.0 X-HTTP-Via: 1.1 wwwproxy-son-ca-01.ca.sandia.gov:80 (squid/2.5.STABLE14) X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6,gzip(gfe),gzip(gfe) Xref: news.mathworks.com comp.soft-sys.matlab:611102 On Feb 23, 4:41 pm, "Benjamin McCrite" <dragonmast...@hotmail.com> wrote: > Greg Heath <he...@alumni.brown.edu> wrote in message <1184052626.324470.175...@n2g2000hse.googlegroups.com>... > > > > > On Jul 9, 5:16 pm, "y Mehta" <mehtayogesh@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