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;
}
Categories: MathVTK

0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Content Summary
: Input your strings, the tool can get a brief summary of the content for you.

X
1
0
Would love your thoughts, please comment.x
()
x