<div>I thought I would solve my problem. But no. Well, in fact the problem is with the rotation.</div><div>The aim of what I am doing is trying to position the cylinder in such way that is around a line I have.</div><div>My idea is, positionning it on the center of the line, and then rotating, so it is in the same direction of the line.</div>
<div><br></div><div>I have a line segment, which I know</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
originLine[3] = myOrigin; //origin of the line<br>dir[3] = myDirection; //direction of the line<br>double lengthLine = 10; //length</blockquote><div><br></div><div>y could position the cylinder in the center of the line with : </div>
<div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">double cen[3];<br>cen[0] = centerTip[0] + dir[0] * (lenght)/2 ;<br>
cen[1] = centerTip[1] + dir[1] * (lenght)/2 ;<br>cen[2] = centerTip[2] + dir[2] * (lenght)/2 ;</blockquote></div><div><br></div><div>Then, the part where I am not sure if it is how it has to be done.</div><div>I obtain the angles between the dir vector and axis. And pass that angles to RotateX, RotateY, RotateZ.</div>
<div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">double alpha, beta, gamma; //angles between dir and axis x, y, z respectively.<br>
double norm;<br>norm = sqrt (dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2]);<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">alpha = acos (dir[0] / norm);<br>beta = acos (dir[1] / norm);<br>
gamma = acos (dir[2] / norm);</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();<br>
transform->Translate(-cen[0],-cen[1],-cen[2]);<br>transform->PostMultiply();<br>transform->RotateX(alpha);<br>transform->RotateY(beta);<br>transform->RotateZ(gamma);<br>transform->Translate(cen[0],cen[1],cen[2]);<br>
</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
vtkSmartPointer<vtkTransformPolyDataFilter> transF = vtkSmartPointer<vtkTransformPolyDataFilter>::New();<br>transF->SetInput(cylinderSource->GetOutput());<br>transF->SetTransform(transform);<br>transF->Update(); </blockquote>
</div><div><br></div><div>There is no way of setting to the cylinder an origin and end point?, so all this part of the orientation can be avoided.</div><br>Someone can help me with this? .<div><br><div>Thank you!<br><br>
<br>
<div class="gmail_quote">2012/7/18 David Doria <span dir="ltr"><<a href="mailto:daviddoria@gmail.com" target="_blank">daviddoria@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_quote"><div class="im">On Wed, Jul 18, 2012 at 1:53 PM, Gonzalo Amadio <span dir="ltr"><<a href="mailto:gonzaloamadio@gmail.com" target="_blank">gonzaloamadio@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Well, here is my code, now it seems to work .<br><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>
vtkSmartPointer<vtkCylinderSource> cylinderSource = vtkSmartPointer<vtkCylinderSource>::New();<br></div>
cylinderSource->SetCenter(center[0], center[1], center[2]);<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();<br>
</div>
transform->Translate(-center[0],-center[1],-center[2]);<br>transform->PostMultiply(); <font color="#ff0000">//This was the fundamental line, if I have not put this line, the second translation goes to a wrong place.</font><br>
transform->RotateX(90);<br>transform->Translate(centerV[0],centerV[1],centerV[2]);<br></blockquote><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">vtkSmartPointer<vtkTransformPolyDataFilter> transF = vtkSmartPointer<vtkTransformPolyDataFilter>::New();<br>
transF->SetInput(cylinderSource->GetOutput());<br>transF->SetTransform(transform);<br>transF->Update();<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">vtkSmartPointer<vtkPolyData> cylinder = transF->GetOutput();</blockquote>
</div></blockquote><div><br></div></div><div>You may find Lecture 2: Transforms from here:</div><a href="http://www.vtk.org/Wiki/VTK/Presentations" target="_blank">http://www.vtk.org/Wiki/VTK/Presentations</a><br clear="all">
<br>useful as well, but it seems you've already solved the problem.<span class="HOEnZb"><font color="#888888"><br>
<br></font></span></div><span class="HOEnZb"><font color="#888888"><div class="gmail_quote">David</div>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>--------<br>Gonzalo Amadio<br><br>
</div></div>