You can use a 4 x 4 transformation matrix which is inversible and allows a bi-directional tranformation between the two coordinate systems that you want.
If you know the three rotations a
, b
and g
, about x
, y
, z
respectively, using the right-hand rule. The x0
, y0
, z0
are the translations between the origins of the two coordinate systems.
The transformation matrix is defined as:
T = np.array([[ cos(b)*cos(g), (sin(a)*sin(b)*cos(g) + cos(a)*sin(g)), (sin(a)*sin(g) - cos(a)*sin(b)*cos(g)), x0],
[-cos(b)*sin(g), (cos(a)*cos(g) - sin(a)*sin(b)*sin(g)), (sin(a)*cos(g) + cos(a)*sin(b)*sin(g)), y0],
[ sin(b), -sin(a)*cos(b), cos(a)*cos(b), z0]
[ 0, 0, 0, 1])
To use it efficiently you should put your points in a 2-D array like:
orig = np.array([[x0, x1, ..., xn],
[y0, y1, ..., yn],
[z0, z1, ..., zn],
[ 1, 1, ..., 1]])
Then:
new = T.dot(orig)
will give you the transformed points.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…