## Vector3D.GetAngle(a,b,axis) haroldvanaarsen
7/1/2013 4:53 PM

How does it work, what does it do?

C# Code:
```private static double GetAngle(Vector3D VecRef, Vector3D VecA, Vector3D VecB)
{
Vector3D vRef = VecRef; vRef.Normalize();
Vector3D vA = VecA; vA.Normalize();
Vector3D vB = VecB; vB.Normalize();

double dAngRad = Vector3D.GetAngle(vA, vB, vRef);

}```

I have created this function and expect it to return the angle between vA and vB where these are first placed on a plane created by de vRef. But is this expectation right ?

Harold rammi
7/4/2013 12:36 PM

Sorry to disappoint you, and sorry for the bad documentation of both GetAngle() methods.
The method with two arguments works as you might expect, but the 3 argument method is an internally used helper method which escaped into the open. It is only useful in entity transformation, but gives no access to the rotation angle around the axis in which you are interested.

I also added a GetAngleAroundAxis() method, which does what you are looking for. It will appear in the next release, but if you don't want to wait here's its code:

C# Code:
```        /// <summary>
/// Get the rotation angle between two vectors around a given axis.
/// </summary>
/// <remarks>
/// As both vectors may have different angles to the axis itself,
/// the returned rotation angle will only give the best fit for the rotation.
/// This is the rotation angle which will rotate the projection of <paramref name="a"/>
/// into a plane perpendicular to the axis to the projection of <paramref name="b"/>
/// into the same plane.
/// </remarks>
/// <param name="a">First vector.</param>
/// <param name="b">Second vector.</param>
/// <param name="axis">Rotation axis.</param>
/// <returns>Angle in radians between 0 and 2 pi.</returns>
public static double GetAngleAroundAxis(Vector3D a, Vector3D b, Vector3D axis)
{
axis.Normalize();
if (Vector3D.AreApproxEqual(Vector3D.Zero, axis))
{
// zero axis
return 0;
}
Matrix3D projection = Transformation3D.GetArbitraryCoordSystem(axis).GetTranspose();
Vector3D aPlane = projection.Transform(a);
Vector3D bPlane = projection.Transform(b);
double rotation = System.Math.Atan2(bPlane.Y, bPlane.X) - System.Math.Atan2(aPlane.Y, aPlane.X);
if (rotation < 0)
{
rotation += 2 * System.Math.PI;
}
return rotation;
}```

- Rammi