How to create a local coordinate system and show it? We define the local coordinate system has its own x-axis, y-axis, z-axis, and origin.

We call the left coordinate system L1 and the right coordinate system L2.
Regard L1 as the world coordinate system in VTK, the other one L2 is a local coordinate system.
Define a vector W.

    \[W = \begin{pmatrix} x \\ y \\ z \\ \end{pmatrix}\]

We want to know the new expression V in the coordinate system L2.
Create a matrix transformation equation.

    \[T W = V\]

The matrix T can help us to convert W to the new expression in the coordinate system L2, we call T local coordinate matrix.
How to show the local coordinate system if we don’t know its status before?
The question is equal to compute the expression of E that a unit vector in L2 in the world coordinate system.
So we have the following equation.

    \[TW = E\]

    \[W = T^{-1} E\]

We can apply the T^{-1} to a vtkAxesActor object to show the local coordinate system.
Let’s call the matrix T^{-1} pose coordinate matrix.

vtkSmartPointer<vtkTransform> CreateLocalTrans(PointStruct origin, PointStruct xDir, PointStruct yDir)
{
    vtkSPtrNew( resultTrans, vtkTransform );
    PointStruct zDir = xDir ^ yDir;
    zDir.Unit();

    double elements1[16] = { xDir[0], xDir[1], xDir[2], 0,
                            yDir[0], yDir[1], yDir[2], 0,
                            zDir[0], zDir[1], zDir[2], 0,
                            0, 0, 0, 1 };

    resultTrans->Concatenate(elements1);     //rotation

    double elements2[16] = { 1, 0, 0, -origin[0],
                             0, 1, 0, -origin[1],
                             0, 0, 1, -origin[2],
                             0, 0, 0, 1 };

    resultTrans->Concatenate(elements2);    //translation
    resultTrans->Update();

    return resultTrans;
}

int main()
{
    vtkSmartPointer<vtkTransform> local1  =
            CreateLocalTrans( PointStruct(0, 0, 0), PointStruct(1, 0, 0), PointStruct(0, 1, 0) );
    vtkSmartPointer<vtkTransform> local2  =
            CreateLocalTrans( PointStruct(10, 0, 0), PointStruct(0, 1, 0), PointStruct(-1, 0, 0) );

    vtkSPtrNew(m1, vtkMatrix4x4);
    m1->DeepCopy( local1->GetMatrix() );
    vtkSPtrNew(m2, vtkMatrix4x4);
    m2->DeepCopy( local2->GetMatrix() );
    m1->Invert();
    vtkSPtrNew(T, vtkMatrix4x4);
    vtkMatrix4x4::Multiply4x4( m2, m1, T );
    T->Print( std::cout );
    vtkSPtrNew(TTrans, vtkTransform);
    TTrans->SetMatrix( T );
    TTrans->Inverse();

    vtkSmartPointer<vtkAxesActor> axesActor =
            vtkSmartPointer<vtkAxesActor>::New();
    axesActor->SetUserTransform( TTrans );

    vtkSmartPointer<vtkRenderer> renderer =
            vtkSmartPointer<vtkRenderer>::New();
    renderer->AddActor( axesActor );
    renderer->SetBackground( 0, 0, 0 );

    vtkSmartPointer<vtkRenderWindow> renderWindow =
            vtkSmartPointer<vtkRenderWindow>::New();
    renderWindow->AddRenderer( renderer );

    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
            vtkSmartPointer<vtkRenderWindowInteractor>::New();
    renderWindowInteractor->SetRenderWindow( renderWindow );

    renderer->ResetCamera();
    renderWindow->Render();
    renderWindowInteractor->Start();

Now let’s regard L1 as a local coordinate system and explore the transform matrix A.

    \[A L_1 W = L_2 W\]

L_1W means the new expression of W in the local coordinate system L_1.
There is a transform matrix A that can help us to describe a vector or point in L_2 by system L_1.
We can calculate the value of A and apply it.

    \[\begin{pmatrix} 0 & 1 & 0  &0 \\ -1 & 0 & 0 & 10 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x \\ y \\ z \\ 1 \end{pmatrix} = \begin{pmatrix} y \\ -x + 10 \\ z \\ 1 \end{pmatrix}\]

Split the matrix A to rotate matrix and translate matrix.
Rotate matrix:

    \[\begin{pmatrix} 0 & 1 & 0 \\ -1 & 0 & 0 \\ 0 & 0 & 1 \end{pmatrix}\]

Translate vector:

    \[\begin{pmatrix} 0 \\ 10 \\ 0 \end{pmatrix}\]

We can find that the translate vector starts from system L_2 to system L_1, it is described by system L_2 because we rotate L_1 firstly, and then move it to get the system L_2.

Categories: VTK

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

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