How to rotate a 3D point around arbitrary axis in JavaScript?
I want to implement a function with parameters like the following: /* @param axisX, axisY, axisZ would be components of a direction vector representing the arbitrary axis of rotation. The vector can be assumed to have a length of 1(a unit vector). @param radians would be an angle of rotation @param point would be something like an Array of length 3 with 3 numbers. This is the point to get rotated. */ function rotateArbitrary(axisX, axisY, axisZ, radians, point) { } I would prefer reusing a third party math library because this is a fairly complicated operation. If not, copy/pasting working JavaScript code would be a good alternative. It is complicated enough that I'm very happy ignoring how it works and mentally treating it like a black box. I found this example that uses three.js but three.js isn't a math library and includes a lot of graphics-related code that I don't want to use: https://stackoverflow.com/questions/11060734/how-to-rotate-a-3d-object-on-axis-three-js This shows how to rotate around x, y, and z axis but that's not flexible enough for my needs: https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Matrix_math_for_the_web#rotation_matrix That is a sequence of 3 rotations around each of the x, y, z axis separately. That's not the same as my problem where an arbitrary axis is described with (x, y, z) vector components. Here is a 2D rotation but 2D rotation is very simple and not my problem: https://mathjs.org/docs/reference/functions/rotationMatrix.html It looks like c++ also has a library similar to what I want in JavaScript: https://stackoverflow.com/questions/62239604/how-to-rotate-a-point-around-an-arbitrary-axis This appears to explain the math and gives some c code but I'd prefer using a third party library that has already been tested rather than implement and test it myself: http://paulbourke.net/geometry/rotate/