Created
July 23, 2014 18:12
-
-
Save Deamon5550/80e9d8ea680f42f2fb92 to your computer and use it in GitHub Desktop.
Rot3d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.thevoxelbox.voxelsniper.util; | |
| public class Rot3d | |
| { | |
| double[][] r = new double[3][3]; | |
| public Rot3d(double u, double v, double w) | |
| { | |
| double cos1 = Math.cos(u); | |
| double sin1 = Math.sin(u); | |
| double cos2 = Math.cos(v); | |
| double sin2 = Math.sin(v); | |
| double cos3 = Math.cos(w); | |
| double sin3 = Math.sin(w); | |
| r[0][0] = cos1*cos2; | |
| r[0][1] = sin1*sin3 - cos1*cos3*sin2; | |
| r[0][2] = cos3*sin1 + cos1*sin2*sin3; | |
| r[1][0] = sin2; | |
| r[1][1] = cos2*cos3; | |
| r[1][2] = -cos2*sin3; | |
| r[2][0] = -cos2*sin1; | |
| r[2][1] = cos1*sin3 + cos3*sin1*sin2; | |
| r[2][2] = cos1*cos3 - sin1*sin2*sin3; | |
| } | |
| public double[] doRotation(double x, double y, double z) | |
| { | |
| double[] p = new double[3]; | |
| p[0] = r[0][0] * x + r[0][1] * y + r[0][2] * z; | |
| p[1] = r[1][0] * x + r[1][1] * y + r[1][2] * z; | |
| p[2] = r[2][0] * x + r[2][1] * y + r[2][2] * z; | |
| return p; | |
| } | |
| public double[] doRotation(double[] xyz) | |
| { | |
| double[] p = new double[3]; | |
| p[0] = r[0][0] * xyz[0] + r[0][1] * xyz[1] + r[0][2] * xyz[2]; | |
| p[1] = r[1][0] * xyz[0] + r[1][1] * xyz[1] + r[1][2] * xyz[2]; | |
| p[2] = r[2][0] * xyz[0] + r[2][1] * xyz[1] + r[2][2] * xyz[2]; | |
| return p; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment