Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.fr>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Angle between two vectors
Date: Sat, 29 Dec 2007 09:46:12 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 59
Message-ID: <fl5514$f9g$1@fred.mathworks.com>
References: <ef5ce9c.-1@webcrossing.raydaftYaTP> <fjj9nj$fia$1@fred.mathworks.com> <fjk0tg$jli$1@fred.mathworks.com> <fl377q$4ip$1@fred.mathworks.com> <fl3moi$pvc$1@fred.mathworks.com> <fl3nhq$3tc$1@fred.mathworks.com> <fl3r7p$5nt$1@fred.mathworks.com> <fl4nc4$47i$1@fred.mathworks.com> <fl539d$np9$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.fr>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1198921572 15664 172.30.248.38 (29 Dec 2007 09:46:12 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 29 Dec 2007 09:46:12 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:443796


"Bruno Luong" <b.luong@fogale.fr> wrote in message
<fl539d$np9$1@fred.mathworks.com>...
> "baris kazar" <mbkazar.nospam@gmail.com> wrote in message
> <fl4nc4$47i$1@fred.mathworks.com>...
> 
> > 
> > However,
> > you can define it locally wrt a point/vector as long as 
> > they are on a plane by defining from which side you are 
> > looking at.
> 
> That's a good way. Pick a side.
> 
> That's easy. 
> 
> 1. Select two arbitrary vectors in the set, e.g., the first
> (U) and the second (V) vectors, assumming they are all unit
> vectors. Normalize them if they aren't.
> 
> 2. Next compute the cross product N = U x V. This gives you
> a normal vector N pointing ONE side of the plane.
> 
> 3. Take a cross product W = N x U. Now you have {U,W} which
> is a orthonormal basis vectors of the plane. In other word,
> Span(U,V) = Span(U,W), <U,W>=0, |U|=1, |W|=1.
> 
> 4. Compute the angle as of any vector Z (in the plane as
> following):
> 
> theta = atan2(<W.Z>,<U.Z>)  % <- Do not change U or W
> 
> This gives you ONE consistent way to define angle (only for
> vectors belong to the plane).
> 
> PS: In a more abstract way, you can also accomplish steps
> 1->3 by using Gram-Smidth orthogonalization, or QR (help qr).
> 
> Bruno
> 

U=[1 0 0]';
V=[1 0 1]'; % example above

[Q R]=qr([U V],0);
angle=@(v) atan2(dot(Q(:,2),v),dot(Q(:,1),v));

>> angle(U)

     0

>> angle(V)

   -0.7854

>> angle([1 0 -1])

    0.7854

Bruno