I take notes about how to rotate vector to a special direction.
#include "./tool.h"
#define vtkSPtr vtkSmartPointer
#define vtkSPtrNew(Var, Type) vtkSPtr<Type> Var = vtkSPtr<Type>::New();
int main(int, char *[])
{
PointStruct vec0( 1, 1, 0 );
PointStruct vec1( -1, 1, 0 );
PointStruct vecZ( 0, 0, 1 );
double radian = vtkMath::AngleBetweenVectors( vec0.point, vec1.point );
double degree = vtkMath::DegreesFromRadians( radian );
vtkSPtrNew( trans, vtkTransform );
if (fabs(degree) > 0.0001)
{
PointStruct crossVec;
if (fabs(degree - 180) < 0.0001)
crossVec = vecZ;
else
crossVec = vec0^vec1;
crossVec.Unit();
trans->RotateWXYZ(degree, crossVec[0], crossVec[1], crossVec[2]);
trans->Update();
}
PointStruct tester = vec0;
trans->TransformVector( tester.point, tester.point );
cout << tester << endl;
return EXIT_SUCCESS;
}
[…] The post is based on https://www.weiy.city/2021/11/vtk-rotate-vector-to-special-direction/. […]