[vtkusers] give direction to cylinder

Gonzalo Amadio gonzaloamadio at gmail.com
Thu Jul 19 12:47:17 EDT 2012


Yes, that is ok. What I am not sure if the part of what I have to give as
arguments to functions RotateX, RotateY, RotateZ.

I have a director vector, lets call it (a1, a2, a3)  and I want to give the
cylinder that direction. I obtained the angles between a1 and axis X, and
so on.
And give that as argument to RotateX, i.e   RotateX(angle between a1 and
axisX);


2012/7/19 Bill Lorensen <bill.lorensen at gmail.com>

> To rotate about a given point you must
> Translate to the point
> Rotate
> Translate back
>
>
> On Thu, Jul 19, 2012 at 12:25 PM, Gonzalo Amadio <gonzaloamadio at gmail.com>wrote:
>
>> I thought I would solve my problem. But no. Well, in fact the problem is
>> with the rotation.
>> The aim of what I am doing is trying to position the cylinder in such way
>> that is around a line I have.
>> My idea is, positionning it on the center of the line, and then rotating,
>> so it is in the same direction of the line.
>>
>> I have a line segment, which I know
>>
>> originLine[3] = myOrigin;   //origin of the line
>>> dir[3] = myDirection;         //direction of the line
>>> double lengthLine = 10;    //length
>>
>>
>> y could position the cylinder in the center of the line with :
>>
>> double cen[3];
>>> cen[0] = centerTip[0] + dir[0] * (lenght)/2 ;
>>> cen[1] = centerTip[1] + dir[1] * (lenght)/2 ;
>>> cen[2] = centerTip[2] + dir[2] * (lenght)/2 ;
>>
>>
>> Then, the part where I am not sure if it is how it has to be done.
>> I obtain the angles between the dir vector and axis. And pass that angles
>> to RotateX, RotateY, RotateZ.
>>
>> double alpha, beta, gamma; //angles between dir and axis x, y, z
>>> respectively.
>>> double norm;
>>> norm = sqrt (dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2]);
>>>
>>
>>
>> alpha =   acos (dir[0] / norm);
>>> beta =     acos (dir[1] / norm);
>>> gamma = acos (dir[2] / norm);
>>
>>
>>> vtkSmartPointer<vtkTransform> transform =
>>> vtkSmartPointer<vtkTransform>::New();
>>> transform->Translate(-cen[0],-cen[1],-cen[2]);
>>> transform->PostMultiply();
>>> transform->RotateX(alpha);
>>> transform->RotateY(beta);
>>> transform->RotateZ(gamma);
>>> transform->Translate(cen[0],cen[1],cen[2]);
>>>
>>
>>
>> vtkSmartPointer<vtkTransformPolyDataFilter> transF =
>>> vtkSmartPointer<vtkTransformPolyDataFilter>::New();
>>> transF->SetInput(cylinderSource->GetOutput());
>>> transF->SetTransform(transform);
>>> transF->Update();
>>
>>
>> There is no way of setting to the cylinder an origin and end point?, so
>> all this part of the orientation can be avoided.
>>
>> Someone can help me with this? .
>>
>> Thank you!
>>
>>
>>
>> 2012/7/18 David Doria <daviddoria at gmail.com>
>>
>>> On Wed, Jul 18, 2012 at 1:53 PM, Gonzalo Amadio <gonzaloamadio at gmail.com
>>> > wrote:
>>>
>>>> Well, here is my code, now it seems to work .
>>>>
>>>> vtkSmartPointer<vtkCylinderSource> cylinderSource =
>>>>> vtkSmartPointer<vtkCylinderSource>::New();
>>>>> cylinderSource->SetCenter(center[0], center[1], center[2]);
>>>>>
>>>>
>>>>
>>>> vtkSmartPointer<vtkTransform> transform =
>>>>> vtkSmartPointer<vtkTransform>::New();
>>>>>  transform->Translate(-center[0],-center[1],-center[2]);
>>>>> transform->PostMultiply();  //This was the fundamental line, if I
>>>>> have not put this line, the second translation goes to a wrong place.
>>>>> transform->RotateX(90);
>>>>> transform->Translate(centerV[0],centerV[1],centerV[2]);
>>>>>
>>>>
>>>>
>>>> vtkSmartPointer<vtkTransformPolyDataFilter> transF =
>>>>> vtkSmartPointer<vtkTransformPolyDataFilter>::New();
>>>>> transF->SetInput(cylinderSource->GetOutput());
>>>>> transF->SetTransform(transform);
>>>>> transF->Update();
>>>>>
>>>>
>>>>
>>>> vtkSmartPointer<vtkPolyData> cylinder = transF->GetOutput();
>>>>
>>>>
>>> You may find Lecture 2: Transforms from here:
>>> http://www.vtk.org/Wiki/VTK/Presentations
>>>
>>> useful as well, but it seems you've already solved the problem.
>>>
>>> David
>>>
>>
>>
>>
>> --
>> --------
>> Gonzalo Amadio
>>
>>
>> _______________________________________________
>> 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
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
>
>
> --
> Unpaid intern in BillsBasement at noware dot com
>
>


-- 
--------
Gonzalo Amadio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120719/125f4410/attachment.htm>


More information about the vtkusers mailing list