We know the matrix shearing object along a particular axis looks like:
The shear transform can help us to approve that when a normal vector is transformed using the same matrix that transforms the points on an object, the resulting vector may not be perpendicular to the surface as is shown here for the sheared rectangle. The tangent vector, however, does transform to a vector tangent to the transformed surface.
#include <vtkPointData.h>
#include <vtkSmartPointer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkPolyData.h>
#include <vtkProperty.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkCommand.h>
#include <vtkSliderWidget.h>
#include <vtkSliderRepresentation.h>
#include <vtkTransform.h>
#include <vtkSliderRepresentation3D.h>
#include <vtkWidgetEventTranslator.h>
#include <vtkWidgetEvent.h>
#include <vtkCubeSource.h>
#include <vtkTransformFilter.h>
#include <vtkAxesActor.h>
#include "./tool.h"
#define vtkSPtr vtkSmartPointer
#define vtkSPtrNew(Var, Type) vtkSPtr<Type> Var = vtkSPtr<Type>::New();
int main(int, char *[])
{
vtkSPtrNew( source, vtkCubeSource );
source->Update();
double elements[16] = { 1, 0, 0, 0,
0.5, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
vtkSPtrNew( trans, vtkTransform );
trans->SetMatrix( elements );
trans->Update();
vtkSPtrNew( transFilter, vtkTransformFilter );
transFilter-vec_n>SetInputData( source->GetOutput() );
transFilter->SetTransform( trans );
transFilter->Update();
vtkSPtrNew( mapper, vtkPolyDataMapper );
mapper->SetInputData( transFilter->GetPolyDataOutput() );
vtkSPtrNew( actor, vtkActor );
actor->SetMapper( mapper );
vtkSPtrNew( axes, vtkAxesActor );
axes->SetTotalLength( 1, 1, 1 ); // change length of three axis
vtkSPtrNew( renderer, vtkRenderer );
renderer->AddActor( actor );
renderer->AddActor( axes );
renderer->SetBackground( 0, 0, 0 );
vtkSPtrNew( renderWindow, vtkRenderWindow );
renderWindow->AddRenderer( renderer );
vtkSPtrNew( renderWindowInteractor, vtkRenderWindowInteractor );
renderWindowInteractor->SetRenderWindow( renderWindow );
renderer->ResetCamera();
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
We write a CPlusPlus program to explore the above conclusion.
let’s use matrix to describe the relationship of vector and .
So the orthogonal vector for is . Let’s name the vector which is perpendicular to all tangent vectors of cell plane .
We have:
PointStruct vec_t( 1, 0, 0 );
trans->TransformVector( vec_t.point, vec_t.point );
cout << vec_t << endl;
PointStruct vec_n( 0, 1, 0 );
trans->Inverse();
trans->Update();
vtkSPtrNew( matrix, vtkMatrix4x4 );
trans->GetTranspose( matrix );
vtkSPtrNew( MT, vtkTransform );
MT->SetMatrix( matrix );
MT->TransformVector( vec_n.point, vec_n.point );
cout << vec_n << endl;
cout << vec_n.Dot( vec_t ) << endl;
Output:
PointStruct [1, 0.5, 0]
PointStruct [-0.5, 1, 0]
0