In article <ef5ce9c.-1@webcrossing.raydaftYaTP>, "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));
>
> 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
---------------------
It is usually understood that the angle between two three-dimensional
vectors is measured by the shortest great circle path between them, which
means that it must lie between 0 and pi radians. To get such an answer,
the best method, in my opinion, is this:
angle = atan2(norm(cross(a,b)),dot(a,b));
Since the first argument must be non-negative, the angle will lie
somewhere in the two first quadrants, and thus be between 0 and pi. This
formula remains valid even if a and b are not unit vectors.
Your 'acos' formula gives the correct answer with unit vectors as it
stands, but it encounters an accuracy problem for angles that are near 0
or pi. This is the main reason for my preference for the 'atan2' method.
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.
> 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.
In article <1184052626.324470.175540@n2g2000hse.googlegroups.com>, Greg
Heath <heath@alumni.brown.edu> wrote:
> 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
---------------
Greg, Y Mehta did specifically state that a and b are unit vectors, so
his formula is in fact correct as it stands, though subject to increasing
errors as its dot product approaches +1 or -1. When a and b are nearly
parallel, the same kind of trouble occurs with the formula you have given
here. In such cases there is a real need to combine the scalar dot
product with the vector cross product in order to make use of both the
sine and cosine in calculating the angle accurately, which is what the
'tan2' formula does.
On Jul 10, 4:27 am, ellieandrogerxy...@mindspring.com.invalid (Roger
Stafford) wrote:
> In article <1184052626.324470.175...@n2g2000hse.googlegroups.com>, Greg
>
>
>
>
>
> Heath <h...@alumni.brown.edu> wrote:
> > 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
>
> ---------------
> Greg, Y Mehta did specifically state that a and b are unit vectors, so
> his formula is in fact correct as it stands, though subject to increasing
> errors as its dot product approaches +1 or -1. When a and b are nearly
> parallel, the same kind of trouble occurs with the formula you have given
> here. In such cases there is a real need to combine the scalar dot
> product with the vector cross product in order to make use of both the
> sine and cosine in calculating the angle accurately, which is what the
> 'tan2' formula does.
Thanks.
For some problem in the past (probably single precision?) I got better
accuracy using
In article <1184104526.774530.54800@n60g2000hse.googlegroups.com>, Greg
Heath <heath@alumni.brown.edu> wrote:
> For some problem in the past (probably single precision?) I got better
> accuracy using
>
> sign(sintheta)*acos(costheta)
>
> instead of atan2.
---------------
I don't know why that would be better, Greg. The acos(costheta) is
subject to the same problem as before. When costheta is very near 1, the
accuracy is very much inferior to that of 'atan2'. I would think this
would be equally true in single precision.
Here's a concrete example of what I am referring to:
format long
a = pi*(1-1/10^8); % Choose an angle a little below pi
a2 = atan2(sin(a),cos(a)); % Use atan2
a3 = acos(cos(a)); % Use acos
[a;a2;a3;a-a2;a-a3] % Compare results
a = pi/2*1.123; % Now select an angle near pi/2
a2 = atan2(sin(a),cos(a)); % atan2 again
a3 = acos(cos(a)); % Then acos
[a;a2;a3;a-a2;a-a3] % Make the same comparisons
As you see, there is a very distinct loss of accuracy in 'acos' for angles
near pi. Some seven entire decimal places have been lost - that is,
errors are several million times as large as normal. On the other hand,
the angle near pi/2 yields the customary 1 in 2^52 accuracy.
hello,
how can i calculate the angles so that they are in the range
0-360 degrees?
thanks
salih
"y Mehta" <mehtayogesh@gmail.(DOT).com> wrote in message
<ef5ce9c.-1@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
hello,
how can i calculate the angles so that they are in the range
0-360 degrees?
thanks
salih
"y Mehta" <mehtayogesh@gmail.(DOT).com> wrote in message
<ef5ce9c.-1@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
"salih tuna" <salihtuna@gmail.com> wrote in message <fjj9nj$fia
$1@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@gmail.(DOT).com> wrote in message
> <ef5ce9c.-1@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
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
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
wrote in message <fjk0tg$jli$1@fred.mathworks.com>...
> "salih tuna" <salihtuna@gmail.com> wrote in message
<fjj9nj$fia
> $1@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@gmail.(DOT).com> wrote in message
> > <ef5ce9c.-1@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
"salih tuna" <salihtuna@gmail.com> wrote in message <fjlrpl$gii
$1@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
>
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
> wrote in message <fjk0tg$jli$1@fred.mathworks.com>...
> > angle = mod(atan2(y2-y1,x2-x1),2*pi); % Range: 0 to 2*pi
--------
I certainly owe you an apology, Salih. That formula I gave you is very, very
wrong. I can't imagine what I was thinking about when I wrote it. Chalk it up
to momentary insanity! :-) The correct computation should be as follows.
Assuming a = [x1,y1] and b = [x2,y2] are two vectors with their bases at the
origin, the non-negative angle between them measured counterclockwise
from a to b is given by
angle = mod(atan2(x1*y2-x2*y1,x1*x2+y1*y2),2*pi);
As you can see, this bears a close relationship to the three-dimensional
formula I wrote last July 10. The quantities, x1*y2-x2*y1 and x1*x2+y1*y2
are, respectively, the sine and cosine of the counterclockwise angle from
vector a to vector b, multiplied by the product of their norms - that is, their
cross product and the dot product restricted to two dimensions. The 'atan2'
function then gives the angle between them ranging from -pi to +pi, and the
'mod' operation changes this so as to range from 0 to 2*pi, as you requested.
Roger hi,
thanks a lot for your help but i am afraid something is
still missing. i tried the formulae on the same example of
a = [1 1]and b = [0 -1] (both passing through origin).
the answer i got is 315 instead of 225.
sorry i am taking a lot of your time :)
thanks
salih
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
wrote in message <fjm4u4$i8o$1@fred.mathworks.com>...
> "salih tuna" <salihtuna@gmail.com> wrote in message
<fjlrpl$gii
> $1@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
> >
> > "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
> > wrote in message <fjk0tg$jli$1@fred.mathworks.com>...
> > > angle = mod(atan2(y2-y1,x2-x1),2*pi); % Range: 0 to 2*pi
> --------
> I certainly owe you an apology, Salih. That formula I
gave you is very, very
> wrong. I can't imagine what I was thinking about when I
wrote it. Chalk it up
> to momentary insanity! :-) The correct computation
should be as follows.
>
> Assuming a = [x1,y1] and b = [x2,y2] are two vectors
with their bases at the
> origin, the non-negative angle between them measured
counterclockwise
> from a to b is given by
>
> angle = mod(atan2(x1*y2-x2*y1,x1*x2+y1*y2),2*pi);
>
> As you can see, this bears a close relationship to the
three-dimensional
> formula I wrote last July 10. The quantities, x1*y2-x2*y1
and x1*x2+y1*y2
> are, respectively, the sine and cosine of the
counterclockwise angle from
> vector a to vector b, multiplied by the product of their
norms - that is, their
> cross product and the dot product restricted to two
dimensions. The 'atan2'
> function then gives the angle between them ranging from
-pi to +pi, and the
> 'mod' operation changes this so as to range from 0 to
2*pi, as you requested.
>
> Roger Stafford
>
>
"salih tuna" <salihtuna@gmail.com> wrote in message <fjmabs$9fh
$1@fred.mathworks.com>...
> Roger hi,
> thanks a lot for your help but i am afraid something is
> still missing. i tried the formulae on the same example of
> a = [1 1]and b = [0 -1] (both passing through origin).
> the answer i got is 315 instead of 225.
> sorry i am taking a lot of your time :)
> thanks
> salih
-----
Hi Salih. I get 225 degrees for that example with a = [1,1] and b = [0,-1],
which is correct. Are you sure you didn't have x2 and y1 interchanged by
mistake? That would get you an erroneous answer of 315. You should have x1
= 1, y1 = 1, x2 = 0, and y2 = -1.
"Roger Stafford"
<ellieandrogerxyzzy@mindspring.com.invalid> wrote in
message <fjk0tg$jli$1@fred.mathworks.com>...
> "salih tuna" <salihtuna@gmail.com> wrote in message
<fjj9nj$fia
> $1@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@gmail.(DOT).com> wrote in
message
> > <ef5ce9c.-1@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
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
"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.
The problem is depends on where you look (from above or from
below the plane), you will see the angle between vectors on
this plane reverse the sign (draw them on a transparent
glass and try to look from both sides). In 3D there is
nothing that could tell us whereas looking from one way or
from another is more "correct".
"Bruno Luong" <b.luong@fogale.fr> wrote in message <fl3eu1
$d3$1@fred.mathworks.com>...
> "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.
>
> The problem is depends on where you look (from above or
from
> below the plane), you will see the angle between vectors
on
> this plane reverse the sign (draw them on a transparent
> glass and try to look from both sides). In 3D there is
> nothing that could tell us whereas looking from one way
or
> from another is more "correct".
>
> Think like a fish or a bird, not like a man.
>
> Bruno
>
Hi Bruno,
Thanks, but i partially dont agree with you. If you
choose a reference of point which the start point of the
first vector, it is not important for me whether you look
from above or below the plane. I need relative positions
but not the absolute positions. I think i indicated this
above.
Anyways, if someone comes up with an idea, please post
here. I am very curious about a solution.
Best regards
"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"
<ellieandrogerxyzzy@mindspring.com.invalid> wrote in
message <fl3moi$pvc$1@fred.mathworks.com>...
> "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
>
Hi Roger,-
yes, this is one step closer to what i need but not
exactly. Let's take a numeric example:
x=(1,0,0); y=(1,0,1) and z=(1,0-1)
let's call the angle between x and y theta.
Then i wanna get 2pi-theta for the angle between x and z.
i dont have access y and z at the same time.
hope that this problem statement is clear.
Thanks much for your reply
Best regards
"baris kazar" <mbkazar.nospam@gmail.com> wrote in message
> yes, this is one step closer to what i need but not
> exactly. Let's take a numeric example:
> x=(1,0,0); y=(1,0,1) and z=(1,0-1)
> let's call the angle between x and y theta.
> Then i wanna get 2pi-theta for the angle between x and z.
> i dont have access y and z at the same time.
> hope that this problem statement is clear.
Assuming a human being (e.g., all the birds, or you) can go
anywhere in R3, and can look in any direction (a fair
assumption isn't it?).
VIEW1: Goto the point (0,-1,0) look toward the direction
(0,1,0): you see angle(x,y)=-pi/4, and angle(x,z)=pi/4.
VIEW2: Goto the point (0,+1,0) look toward the direction
(0,-1,0): you see angle(x,y)=+pi/4, and angle(x,z)=-pi/4.
In both cases you have angle(x,y) = -angle(x,z) modulo 2*pi,
as your wish expressed above with "theta".
BUT
CASE1/VIEW1: angle(x,y)=-pi/4; angle(x,z)=pi/4; angle(y,z)=pi/2.
"baris kazar" <mbkazar.nospam@gmail.com> wrote in message <fl3nhq$3tc
$1@fred.mathworks.com>...
> Hi Roger,-
> yes, this is one step closer to what i need but not
> exactly. Let's take a numeric example:
> x=(1,0,0); y=(1,0,1) and z=(1,0-1)
> let's call the angle between x and y theta.
> Then i wanna get 2pi-theta for the angle between x and z.
> i dont have access y and z at the same time.
> hope that this problem statement is clear.
> Thanks much for your reply
> Best regards
--------
You will have to try harder to explain your problem, if I am to understand
you, Baris. The example you gave has x, y, and z all in the same plane. You
didn't state previously that all your vectors are coplanar. Are they? But
whether they are or not, this doesn't explain how you would define the angle
theta between x and y. It could be plus pi/4 or it could be minus pi/4 (or
7/4*pi.) Which one would you choose and according to what criterion? It
would depend on which side of the plane, in this case the x-z plane, is
regarded as its positive side - along the plus y-axis, or along the negative
side of the y-axis. Also it depends on whether you are moving from x
towards y or from y towards x if you are adhering to right-hand cross
product direction conventions.
Select two arbitrary vectors in three-dimensional space (x1,y1,z1) and
(x2,y2,z2) and try to think of a consistent way of defining the angle between
them without reference to any other vector that would allow this quantity to
range over the full four quadrants, 0 to 2*pi. I think you will find this a
difficult thing to do in any way that could reasonably be considered canonical.
In two dimensions, there is a clearly defined counterclockwise direction from
vector x to vector y which would give you the range you desire. In three
dimensions, you lose the sense of what is a "counterclockwise" direction. You
can go from x to y along either of two great circle paths and one direction will
give the supplement angle to the opposite direction. If you always select the
shortest path, then your angle range is restricted to [0,pi].
If one vector of each pair is restricted to a particular fixed vector, as your
previous wordage seemed to imply, I still don't see what criterion you wish to
use to define these angles. For example, you can move from the fixed vector
by one degree in all possible directions giving a cone, but which half of these
angles should be adjusted so as to be the supplements (that is 359 degrees,)
of those on the opposite side? If you are restricting your vectors to all be
coplanar, then which side of such a plane is to be considered its "positive"
side?
"Roger Stafford"
<ellieandrogerxyzzy@mindspring.com.invalid> wrote in
message <fl3r7p$5nt$1@fred.mathworks.com>...
> You will have to try harder to explain your problem,
if I am to understand
> you, Baris. The example you gave has x, y, and z all in
the same plane. You
> didn't state previously that all your vectors are
coplanar. Are they? But
I think i did:
> > 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.
I think i might not have done a good in explaining the
problem. Sorry about that.
Best regards,
"Roger Stafford"
<ellieandrogerxyzzy@mindspring.com.invalid> wrote in
message <fl3r7p$5nt$1@fred.mathworks.com>...
> "baris kazar" <mbkazar.nospam@gmail.com> wrote in
message <fl3nhq$3tc
> $1@fred.mathworks.com>...
> > Hi Roger,-
> > yes, this is one step closer to what i need but not
> > exactly. Let's take a numeric example:
> > x=(1,0,0); y=(1,0,1) and z=(1,0-1)
> > let's call the angle between x and y theta.
> > Then i wanna get 2pi-theta for the angle between x and
z.
> > i dont have access y and z at the same time.
> > hope that this problem statement is clear.
> > Thanks much for your reply
> > Best regards
> --------
> You will have to try harder to explain your problem,
if I am to understand
> you, Baris. The example you gave has x, y, and z all in
the same plane. You
> didn't state previously that all your vectors are
coplanar. Are they? But
> whether they are or not, this doesn't explain how you
would define the angle
> theta between x and y. It could be plus pi/4 or it
could be minus pi/4 (or
> 7/4*pi.) Which one would you choose and according to
what criterion? It
> would depend on which side of the plane, in this case
the x-z plane, is
> regarded as its positive side - along the plus y-axis,
or along the negative
> side of the y-axis. Also it depends on whether you are
moving from x
> towards y or from y towards x if you are adhering to
right-hand cross
> product direction conventions.
>
> Select two arbitrary vectors in three-dimensional
space (x1,y1,z1) and
> (x2,y2,z2) and try to think of a consistent way of
defining the angle between
> them without reference to any other vector that would
allow this quantity to
> range over the full four quadrants, 0 to 2*pi. I think
you will find this a
> difficult thing to do in any way that could reasonably
be considered canonical.
> In two dimensions, there is a clearly defined
counterclockwise direction from
> vector x to vector y which would give you the range you
desire. In three
> dimensions, you lose the sense of what is
a "counterclockwise" direction. You
> can go from x to y along either of two great circle
paths and one direction will
> give the supplement angle to the opposite direction. If
you always select the
> shortest path, then your angle range is restricted to
[0,pi].
>
> If one vector of each pair is restricted to a
particular fixed vector, as your
> previous wordage seemed to imply, I still don't see what
criterion you wish to
> use to define these angles. For example, you can move
from the fixed vector
> by one degree in all possible directions giving a cone,
but which half of these
> angles should be adjusted so as to be the supplements
(that is 359 degrees,)
> of those on the opposite side? If you are restricting
your vectors to all be
> coplanar, then which side of such a plane is to be
considered its "positive"
> side?
>
> Roger Stafford
>
Hi Roger,-
these are excellent questions.
one can choose to look at the plane from +ive infinity
(above) or from -ive infinity (below).
I know that in 3D there is no notion of CW or CCW. 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.
Anyways, i dont wanna confuse anyone any more.
I will find another solution to this problem.
Best regards
"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 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
>
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.