[Chimera-users] Rotation about an axis
Charlie Moad
cwmoad at gmail.com
Tue Apr 11 18:31:31 PDT 2006
On 4/11/06, Jordan Benjamin <jordan.benjamin at gmail.com> wrote:
> I'm trying to rotate a model about a specified axis and origin
> (preferably in global coordinates). I would like the rotation to be
> applied on top of whatever transformations have been applied already.
> I've looked at the documentation, including the programmer's FAQ and
> the source code for ConstrainedMove. I couldn't figure out how to do
> this, so I wrote the following function based on the ConstrainedMove
> code to do the rotation relative to another model:
>
> def rotate_around_model_axis(ref_model, model, origin, axis, angle_deg):
> mvo = apply(chimera.Vector, origin)
> vo = ref_model.openState.xform.apply(mvo)
> mva = apply(chimera.Vector, axis)
> va = ref_model.openState.xform.apply(mva)
>
> xf = chimera.Xform()
> xf.translate(vo)
> xf.rotate(va, angle_deg)
> xf.translate(-vo)
>
> model.openState.globalXform(xf)
>
> But, this doesn't seem to work as I'd intended. Is there a way to do
> this? Also, I'm a little confused about the coordinate system. It
> seems like the concept of a global coordinate system may not apply in
> Chimera the way I'm used to (like in Amira for example) since the
> camera is fixed. Is this true, or am I totally lost? Thanks in advance
> for any help you can provide.
I have very similar code that works. How you derive "vo" seems a bit
strange to me, but it may be that I don't fully understand what you
are doing. I edited the code so it makes a little sense alone.
Basically I rotate modelB by modelA's rotation.
xf = modelA.openState.xform
centerVec = modelB.bbox()[1].center().toVector()
delta = chimera.Xform()
delta.translate(centerVec)
delta.rotate(*xf.getRotation())
centerVec.negate()
delta.translate(centerVec)
modelB.openState.globalXform(delta)
Good luck and I feel your pain. I remember doing a lot of hacking
before I got my desired results.
- Charlie
More information about the Chimera-users
mailing list