I have a 2-dimensional image of smiley face in a 3-dimensional space. I want it to rotate like a fan, so the smiley would look as if it's rolling like a wheel in place. Since the smiley is placed in a 3D space it can face any direction, but I always want it to rotate around like a wheel.
I use Minecraft so the Z and Y have the opposite jobs. (Y is the height).
I use these 3 functions for rotating around the x, y and z axis.
public static final Vector rotateAroundAxisX(Vector v, double angle) {
double y, z, cos, sin;
cos = Math.cos(angle);
sin = Math.sin(angle);
y = v.getY() * cos - v.getZ() * sin;
z = v.getY() * sin + v.getZ() * cos;
return v.setY(y).setZ(z);
}
public static final Vector rotateAroundAxisY(Vector v, double angle) {
double x, z, cos, sin;
cos = Math.cos(angle);
sin = Math.sin(angle);
x = v.getX() * cos + v.getZ() * sin;
z = v.getX() * -sin + v.getZ() * cos;
return v.setX(x).setZ(z);
}
public static final Vector rotateAroundAxisZ(Vector v, double angle) {
double x, y, cos, sin;
cos = Math.cos(angle);
sin = Math.sin(angle);
x = v.getX() * cos - v.getY() * sin;
y = v.getX() * sin + v.getY() * cos;
return v.setX(x).setY(y);
}
Sometimes I spawn the smiley facing the negative/positive X direction so to make it look like a wheel I have to rotate it around the X axis. But sometimes I spawn the smiley facing the negative/positive Z direction so I have to rotate it around the Z axis.
I searched online and found a term for an object's axes, and the one I was looking for is called "Roll".
Is there any way to rotate this smiley like a wheel regardless of where it's facing? a.k.a rotate it around its own "roll axis"?