   Volume slice orientation.
  I have three stacks of images in which I need to display within an rectangular area. Each stack is oriented perpendicular towards one of the axis (x,y,z). Depending on the viewing angle, I need to switch the stack to  be the most perpendicular to the viewing direction. I have managed to get it semi working. However, the algorithm I am using only seems to only work correctly when solely rotating around a single axis. Ie: I can rotate around the X axis fine. However, if I rotate 25 degree's along the X axis and then 90 degress along the Y axis the wrong stack is chosen. The following C# code is a snippet of the algorithm I am using to determine the viewing direction. I'm open for any suggestions, and corrections to my math.// I'm using my camera eye as the view vector. Vector4 vV = new Vector4(cameraEye.X, cameraEye.Y, cameraEye.Z, 0);  int quadrant = 0;float[] result = new float[3];// Where MultMatrix(Matrix mat, Vector4 vec) multiplies an matrix and a vector4.// Rotation represents the rotation matrix of the object.result[0] = Vector4.Dot(MultMatrix(Rotation, new Vector4(1, 0, 0, 0)), vV);result[1] = Vector4.Dot(MultMatrix(Rotation, new Vector4(0, 1, 0, 0)), vV);result[2] = Vector4.Dot(MultMatrix(Rotation, new Vector4(0, 0, 1, 0)), vV);// Determines which quadrant the result falls in.if (Math.Abs(result[0]) > Math.Abs(result[1])){    if (Math.Abs(result[0]) > Math.Abs(result[2]))   quadrant = 0;else   quadrant = 2;}else{    if (Math.Abs(result[1]) > Math.Abs(result[2]))    quadrant = 1;    else    quadrant = 2;}
  What you have looks correct.  Maybe the problem is elsewhere in your code.  Is there a problem when the view direction has you looking on the "back-side" of the 3D image object?  What you decide is wrong visually might be a matter of processing the image slices in the reverse order of what you were expecting.Rather than compute result[] the way you do, notice that if R is a rotation and V is the view direction, result = Transpose(R)*V.  Your code then determines the largest magnitude component for the first three components of 'result'.  (Your code is designed to map vV into the original coordinate system of the image object, so you are applying the inverse of the rotation applied to the image object.  (This avoids the verbose "new" calls to extract the columns of Rotation.);Quote:Original post by Wasting TimeWhat you have looks correct.  Maybe the problem is elsewhere in your code.  Is there a problem when the view direction has you looking on the "back-side" of the 3D image object?  What you decide is wrong visually might be a matter of processing the image slices in the reverse order of what you were expecting.Rather than compute result[] the way you do, notice that if R is a rotation and V is the view direction, result = Transpose(R)*V.  Your code then determines the largest magnitude component for the first three components of 'result'.  (Your code is designed to map vV into the original coordinate system of the image object, so you are applying the inverse of the rotation applied to the image object.  (This avoids the verbose "new" calls to extract the columns of Rotation.)I do account for the reverse sorting of the slices. I just clipped that portion of the code out for the post. I don't have the code in front of me right now. But for instance I am able to rotate the X and Y Axis slightly. Then when I rotate the Z axis it will flip between the correct group of slices and an incorrect group of slices. Because of the angle and its position, it should actually not change stacks during the rotation. It seems to be happening only when all three axis are not equal to 0. If I spin the object around the x, y, or z axis alone it looks correct. I will double check that this is not a problem, and take your optimization into account. Thanks for the suggestion.Basically I think something is backwards somewhere. There are times when the quadrant value is changing when it should be constant, and times when its staying constant when it shouldn't be.  Everything works good when rotating the volume in a single direction.[Edited by - Billr17 on June 20, 2006 9:13:41 AM];  Actually the reason things seem backwards is because I don't need the transpose. The entire thing can be simplified to result = R*V. Now it works correctly. :-) Thanks.   