问题
I'm working with a program where I visualize molecules. The molecules are represented by multiple x, y, and z values for each atom. What I would like to be able to do, is some math on each coordinate and have the resulting molecule be rotated on one of the axis. I've tried using these formulas:
y' = y*cos q - z*sin q
z' = y*sin q + z*cos q
x' = x
and the corresponding ones for Y and Z axis. In rotations of 180 degrees, the resulting molecule looks fine, but appears to be the enatiomer (mirror image). Any other angle (other than 360) skews the molecules apart from each other.
What I was hoping for was that all atoms would rotate "together". If it matters I'm working in Java.
Thank you for your help
edited code
if (axis == 'X') {
// y' = y*cos q - z*sin q
// z' = y*sin q + z*cos q
// x' = x
y = y * Math.cos(radians) - z * Math.sin(radians);
z = y * Math.sin(radians) + z * Math.cos(radians);
}
else if(axis == 'Y'){
//z' = z*cos q - x*sin q
//x' = z*sin q + x*cos q
//y' = y
z = z * Math.cos(radians) - x * Math.sin(radians);
x = z * Math.sin(radians) + x * Math.cos(radians);
}
else if(axis == 'Z'){
//x' = x*cos q - y*sin q
//y' = x*sin q + y*cos q
//z' = z
x = x * Math.cos(radians) - y * Math.sin(radians);
y = x * Math.sin(radians) + y * Math.cos(radians);
}
edit 2. Found the error. I was calculating the first coordinate value correctly, and assigning it. When I attempt to calculate the second coordinate, I have changed the first coordinate and so get the wrong value for the second one. I'm sorry for the troubles
来源:https://stackoverflow.com/questions/16380147/how-to-rotate-an-object-defined-by-x-y-z-points-around-the-x-y-or-z-axis