Skip to content

Instantly share code, notes, and snippets.

@mooman219
Created August 4, 2014 09:22
Show Gist options
  • Save mooman219/e7a61c3564648e05aa0a to your computer and use it in GitHub Desktop.
Save mooman219/e7a61c3564648e05aa0a to your computer and use it in GitHub Desktop.
public static List<Vector> rotateX(List<Vector> vectors, double degrees) {
List<Vector> result = new ArrayList<>(vectors.size());
double cos = Math.cos(Math.toRadians(degrees));
double sin = Math.sin(Math.toRadians(degrees));
for (Vector target : vectors) {
result.add(new Vector(
target.getX(),
cos * target.getY() - sin * target.getZ(),
sin * target.getY() + cos * target.getZ()));
}
return result;
}
public static List<Vector> rotateY(List<Vector> vectors, double degrees) {
List<Vector> result = new ArrayList<>(vectors.size());
double cos = Math.cos(Math.toRadians(degrees));
double sin = Math.sin(Math.toRadians(degrees));
for (Vector target : vectors) {
result.add(new Vector(
cos * target.getX() - sin * target.getZ(),
target.getY(),
sin * target.getX() + cos * target.getZ()));
}
return result;
}
public static List<Vector> rotateZ(List<Vector> vectors, double degrees) {
List<Vector> result = new ArrayList<>(vectors.size());
double cos = Math.cos(Math.toRadians(degrees));
double sin = Math.sin(Math.toRadians(degrees));
for (Vector target : vectors) {
result.add(new Vector(
cos * target.getX() - sin * target.getY(),
sin * target.getX() + cos * target.getY(),
target.getZ()));
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment