|
Sure, but its tricky. All these transforms are do'able as matrices, so you
end up with three transforms.
Let P be the matrix ( X
Y
Z )
Then there is a matrix ( -Ox 0 0
0 -Oy 0
0 0 -Oz ) that maps the centre of your
desired rotation to the origin,
a matrix ( ???? ) that does the 3D rotation about
the origin,
a matrix ( Ox 0 0
etc ) that maps the origin back to the
centre of rotation.
Now just multiply the three together (in the correct order!) to get a single
3x3 matrix that will do the rotation around the desired place. The only
problem is the ( ???? ) matrix. That should be easily calculatable, but I'd
have to think about it 'off line' for a few minutes. It'll be something like
( cos A sin B, ...
... )
/Bevin
|
| A general way of viewing rotates (in 2 or more dimensions) is that
you must choose a plane oriented in some way to rotate in. Rotating
points in that plane will effect only coordinates lying in that plane
and not any others orthogonal to it.
Thus to rotate in the (x,y) plane about the z axis you would have
x' = x*cos - y*sin
y' = y*cos + x*sin
z' = z
Or in matrix notation
| cos -sin 0 |
{x',y',z'} = | sin cos 0 | * {x,y,z}
| 0 0 1 |
Any orientation of an object (due to some combination of rotations) can
be expressed as a single orthonormal matrix which transforms coordinates
in the rotated frame of reference to some other frame of reference
(say from {x,y,z} to {x',y',z'}.
To transform from the {x',y',z'} system back to the {x,y,z} system you
would need to multiply the primed coordinates by the inverse of the
orthonormal matrix, which turns out to be simply its transpose.
You can see this by noting that an orthogonal matrix is a set of
normal vectors with unity magnitude.
Note that rotates are not commutative.
If you really need to represent the orientation of some object, I'd
recommend doing it as a 3 by 3 orthonormal matrix, rather than
3 angles (such as roll, pitch, yaw). This is because the (roll, pitch,
yaw) representation can come up against singularities (like the way
longitude lines on a globe converge at the poles). Back in school
I wrote a 3-D spacewar for the PDP-12 and made that mistake: ships
pointing nearly up or down would briefly spin on their axis until
they were orientated away from the poles. You can attemp to correct
this with expressions derived from tensors, but if the high-order
derivatives are large enough the problem will still reappear.
The problem with the unit matrix is that continuously modifying its
entries with successive rotates can lead to roundoff errors, making
the matrix non-orthonormal after a time. You can do a periodic
Gram-Schmidt orthogonalization to fix that though.
There is another interesting way of representing object orientations based
on quaternions, but I haven't used it; it would be worth looking at.
- Jim
|
| Actually, if it isn't a "pure" translation, then there's some "fixed" point,
which can be considered as the center of the rotation. However, determining
this fixed point is a nuisance, so follow Brett's suggestion with a translate,
if needed.
|
| The clean way to deal with the translation is to use homogenous coordinates.
(Equivalently, you look at Euclidian space as a subset of projective space.)
This works as follows: Projective n-space is the set of (n+1)-tuples
(a0,a1,...,an). However, if r is any non-zero real, we identify
(a0,a1,...,an) with (ra0,ra1,...,ran). (So really projective n-space is a
set of equivalence classes of (n+1)-tuples. To make my later comments rigor-
ous, it's simple to see how to represent Pn as a quotient space of En+1, Eu-
clidean (n+1)-space.)
Write a=(a0,a1,...,an). If a, b are vectors in Pn (n-d projective space),
a+b, a-b, and ra, for r any real, are defined element-wise. It's clear that
these are well-defined e.g., the sums of things in a given pair of equivalence
classes are in the same equivalence class.
If a0 is non-zero, then there is a unique element in its equivalence class of
the form (1,b1,b2,...,bn). It's clear that {(1,b1,...,bn)}, with "+", "-",
and scalar multiplication re-defined to "re-normalize" the result back to a
representative with first element 1, gives us just n-d Euclidean space. (You
do have to make multiplication by 0 work right if you want a full definition.)
(The equivalence classes with first coordinate 0 act like "points at infini-
ty", hence the name "projective spaces".)
Now consider (n+1) X (n+1) matrices acting on Pn, and what effect they have on
the Euclidean subspace we found. For simplicity, I'll take n=2, but what I
do obviously extends.
1 0 0 1 1
0 a b x x = ax+by compare: a b . x = ax+by
0 c d y cx+dy c d y cx+dy
Hence, rotation and scaling - representable as matrix multiplication over
En (Euclidean n-space) - can be effected for the image of En in Pn by the
usual action of matrices on Pn - by embedding the n X n matrices that act on
En into the (n+1) x (n+1) matrices that act on Pn. (Since scalar multiplica-
tion commutes with matrix multiplication, it's clear that matrix multiplica-
tion is well-defined over Pn.)
But now for the kicker. Consider:
1 0 0 1 1
a 1 0 x x = a+x compare: a + x = a+x
b 0 1 y b+y b y b+y
That is, translation in En is ALSO representable by a matrix multiplication
over Pn. To combine any number of rotations and translations, simply write
them out as matrices acting on Pn and multiply them together.
-- Jerry
|