------------------------------------------------------------------------------ Set the normal to the plane. Will modify the Origin, Point1, and Point2 instance variables as necessary (i.e., rotate the plane around its center).
| 197 | // Set the normal to the plane. Will modify the Origin, Point1, and Point2 |
| 198 | // instance variables as necessary (i.e., rotate the plane around its center). |
| 199 | void vtkPlaneSource::SetNormal(double N[3]) |
| 200 | { |
| 201 | double n[3], rotVector[3], theta; |
| 202 | |
| 203 | // make sure input is decent |
| 204 | n[0] = N[0]; |
| 205 | n[1] = N[1]; |
| 206 | n[2] = N[2]; |
| 207 | if (vtkMath::Normalize(n) == 0.0) |
| 208 | { |
| 209 | vtkErrorMacro(<< "Specified zero normal"); |
| 210 | return; |
| 211 | } |
| 212 | |
| 213 | // Compute rotation vector using a transformation matrix. |
| 214 | // Note that if normals are parallel then the rotation is either |
| 215 | // 0 or 180 degrees. |
| 216 | double dp = vtkMath::Dot(this->Normal, n); |
| 217 | if (dp >= 1.0) |
| 218 | { |
| 219 | return; // zero rotation |
| 220 | } |
| 221 | else if (dp <= -1.0) |
| 222 | { |
| 223 | theta = 180.0; |
| 224 | rotVector[0] = this->Point1[0] - this->Origin[0]; |
| 225 | rotVector[1] = this->Point1[1] - this->Origin[1]; |
| 226 | rotVector[2] = this->Point1[2] - this->Origin[2]; |
| 227 | } |
| 228 | else |
| 229 | { |
| 230 | vtkMath::Cross(this->Normal, n, rotVector); |
| 231 | theta = vtkMath::DegreesFromRadians(acos(dp)); |
| 232 | } |
| 233 | |
| 234 | this->Rotate(theta, rotVector); |
| 235 | } |
| 236 | |
| 237 | //------------------------------------------------------------------------------ |
| 238 | // Set the normal to the plane. Will modify the Origin, Point1, and Point2 |