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.<div><br></div><div>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.</div>
<div>And give that as argument to RotateX, i.e RotateX(angle between a1 and axisX);</div><div><br></div><div><br><div class="gmail_quote">2012/7/19 Bill Lorensen <span dir="ltr"><<a href="mailto:bill.lorensen@gmail.com" target="_blank">bill.lorensen@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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">
<div><div class="h5">On Thu, Jul 19, 2012 at 12:25 PM, Gonzalo Amadio <span dir="ltr"><<a href="mailto:gonzaloamadio@gmail.com" target="_blank">gonzaloamadio@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><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>
<br>vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();<br></div>
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><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(); </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><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>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><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><font color="#888888">-- <br>--------<br>Gonzalo Amadio<br><br>
</font></span></div></div>
<br></div></div><div class="im">_______________________________________________<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></div></blockquote></div><div class="HOEnZb"><div class="h5"><br><br clear="all"><br>-- <br>Unpaid intern in BillsBasement at noware dot com<br><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>--------<br>Gonzalo Amadio<br><br>
</div>