Skip to content

Instantly share code, notes, and snippets.

@mcy
Created May 2, 2014 19:20
Show Gist options
  • Save mcy/5b27c89aea90e3dfe24c to your computer and use it in GitHub Desktop.
Save mcy/5b27c89aea90e3dfe24c to your computer and use it in GitHub Desktop.
/*
* v - Vector to rotate
* e - unit Vector about which to rotate
* th - angle in radians
*/
private static Vector rotate(Vector v, Vector e, double th){
double cos = Math.cos(th);
double sin = Math.sin(th);
return (v.clone().multiply(cos)).add(e.clone().crossProduct(v).multiply(sin)).add(e.clone().multiply(e.dot(v)).multiply(1 - cos));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment