[vtkusers] Angle Calculation

John Hunter jdhunter at ace.bsd.uchicago.edu
Tue Apr 8 10:02:53 EDT 2003


>>>>> "ramu" == ramu chandran <chandranram4u at rediffmail.com> writes:

    ramu> Hi, How can I calculate the angle of the plane with respect
    ramu> to X, Y or Z axes using the normal of the plane.

The angle any line makes with another line can be obtained from the
relation:

 x . y = |x| |y| cos(alpha)

where '.' is the dot product, |x| is the norm of x, and alpha is the
angle between x and y.

Thus if x and y have norm 1, you can get the angle as acos(x . y).

In python:

    a = (1,0,0)                      # the normed x axis
    b = plane.GetNormal()            # the normalized plane normal
    dotprod = vtk.vtkMath.Dot(a,b)
    alpha = acos(dotprod)            # angle in radians

I believe the normals from vtkPlanes are always normalized, but if you
are dealing normals that don't have length 1, you can normalize them
with

    vtk.vtkMath.Normalize(b) 

Ditto for the y and z axes.  Now if you want the angle of the plane,
rather than the normal, I think you'll just want to do 

  90 - 180.0/pi*alpha

John Hunter



More information about the vtkusers mailing list