Advertisement
Luninariel

289 - Rotation Matrix Z

Apr 8th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. //
  2. //  RotationMatrixZ.java
  3. //  Easel
  4. //
  5. //  Created by Philip Rhodes on 7/29/05.
  6. //  Copyright 2005 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. /** This class represents matrices that rotate vertices around the z axis.
  10.   * according to the "right hand rule".
  11.   */
  12. public class RotationMatrixZ extends RotationMatrix{
  13.  
  14.    /** Constructs a rotation matrix with rotation angle 0. */
  15.    public RotationMatrixZ(){
  16.       // The default constructor will set this matrix
  17.       // equal to the identity, so do nothing here.
  18.    }
  19.  
  20.    /** Construct a matrix that will rotate vertices around the z axis by the
  21.     *  angle theta, expressed in radians."
  22.     */
  23.    RotationMatrixZ(double theta){
  24.      // Write me!
  25.       float  [][] rotationx_matrix =
  26.               {{(float)Math.cos(theta),  -(float)Math.sin(theta),    0.0f,                    0.0f},
  27.               {(float)Math.sin(theta),    (float)Math.cos(theta),    0.0f,                    0.0f},
  28.               {0.0f,                      0.0f,                      1.0f,                    0.0f},
  29.               {0.0f,                      0.0f,                      0.0f,                    1.0f}
  30.       };
  31.  
  32.       matrix = rotationx_matrix;
  33.    }
  34.    
  35.    /** Set the angle of rotation to theta, expressed in radians.  */  
  36.    public void setAngle(double theta){
  37.       // Write me!
  38.       matrix[0][0] = (float)Math.cos(theta);
  39.       matrix[0][1] = -(float)Math.sin(theta);
  40.       matrix[1][0] = (float)Math.sin(theta);
  41.       matrix[1][1] = (float)Math.cos(theta);
  42.    }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement