[prev in list] [next in list] [prev in thread] [next in thread]
List: paraview
Subject: Re: [Paraview] how to change the position and orientation of arrows in paraview?
From: 骆沛 <areslp () gmail ! com>
Date: 2012-05-30 6:14:43
Message-ID: CADZiFrcjONtV_k86K4R4oa-n9qdu=8BovSkgzq_rFbBB=P3Rrw () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
I got something like this, but it didn't work...It's a python script.
Each line in "D.txt" is a vector b, and I want to transform the default
arrow(vector a) to b's direction.
Firstly I calculate Quaternions to represent the rotation, then I got the
euler angle from the quaternions.
What's wrong with the following code? Please help me! Thanks a lot!!
try: paraview.simple
> except: from paraview.simple import *
> paraview.simple._DisableFirstRenderCameraReset()
> from math import *
> from numpy import *
> from numpy.linalg import *
>
>
> f=open('D.txt')
> for line in iter(f):
> # print line
> items=line.split()
> arrow=Arrow()
> arrow = GetActiveSource()
> arrow.TipRadius = 0.05
> arrow.TipResolution = 32
> arrow.ShaftRadius = 0.01
> arrow.TipLength = 0.2
> arrow.ShaftResolution = 32
> dr=GetDisplayProperties(arrow)
> dr.DiffuseColor = [1.0, 0.0, 0.0]
> dr.Origin = [0.0, 0.0, 0.0]
> dr.Position = [2.69616, 15.2011, -2.68065] # tried with [0,0,0], same
> result
> dr.Scale = [0.02, 0.02, 0.02]
> e=array([1, 0, 0]) #vector a
> print 'e:',e
> u=array([float(items[0]),float(items[1]),float(items[2])]) #vector b
> print 'u:',u
>
>
> v=cross(u,e) #rotation axis
> print 'v:',v
> print 'norm(v):',norm(v)
> v=v/norm(v)
>
> #Quaternions
> print 'u*e:',dot(u,e)
> a=acos(dot(u,e))
> q=array([cos(a/2),sin(a/2)*v[0],sin(a/2)*v[1],sin(a/2)*v[2]])
> print 'q:',q
> q=q/norm(q)
> print 'normalized q:',q
> w=q[0]
> x=q[1]
> y=q[2]
> z=q[3]
>
ax=atan2(2*(w*x+y*z),1-2*(x**2+y**2)) #ax,ay,az are euler angles
> ay=arcsin(2*(w*y-z*x))
> az=atan2(2*(w*z+x*y),1-2*(y**2+z**2))
> print 'ax:',ax,'ay:',ay,'az:',az
> dr.Orientation = [180*ax/pi,180*ay/pi,180*az/pi] #convert to degree
> f.close()
>
> Render()
On Mon, May 28, 2012 at 12:16 PM, 骆沛 <areslp@gmail.com> wrote:
> 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.
>
> --
> Best Regards
> Areslp
>
>
--
Best Regards
Areslp
[Attachment #5 (text/html)]
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>
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the ParaView Wiki at: http://paraview.org/Wiki/ParaView
Follow this link to subscribe/unsubscribe:
http://www.paraview.org/mailman/listinfo/paraview
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic