Differences between revisions 3 and 8 (spanning 5 versions)
Revision 3 as of 2008-09-05 20:31:43
Size: 1764
Comment:
Revision 8 as of 2008-09-05 20:48:41
Size: 3042
Comment:
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
{{{$$Transform \equiv M T S R $$}}} {{{$$ Tr \equiv M T S R $$}}}
Line 9: Line 9:
Where {{{$$M }}} is a mirroring operation about the x-axis, {{{$$T} }}} is a translation, {{{$$S$$}}} is a uniform, positive, non zero scaling operation and {{{$$R$$}}} is a rotation. The Transformobject stores these transformations internally in a 4x4 matrix, as is commonly the case in computer graphics applications that use homogeneous coordinate systems (i.e. OpenGL). In these approaches the 4x4 transformation matrix {{{$$X$$}}} is constructed in this way Where {{{$$M$$}}} is a mirroring operation about the x-axis, {{{$$T$$}}} is a translation, {{{$$S$$}}} is a uniform, positive, non zero scaling operation and {{{$$R$$}}} is a rotation. The Transformobject stores these transformations internally in a 4x4 matrix, as is commonly the case in computer graphics applications that use homogeneous coordinate systems (i.e. OpenGL). In these approaches the 4x4 transformation matrix is constructed in this way
Line 11: Line 11:
{{{$$ Transform = [[sMR,M\mathbf{t}],[\mathbf{0}^T,1]]$$}}} {{{$$ Tr = [[sMR,M\mathbf{t}],[\mathbf{0}^T,1]]$$}}}
Line 15: Line 15:
{{{$$ Transform \mathbf{p}_{hc} = ( (sMR\mathbf{p} + M\mathbf{t})^T, 1 )^T $$}}} {{{$$ Tr \mathbf{p}_{hc} = ( (sMR\mathbf{p} + M\mathbf{t})^T, 1 )^T $$}}}
Line 17: Line 17:
In this way the result of applying a Transform is a rotation followed by scaling operation, followed by a translation and then finally the x mirroring operation is (optionally) applied. In this way the result of applying a Transform is a rotation followed by a scaling, followed by a translation and then finally the x mirroring operation is (optionally) applied.
Line 19: Line 19:
= Constructing a Transform = = The Transforms object in Python =

== Constructing a Transform ==

There a three ways to construct a Transform object in Python

{{{#!python
t = Transform() # default constructor, t is the identity
t = Transform({"type":"eman","az":10,"alt":150,"scale":2.0,"mirror":True,"dx":3.4}) # construction using a dictionary
s = Transform(t) # copy construction - s is precisely the same as t
}}}

== Setting/getting rotations ==

{{{#!python
t = Transform()
t.set_rotation({"type":"spider","phi":32,"theta":12,"psi":-100})
spider_rot = t.get_rotation("spider")
eman_rot = t.get_rotation("eman")
s = Transform(eman_rot) # works fine
}}}

== Setting/getting scale ==

{{{#!python
t = Transform()
t.set_scale(2.0)
scale = t.get_scale()
s = Transform({"scale":scale}) # set scale as part of construction
}}}

== Setting/getting mirror ==


{{{#!python
t = Transform()
t.set_mirror(2.0)
mirror = t.get_mirror()
s = Transform({"mirror":mirror}) # set mirror as part of construction
}}}

== Setting/getting translation ==

{{{#!python
t = Transform()
t.set_trans(1,2,3) # method 1
t.set_trans(Vec3f(1,2,3)) # method 2
t.set_trans([1,2,3]) # method 3 - the tuple is converted to a Vec3f automatically
v = t.get_trans()
s = Transform("dx":v[0],"dy":v[1],"dz":v[2]) # set translation as part of construction
}}}

TableOfContents

What is a Transform?

We use the [http://blake.bcm.edu/eman2/doxygen_html/classEMAN_1_1Transform.html Transform] class for storing/managing Euler angles,translations, scales and x mirroring. At any time a Transform object defines a group of 4 transformations of a rigid body that are applied in a specific order, namely

$$ Tr \equiv M T S R $$

Where $$M$$ is a mirroring operation about the x-axis, $$T$$ is a translation, $$S$$ is a uniform, positive, non zero scaling operation and $$R$$ is a rotation. The Transformobject stores these transformations internally in a 4x4 matrix, as is commonly the case in computer graphics applications that use homogeneous coordinate systems (i.e. OpenGL). In these approaches the 4x4 transformation matrix is constructed in this way

$$ Tr = [[sMR,M\mathbf{t}],[\mathbf{0}^T,1]]$$

Where $$s$$ is the constant scaling factor, $$M$$ is the option x-mirroring operation which identity, except in the case of x mirroring where the (0,0) entry is -1, $$R$$ is a $$3x3$$ rotation matrix and $$\mathbf{t}=(dx,dy,dz)^T$$ is a post translation. In this approach a 3D point $$\mathbf{p}=(x,y,z)^T$$ as represented in homogeneous coordinates as a 4D vector $$\mathbf{p}_{hc}=(x,y,z,1)^T$$ and is multiplied by the matrix $$M$$ to produce the result of applying the transformation

$$ Tr \mathbf{p}_{hc} = ( (sMR\mathbf{p} +  M\mathbf{t})^T, 1 )^T $$

In this way the result of applying a Transform is a rotation followed by a scaling, followed by a translation and then finally the x mirroring operation is (optionally) applied.

The Transforms object in Python

Constructing a Transform

There a three ways to construct a Transform object in Python

   1 t = Transform() # default constructor, t is the identity
   2 t = Transform({"type":"eman","az":10,"alt":150,"scale":2.0,"mirror":True,"dx":3.4}) # construction using a dictionary
   3 s = Transform(t) # copy construction - s is precisely the same as t

Setting/getting rotations

   1 t = Transform()
   2 t.set_rotation({"type":"spider","phi":32,"theta":12,"psi":-100})
   3 spider_rot = t.get_rotation("spider")
   4 eman_rot = t.get_rotation("eman")
   5 s = Transform(eman_rot) # works fine

Setting/getting scale

   1 t = Transform()
   2 t.set_scale(2.0)
   3 scale = t.get_scale()
   4 s = Transform({"scale":scale}) # set scale as part of construction

Setting/getting mirror

   1 t = Transform()
   2 t.set_mirror(2.0)
   3 mirror = t.get_mirror()
   4 s = Transform({"mirror":mirror}) # set mirror as part of construction

Setting/getting translation

   1 t = Transform()
   2 t.set_trans(1,2,3) # method 1
   3 t.set_trans(Vec3f(1,2,3)) # method 2
   4 t.set_trans([1,2,3]) # method 3 - the tuple is converted to a Vec3f automatically
   5 v = t.get_trans()
   6 s = Transform("dx":v[0],"dy":v[1],"dz":v[2]) # set translation as part of construction

EMAN2/TransformInPython (last edited 2023-09-29 12:51:26 by SteveLudtke)