Rotate Vector3 on arbitrary surface/plane

So I’m pretty bad at math, and I’ve been struggling with this question for a while.
How would I rotate a vector3 on an arbitrary plane/surface given the angle of rotation and the surface normal?

Something like this

function rotateOnArbitraryAxis(toRotate : Vector3, surfaceNormal : Vector3, angleOfRotation : Number)
   -- code I'm struggling to produce
   -- returns rotated vector3.
end

I couldn’t find an easy solution to my problem in the documentation or forums and I’ve been scrolling through math wikis but I’m struggling

Please Advise :slight_smile:

1 Like

Does this do the intended thing?

local function rotateOnArbitraryAxis(toRotate : Vector3, surfaceNormal : Vector3, angleOfRotation : Number)
	return CFrame.fromAxisAngle(surfaceNormal.Unit, angleOfRotation) * toRotate
end

The angle needs to be in radians.

3 Likes

Thank you so much :smiley: this is really helpful. Worked like a charm

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.