[vtkusers] give direction to cylinder
Gonzalo Amadio
gonzaloamadio at gmail.com
Thu Jul 19 12:25:38 EDT 2012
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120719/d967949a/attachment.htm>
More information about the vtkusers
mailing list