Commit ba3c24c3 authored by David Gobbi's avatar David Gobbi
Browse files

ProjectVector method was modifying plane normal.

Thanks to David Jarvis for pointing out this bug.  Projecting a vector
would cause the plane's normal to be multiplied by the dotprod of the
plane and the vector (in some cases, causing the normal to become zero).
Obviously the ProjectVector() function should not modify the normal.

Change-Id: Idaa86fdad897777a65fba6f8ac5309a3582175e6
parent a00da5eb
......@@ -56,22 +56,19 @@ void vtkPlane::ProjectPoint(double x[3], double xproj[3])
this->ProjectPoint(x, this->GetOrigin(), this->GetNormal(), xproj);
}
void vtkPlane::ProjectVector(double v[3], double origin[3], double normal[3],
void vtkPlane::ProjectVector(
double v[3], double vtkNotUsed(origin)[3], double normal[3],
double vproj[3])
{
(void)origin;
// This function uses this equation:
// projected = vector - (vector dot Normal)Normal
// Where 'Normal' is unit length
vtkMath::Normalize(normal);
double dotProd = vtkMath::Dot(v, normal);
vtkMath::MultiplyScalar(normal, dotProd);
vtkMath::Subtract(v, normal, vproj);
double t = vtkMath::Dot(v, normal);
double n2 = vtkMath::Dot(normal, normal);
if (n2 == 0)
{
n2 = 1.0;
}
vproj[0] = v[0] - t * normal[0] / n2;
vproj[1] = v[1] - t * normal[1] / n2;
vproj[2] = v[2] - t * normal[2] / n2;
}
void vtkPlane::ProjectVector(double v[3], double vproj[3])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment