I got something like this, but it didn't work...It's a python script.<br>Each line in "D.txt" is a vector b, and I want to transform the default arrow(vector a) to b's direction.<br>Firstly I calculate Quaternions to represent the rotation, then I got the euler angle from the quaternions.<br>
What's wrong with the following code? Please help me! Thanks a lot!!<br><br><blockquote style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">try: paraview.simple<br>
except: from paraview.simple import *<br>paraview.simple._DisableFirstRenderCameraReset()<br>from math import *<br>from numpy import *<br>from numpy.linalg import *<br><br><br>f=open('D.txt')<br>for line in iter(f):<br>
# print line<br> items=line.split()<br> arrow=Arrow()<br> arrow = GetActiveSource()<br> arrow.TipRadius = 0.05<br> arrow.TipResolution = 32<br> arrow.ShaftRadius = 0.01<br> arrow.TipLength = 0.2<br>
arrow.ShaftResolution = 32<br> dr=GetDisplayProperties(arrow)<br> dr.DiffuseColor = [1.0, 0.0, 0.0]<br> dr.Origin = [0.0, 0.0, 0.0]<br> dr.Position = [2.69616, 15.2011, -2.68065] # tried with [0,0,0], same result<br>
dr.Scale = [0.02, 0.02, 0.02]<br> e=array([1, 0, 0]) #vector a<br> print 'e:',e<br> u=array([float(items[0]),float(items[1]),float(items[2])]) #vector b<br> print 'u:',u<br><br><br> v=cross(u,e) #rotation axis<br>
print 'v:',v<br> print 'norm(v):',norm(v)<br> v=v/norm(v)<br><br> #Quaternions<br> print 'u*e:',dot(u,e)<br> a=acos(dot(u,e))<br> q=array([cos(a/2),sin(a/2)*v[0],sin(a/2)*v[1],sin(a/2)*v[2]])<br>
print 'q:',q<br> q=q/norm(q)<br> print 'normalized q:',q<br> w=q[0]<br> x=q[1]<br> y=q[2]<br> z=q[3]<br></blockquote>
ax=atan2(2*(w*x+y*z),1-2*(x**2+y**2)) #ax,ay,az are euler angles<br><blockquote style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"> ay=arcsin(2*(w*y-z*x))<br>
az=atan2(2*(w*z+x*y),1-2*(y**2+z**2))<br> print 'ax:',ax,'ay:',ay,'az:',az<br> dr.Orientation = [180*ax/pi,180*ay/pi,180*az/pi] #convert to degree<br>
f.close()<br><br>Render()</blockquote><br><br><div class="gmail_quote">On Mon, May 28, 2012 at 12:16 PM, 骆沛 <span dir="ltr"><<a href="mailto:areslp@gmail.com" target="_blank">areslp@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I add an arrow in Sources, but I don't find the place to set the position and orientation of the arrow...
Could anyone tell me how can I do this?
I use paraview3.14 version.<span class="HOEnZb"><font color="#888888"><br clear="all"><br>-- <br>Best Regards<br>Areslp<br><br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br>Best Regards<br>Areslp<br><br>