Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JokerMartini/cf8de3bf3747dca3b52e to your computer and use it in GitHub Desktop.
Save JokerMartini/cf8de3bf3747dca3b52e to your computer and use it in GitHub Desktop.
Maxscript: How to rotate a vector around another vector x degrees.
/* How to rotate a vector around another vector x degrees? */
staticVector = normalize (point3 1 1 1)
rotatingVector = normalize (point3 0 1 1)
centerOfRotatoin = [0,0,0]
x = 30
--use static vector and rotating vector to derive a 3rd axis.
finalVector= cross staticVector rotatingVector
--contruct a matrix 3
-- rotating vector is in row2
tm = matrix3 1
tm.row1 = staticVector
tm.row2 = rotatingVector
tm.row3 = finalVector
tm.row4 = centerOfRotatoin
--rotate
rotateX tm 90
--extract the new vector
rotatedVector = tm.row2
https://forums.cgsociety.org/t/geometrical-calculations-points-lines-planes-intersections-distances-angles/906269/22
fn PointAxisAt a which_axis b =
(
local c = normalize (b - a)
local angle = acos (dot which_axis c)
local axis = normalize (cross which_axis c)
local out = (angleaxis angle axis) as quat
out
)
a = $Pyramid01.position
b = $Point01.position
q = PointAxisAt a z_axis b
r = q * (inverse $Pyramid01.rotation)
rotate $Pyramid01 r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment