Given an arbitrary number of points which lie on the surface of a unit sphere, one of which is arbitrarily <0, 0, 1> (which I will call K) in a rotated system (i.e. the rotation matrix is unknown), I'm trying to figure out how to (un-)rotate it so that the given point is <0, 0, 1> in the origin system.
The original method I came up with is to find the angle between the x and z components of K and rotating around the y-axis by that value:
double yrot = Math.atan2(point[0], point[2]);
for (int i = 0; i < p0.length; i++) {
double[] p = p0[i];
p0[i][0] = p[0] * Math.cos(theta) - p[2] * Math.sin(theta);;
p0[i][2] = p[0] * Math.sin(theta) + p[2] * Math.cos(theta);
}
Then to find the angle between the y and z components of K and rotating around the x-axis by that value:
double xrot = Math.atan2(point[1], point[2]);
for (int i = 0; i < p0.length; i++) {
double[] p = p0[i];;
p0[i][1] = p[1] * Math.cos(theta) - p[2] * Math.sin(theta);
p0[i][2] = p[1] * Math.sin(theta) + p[2] * Math.cos(theta);
}
This works great except for one issue: The magnitude of any of the points are no longer 1.
Where am I going wrong here?
In the above code blocks, p0 refers to the system of points while point refers to K.