Advertisement
iSach

Some Utils about Vectors.

Nov 8th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. public static final Vector rotateAroundAxisX(Vector v, double angle) {
  2. double y, z, cos, sin;
  3. cos = Math.cos(angle);
  4. sin = Math.sin(angle);
  5. y = v.getY() * cos - v.getZ() * sin;
  6. z = v.getY() * sin + v.getZ() * cos;
  7. return v.setY(y).setZ(z);
  8. }
  9.  
  10. public static final Vector rotateAroundAxisY(Vector v, double angle) {
  11. double x, z, cos, sin;
  12. cos = Math.cos(angle);
  13. sin = Math.sin(angle);
  14. x = v.getX() * cos + v.getZ() * sin;
  15. z = v.getX() * -sin + v.getZ() * cos;
  16. return v.setX(x).setZ(z);
  17. }
  18.  
  19. public static final Vector rotateAroundAxisZ(Vector v, double angle) {
  20. double x, y, cos, sin;
  21. cos = Math.cos(angle);
  22. sin = Math.sin(angle);
  23. x = v.getX() * cos - v.getY() * sin;
  24. y = v.getX() * sin + v.getY() * cos;
  25. return v.setX(x).setY(y);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement