[vtkusers] Align vtk cylinder source to a given vector

Bill Lorensen bill.lorensen at gmail.com
Tue Dec 13 10:48:11 EST 2016


The arrow source is originally aligned with the x-axis, The cylinder source
is aligned with the y-axis. Also the cylinder origin is different. Replace
the transform with

 vtkSmartPointer<vtkTransform> transform =
    vtkSmartPointer<vtkTransform>::New();
  transform->Translate(startPoint);
  transform->Concatenate(matrix);
  transform->Scale(length, length, length);
  transform->RotateZ(-90.0); // orient along x axis
  transform->Translate(0, .5, 0); // translate to end of cylinder


On Tue, Dec 13, 2016 at 10:15 AM, M. Jordan <mjordan at live.at> wrote:

> Thank you very much!
> The example works fine, but when I change the source from arrow to
> cylinder the result is strange (not aligned).
> I don't know why
>
> ------------------------------
> *Von:* Bill Lorensen <bill.lorensen at gmail.com>
> *Gesendet:* Dienstag, 13. Dezember 2016 15:23
> *An:* Cory Quammen
> *Cc:* VTK Users; M. Jordan
> *Betreff:* Re: [vtkusers] Align vtk cylinder source to a given vector
>
> This example may help
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/OrientedArrow
> VTK/Examples/Cxx/GeometricObjects/OrientedArrow ...
> <http://www.vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/OrientedArrow>
> www.vtk.org
> Download and Build OrientedArrow. Click here to download OrientedArrow.
> and its CMakeLists.txt file. Once the tarball OrientedArrow.tar has been
> downloaded and extracted,
>
>
> On Dec 13, 2016 9:13 AM, "Cory Quammen" <cory.quammen at kitware.com> wrote:
>
>> Here's a sketch of how to do this in VTK:
>>
>> * Find the cross product h between the normalized default cylinder
>> axis c and your normalized direction vector v.
>> * Now compute theta = acos(d) where d is the dot product of c and v.
>> theta is the rotation angle about h you need to rotate the cylinder to
>> the direction vector.
>> * Use vtkTransformFilter with the transform set to a vtkTransform
>> where you have called vtkTransform::RotateWXYZ (double angle, double
>> x, double y, double z). theta is in radians, but angle is expected to
>> be in degrees, so you'll need to convert.
>>
>> Hope that helps,
>> Cory
>>
>> On Tue, Dec 13, 2016 at 6:33 AM, M. Jordan <mjordan at live.at> wrote:
>> > Hi,
>> >
>> > i have a cylinder and a given direction vector. Now I want to align the
>> > cylinder along that vector.
>> > How can I do this?
>> >
>> > Thank you!
>> >
>> >
>> > _______________________________________________
>> > Powered by www.kitware.com
>> >
>> > Visit other Kitware open-source projects at
>> > http://www.kitware.com/opensource/opensource.html
>> >
>> > Please keep messages on-topic and check the VTK FAQ at:
>> > http://www.vtk.org/Wiki/VTK_FAQ
>> >
>> > Search the list archives at: http://markmail.org/search/?q=vtkusers
>> >
>> > Follow this link to subscribe/unsubscribe:
>> > http://public.kitware.com/mailman/listinfo/vtkusers
>> >
>>
>>
>>
>> --
>> Cory Quammen
>> Staff R&D Engineer
>> Kitware, Inc.
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>>
>


-- 
Unpaid intern in BillsBasement at noware dot com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20161213/13e72f2a/attachment.html>


More information about the vtkusers mailing list