To rotate about a given point you must<br>Translate to the point<br>Rotate<br>Translate back<br><br><br><div class="gmail_quote">On Thu, Jul 19, 2012 at 12:25 PM, Gonzalo Amadio <span dir="ltr">&lt;<a href="mailto:gonzaloamadio@gmail.com" target="_blank">gonzaloamadio@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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"><div class="im">
<br>vtkSmartPointer&lt;vtkTransform&gt; transform = vtkSmartPointer&lt;vtkTransform&gt;::New();<br></div>

transform-&gt;Translate(-cen[0],-cen[1],-cen[2]);<br>transform-&gt;PostMultiply();<br>transform-&gt;RotateX(alpha);<br>transform-&gt;RotateY(beta);<br>transform-&gt;RotateZ(gamma);<br>transform-&gt;Translate(cen[0],cen[1],cen[2]);<br>


</blockquote><div class="im"><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&lt;vtkTransformPolyDataFilter&gt; transF = vtkSmartPointer&lt;vtkTransformPolyDataFilter&gt;::New();<br>transF-&gt;SetInput(cylinderSource-&gt;GetOutput());<br>transF-&gt;SetTransform(transform);<br>transF-&gt;Update(); </blockquote>


</div></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!<div>
<div class="h5"><br><br>
<br>
<div class="gmail_quote">2012/7/18 David Doria <span dir="ltr">&lt;<a href="mailto:daviddoria@gmail.com" target="_blank">daviddoria@gmail.com</a>&gt;</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>On Wed, Jul 18, 2012 at 1:53 PM, Gonzalo Amadio <span dir="ltr">&lt;<a href="mailto:gonzaloamadio@gmail.com" target="_blank">gonzaloamadio@gmail.com</a>&gt;</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&lt;vtkCylinderSource&gt; cylinderSource = vtkSmartPointer&lt;vtkCylinderSource&gt;::New();<br></div>


cylinderSource-&gt;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&lt;vtkTransform&gt; transform = vtkSmartPointer&lt;vtkTransform&gt;::New();<br>



</div>


transform-&gt;Translate(-center[0],-center[1],-center[2]);<br>transform-&gt;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-&gt;RotateX(90);<br>transform-&gt;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&lt;vtkTransformPolyDataFilter&gt; transF = vtkSmartPointer&lt;vtkTransformPolyDataFilter&gt;::New();<br>






transF-&gt;SetInput(cylinderSource-&gt;GetOutput());<br>transF-&gt;SetTransform(transform);<br>transF-&gt;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&lt;vtkPolyData&gt; cylinder = transF-&gt;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&#39;ve already solved the problem.<span><font color="#888888"><br>
<br></font></span></div><span><font color="#888888"><div class="gmail_quote">David</div>
</font></span></blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br>--------<br>Gonzalo Amadio<br><br>
</font></span></div></div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Unpaid intern in BillsBasement at noware dot com<br><br>