Re: VectorAngle

• To: mathgroup at smc.vnet.net
• Subject: [mg89982] Re: VectorAngle
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Wed, 25 Jun 2008 06:31:31 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <g3q7mc\$ajm\$1@smc.vnet.net>

```will parr wrote:

> I am having a little trouble with determining the angles between 2 vectors using the VectorAngle function. As an example:
>
> centroid = {0, 0, 0};
>
> Xvec = {1, 0, 0};
> Yvec = {0, 1, 0};
> Zvec = {0, 0, 1};
>
> xaxis = {centroid, Xvec};
>
> yaxis = {centroid, Yvec};
>
> zaxis = {centroid, Zvec};
>
> Show[Graphics[{Thickness[0.01], Blue, Line[xaxis[[All, {1, 2}]]]}],
>  Graphics[{Thickness[0.01], Red, Line[yaxis[[All, {1, 2}]]]}],
>  Graphics[{Thickness[0.01], Green, Line[zaxis[[All, {1, 2}]]]}],
>
>  Axes -> True, AxesLabel -> {"x", "y"}]
>
> This displays the x,y,z axes vectors. Then:
>
> vec1 = {-1, 0.2, 0};
> vec2 = {-1, -0.2, 0};
>
> Show[Graphics[{Thickness[0.01], Blue, Line[xaxis[[All, {1, 2}]]]}],
>  Graphics[{Thickness[0.01], Red, Line[yaxis[[All, {1, 2}]]]}],
>  Graphics[{Thickness[0.01], Green, Line[zaxis[[All, {1, 2}]]]}],
>
>  Graphics[{Thickness[0.01], Orange,
>    Line[{centroid, vec1}[[All, {1, 2}]]]}],
>  Graphics[{Thickness[0.01], Purple,
>    Line[{centroid, vec2}[[All, {1, 2}]]]}],
>
>
>  Axes -> True, AxesLabel -> {"x", "y"}]
>
> Displays 2 test vectors (vec1 and vec2). Now, using VectorAngle and calculating all angles in degrees (*180/\[Pi]):
>
> VectorAngle[Xvec, vec1]*180/\[Pi]
>
> = 168.69
>
> VectorAngle[Xvec, vec2]*180/\[Pi]
>
> = 168.69
>
> Here is my problem... is there any way to constrain VectorAngle so that it always measures from the first vector to the second vector in the same direction? ie so that the angle given by;
>
> VectorAngle[Xvec, vec2]*180/\[Pi]
>
> is;
>
> 180 + (180 - (VectorAngle[Xvec, vec2]*180/\[Pi]))
>
> = 191.31

Say we have two vectors v1 and v2 in R^3. That is,

v1 = (x1, y1, z1) and v2 = (x2, y2, z2).

The function VectorAngle[v1, v2] returns the angle theta that correspond to

cos(theta) = (v1.v2)/(||v1||*||v2||)

In the above formula, the scalar product (as well as the norms) is
computed component by component, i.e.

v1.v2 = x1*x2 + y1*y2 + z1*z2,

Now, cos(theta) is computed by dividing the scalar product by the
product of the norms.

As you can see, the orientation of the vectors with respect to each
others or to the axes is irrelevant in this formula. In other words you
will always get the angle theta between zero and pi.

HTH,
-- Jean-Marc

```

• Prev by Date: Re: Making nice-looking Legend for Plot
• Next by Date: Re: ParameterCITable vs. ParameterConfidenceRegion:
• Previous by thread: VectorAngle
• Next by thread: Re: VectorAngle