0

Intro I have been researching this topic for a while, however do not entirely grasp it. I have looked on stackoverflow as well as other on-line resources for an example, but couldn't find a fairly similar problem to refer to. Any help would be very much appreciated.

To reduce the amount of duplicates, please notify me if there is such question already answered so I can remove this question;

Objective: Rotate a point [ x,y,z ] in 3D space around an origin using rotation matrices;

Problem specification: Insufficient level of understanding in the above topic. Uncertainty in the implementation;

Reference: http://en.wikipedia.org/wiki/Rotation_matrix

Code structure:

class RotationMatrix{
        private double theta; // Rotiation angle;
        private double rotateX[][] = {{1,0,0},{0,Math.cos(theta),-Math.sin(theta)},{0,Math.sin(theta),Math.cos(theta)}};   // Rotation matrice for x axis;
        private double rotateY[][] = {{Math.cos(theta),0,Math.sin(theta)},{0,1,0},{-Math.sin(theta),0,Math.cos(theta)}};   // Rotation matrice for y axis;
        private double rotateZ[][] = {{Math.cos(theta),-Math.sin(theta),0},{Math.sin(theta),Math.cos(theta),0},{0,0,1}};   // Rotation matrice for z axis;

    // Method to rotate point in interest in 3D [ x,y,z ];
    public void Rotate3D(Node n,double[] point){             // Method to be called (Node n to provide direction N/E/U) and array[] point to provide the coordinates of the point in interest;


            if(n.getN() == 1){                                 
                while(theta != 6.28318531){                           // Rotate by 90 degrees till theta != 360;
                    theta += 1.57079633;
                // do rotation around 'y' axis;
                }
            }
            else if(n.getE() == 1){                         
                while(theta != 6.28318531){                        // Rotate by 90 degrees till theta != 360;
                    theta += 1.57079633;
                // do rotation around 'x' axis;
                }
            }
            else if(n.getU() == 1){
                while(theta != 6.28318531){                        // Rotate by 90 degrees till theta != 360;
                    theta += 1.57079633;
                // do rotation around 'z' axis;
                }
            } else {
                System.out.println("The rotation has failed \n"
                        + "The direction data is missing...");
            }
        }
    }
e.doroskevic
  • 2,129
  • 18
  • 25
  • Could you indicate what is the issue you are facing and evidences (i.e. output on screen, expected output, exception if any...) – Grimmy Dec 11 '13 at 14:53
  • @Grimmy the issue - please refer to the objective section of this question. There is no working code - due to the reason which I have specified above. I require enlightenment in the above topic in order to modify the existing code frame in accordance to the objective specified above. A worked through example would be very much appreciated. – e.doroskevic Dec 11 '13 at 14:58
  • 1
    Note : This is not any type of a homework. – e.doroskevic Dec 11 '13 at 15:01
  • 2
    the cosine function takes an argument in radians NOT degrees. [documentaion](http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Math.html#cos(double)). So theta should be an angle in radians of data type double. – dataNinja124 Dec 11 '13 at 15:02
  • Rotation is a 2D operation. You can rotate something in the XY plane, the XZ plane, or the YZ plane, but there is no such thing as a single-angle 3D rotation. That may be a source of some of your confusion. What is your desired output given the point 1,1,1 and the rotation angle of 90 degrees? – Pace Dec 11 '13 at 15:25
  • @Pace thank you for you reply. I would like to preserve data from each rotation so I can print it out in a user friendly manner at the later stage. Perhaps you are right - I thought of basic rotations for Rx(theta),Ry(theta),Rz(theta) taken from the reference I supplied above. – e.doroskevic Dec 11 '13 at 15:31
  • Ok. So one approach, which sounds like what you're thinking, is called Euler angles. Your input is 3 different angles (3 thetas), one for the YZ plane (Rx(theta_x)), one for the XZ plane (Ry(theta_y)), and one for the XY plane (Rz(theta_z)). You then take your origin point and multiply it by the Rx matrix, then by the Ry matrix, then by the Rz matrix. The final point is your result. Is this what you would like to do? – Pace Dec 11 '13 at 16:07
  • @Pace I apologise for all the confusion. What I need to do is to produce a rotation about one of the axis [x,y,z] in Coordinate system. There are three rotation matrices that I have found in the reference I provide above. These matrices are consider basic or elemental rotation matrices. It is my understanding that I have to put coordinates of the point in interest into a column vector and then multiply this column vector with one of the matrices I've defined in my code sample; – e.doroskevic Dec 11 '13 at 16:18

0 Answers0