# Rotating vectors around an axis

**URL:** <https://discourse.vtk.org/t/rotating-vectors-around-an-axis/5365>\
**Category:** Development\
**Created:** [March 11, 2021, 7:59am UTC](https://discourse.vtk.org/t/rotating-vectors-around-an-axis/5365 "2021-03-11T07:59:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guillaume\_Gillet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/guillaume_gillet/32/3114_2.png) [@Guillaume\_Gillet](https://discourse.vtk.org/u/Guillaume_Gillet)\
**Post date:** [March 11, 2021, 7:59am UTC](https://discourse.vtk.org/t/rotating-vectors-around-an-axis/5365/1 "2021-03-11T07:59:39Z")

</div>

So, i have a vector field i need to display in vtk, i have x and y coordinates (it’s a vector field on a 0 z axis, just a plane) but i also have for every vector a rotation around an axis, so what i’m asking here is, is it possible to apply a transform array or something like that to rotate each vector individually? Or am i forced to create an actor for each vector to display it properly (doesn’t seem good for memory)

Thanks for your answer.

---

<div class="post-metadata">

**Author:** ![Andrew](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andrew/32/3861_2.png) [@Andrew](https://discourse.vtk.org/u/Andrew)\
**Post date:** [March 11, 2021, 8:52am UTC](https://discourse.vtk.org/t/rotating-vectors-around-an-axis/5365/2 "2021-03-11T08:52:26Z")

</div>

What is your rotation? Can you rotate all the vectors in the field so you just have an array of post rotated vectors?

The vtkGlyph3D filter should do the trick.

```
vtkNew<vtkArrowSource> glyphSource;
glyphSource->SetShaftRadius(0.03 * RadiusScale);
glyphSource->SetTipRadius(0.1 * RadiusScale);
glyphSource->SetTipLength(TipLengthScale);
glyphSource->Update();

vtkNew<vtkGlyph3D> glyphFilter;
glyphFilter->SetInputData(myInputPoly);
glyphFilter->SetSourceData(glyphSource->GetOutput());
glyphFilter->OrientOn();
glyphFilter->SetScaleFactor(ScaleFactor);
glyphFilter->SetScaleModeToScaleByVector();
glyphFilter->SetColorModeToColorByScale();
glyphFilter->Update();

```

Where myInputPoly provides all the positions of the vectors as well as a 3 component vtkDataArray that gives the vectors. ie: myInputPoly-\>GetPointData()-\>SetScalars();

It may also be sensitive to the name of the array, I can’t remember. In some old code of mine I have it force the name to “Scalars”.

glyphFilter-\>GetOutput() should then give you output poly data of a bunch of arrows copied to the positions of myInputPoly, and oriented by the vectors given by the active scalars.

---

<div class="post-metadata">

**Author:** ![Guillaume\_Gillet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/guillaume_gillet/32/3114_2.png) [@Guillaume\_Gillet](https://discourse.vtk.org/u/Guillaume_Gillet)\
**Post date:** [March 11, 2021, 8:58am UTC](https://discourse.vtk.org/t/rotating-vectors-around-an-axis/5365/3 "2021-03-11T08:58:43Z")

</div>

Ok thank you i’ll try working around that!
