Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: Angle between two vectors Date: Fri, 28 Dec 2007 20:36:34 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 31 Message-ID: <fl3moi$pvc$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> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-05-blr.mathworks.com Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1198874194 26604 172.30.248.35 (28 Dec 2007 20:36:34 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Fri, 28 Dec 2007 20:36:34 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:443743 "baris kazar" <mbkazar.nospam@gmail.com> wrote in message <fl377q$4ip $1@fred.mathworks.com>... > Hi,- > how can we generalize this to 3-D vectors? Think of a > plane on 3-D space and you have vectors on this plane. I > wanna know the angle between 2 vectors in the range 0-2pi. > or at least -pi to pi. I have 3 vectors. One (First) > vector is the same all the time. I wanna know the relative > positions of the other two vector wrt the firsy one. Thus, > i need angles in the range 0 to 2pi or -pi to pi. > Thanks in advance --------- As Bruno has pointed out, the angle between two three-dimensional vectors depends on which sense one gives to a vector orthogonal to their plane. It isn't clear what you meant by, "the relative positions of the other two vector wrt the firsy one." The vector cross product of the second two vectors will be a vector orthogonal to their plane. Perhaps you mean that the angle between them is to be considered positive if this cross product lies on the same side of the plane as this first vector, and negative otherwise. If that is the case, then let your first, second, and third vectors be designated as x, y, and z, respectively. A matlab formula for calculating the angle between y and z will then be: c = cross(y,z); angleyz = sign(dot(x,c))*atan2(norm(c),dot(y,z)); The value of 'angleyz' will range from -pi to +pi. If you want it to range from 0 to 2*pi, then apply the 'mod' function as I did on Dec. 11 in this thread. Roger Stafford