# Arrow for forces

Hi,

I have a writer for a moving rod (a vtkPolyData then a vtkTubeFilter followed by a vtkPolyDataMapper and vtkPolyDataWriter).
I now have detected collision in my software and I am applying a contact force when there is a collision in my rod.
So, is there a simple way to pass a vector and its origin so that I can visualize my forces acting on the rod ? So far, it seems that vtkGlyph3D could do it but I find this very complicated …

This did the job. In case somebody will need it someday…
It creates a second file with the arrows as intended. Then I open it with Paraview to see the sequence…

``````  // Points
vtkNew<vtkPoints> contactPoints;

// Reaction force
vtkNew<vtkDoubleArray> pointNormalsArray;
pointNormalsArray->SetNumberOfComponents(3); // 3d normals (ie x,y,z)
pointNormalsArray->SetNumberOfTuples(contactSet.size());

int i=0;
if(contactSet.size()!=0)
{
for(contact = contactSet.begin(); contact!=contactSet.end(); ++contact)
{
contact = contactSet.begin();
double normLocalForce = repulsive(contact->_squaredDistance);
Vec3x localForce = normLocalForce * contact->_normal;
double s = contact->_s;
double t = contact->_t;
double x,y,z;
strandsim::Vec3x contactPoint = contact->_contact *0.01;
x = contactPoint[0]; y = contactPoint[1]; z = contactPoint[2];
contactPoints->InsertNextPoint(x,y,z);
double normal[3] ={ localForce[0], localForce[1], localForce[2]};
pointNormalsArray->SetTuple(i,normal);
i++;
}
vtkNew<vtkPolyData> contactPolydata;
contactPolydata->SetPoints(contactPoints);
contactPolydata->GetPointData()->SetNormals(pointNormalsArray);

// Create anything you want here, we will use a cube for the demo.
vtkNew<vtkArrowSource> arrowSource;
arrowSource->SetTipResolution(16);
arrowSource->SetTipLength(0.3);
arrowSource->Update();

vtkNew<vtkGlyph3D> glyph3D;
glyph3D->SetSourceConnection(arrowSource->GetOutputPort());
glyph3D->SetInputData(contactPolydata);
glyph3D->SetVectorModeToUseNormal();
glyph3D->SetScaleFactor(0.0001);
glyph3D->SetColorModeToColorByVector();
glyph3D->SetScaleModeToScaleByVector();
glyph3D->OrientOn();
glyph3D->Update();

// Writer
vtkNew<vtkPolyDataWriter> writer;
fileName = fileName + std::to_string(numberOfFrame) + ".vtk";
const char * fName = fileName.c_str();
writer->SetFileName(fName);
// writer->SetInputConnection(tube->GetOutputPort());
writer->SetInputConnection(glyph3D->GetOutputPort());
writer->SetFileTypeToBinary();
writer->Write();

``````