Include details about your goal:
- So first of all, my goal is to make the points rotations of a cube aroud X, Y, and Z axis to rotate the cube itself.
Describe expected:
- I expect to have that after an 17.18° rotation around X axis:
- I expect to have that after an 17.18° rotation around Z axis:
Actual results:
Black shape is the default cube with no rotations
White shape is the rotated cube.
My actual result after an 17.18° rotation around X axis with my formula:
- My actual result after an 17.18° rotation around Z axis with my formula:
Show what you’ve tried and tell us what you found (on this site or elsewhere) and why it didn’t meet your needs. You can get better answers when you provide research.
I have saw a few site that describe exactly what I want:
- https://www.desmos.com/calculator/imazvy40oz?lang=fr
- https://fr.khanacademy.org/computer-programming/cube-rotating-with-user-interaction/5953495622746112
Show some code
- First of all i am using Java because my problem is my Minecraft virtually shape don't meet with the real one;
Rotation methods
public void rotateX() {
for(int i = 0; i < points.size(); i++) {
Vector vector = points.get(i);
double sinTheta = Math.sin(eulerAngle.getX());
double cosTheta = Math.cos(eulerAngle.getX());
double y = vector.getY();
double z = vector.getZ();
vector.setY(y * cosTheta - z * sinTheta);
vector.setZ(z * cosTheta + y * sinTheta);
}
}
public void rotateY() {
for(int i = 0; i < points.size(); i++) {
Vector vector = points.get(i);
double sinTheta = Math.sin(eulerAngle.getY());
double cosTheta = Math.cos(eulerAngle.getY());
double x = vector.getX();
double z = vector.getZ();
vector.setX(x * cosTheta - z * sinTheta);
vector.setZ(z * cosTheta + x * sinTheta);
}
}
public void rotateZ() {
for(int i = 0; i < points.size(); i++) {
Vector vector = points.get(i);
double sinTheta = Math.sin(eulerAngle.getZ());
double cosTheta = Math.cos(eulerAngle.getZ());
double x = vector.getX();
double y = vector.getY();
vector.setX(x * cosTheta - y * sinTheta);
vector.setY(y * cosTheta + x * sinTheta);
}
}
My setup method
public void setupPoints() {
ArrayList<Vector> points = new ArrayList<Vector>();
points.add(getA());
points.add(getB());
points.add(getC());
points.add(getD());
points.add(getE());
points.add(getF());
points.add(getG());
points.add(getH());
this.points = points;
rotateZ();
rotateY();
rotateX();
}
My points locations are (i know its not an exact cube):
My enviroment:
note: Only Y rotation works perfectly, i noticed that the rotation on the Y axis corresponds to that of the Z axis in a coordinate system where Y would be the "height", its the first time that i work on 3d space plan so i am learning. Thanks if you read until here.