[vtkusers] Angle between two vectors
Harold
boogiedoll at yahoo.com
Sat Jan 4 00:43:00 EST 2014
Thanks David. That reduces the number of calculation.So I guess there isn't any vtk method I can call to get the angle.
Harold
On Friday, January 3, 2014 11:52 PM, David Cole <dlrdave at aol.com> wrote:
Your "get_angle_new" is about as simple as it gets.
I would do something like this, though:
double dot = vtkMath::Dot(v1, v2);
// Expect v1 and v2 to be normalized unit vectors, but sometimes
the dot product
// exceeds 1 by just enough to cause errors when calling acos.
// If it's greater than 1.0, or less than -1.0, clamp it:
if (dot > 1.0)
{
dot = 1.0;
}
else if (dot < -1.0)
{
dot = -1.0;
}
double angle = acos(dot);
HTH,
David C.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140103/235cf70e/attachment.htm>
More information about the vtkusers
mailing list