Help with axis angle

So it seems I’m having some trouble understanding what exactly CFrame.fromAxisAngle() does. My original understanding was that fromAxisAngle() would accept a vector and an angle. The vector (illustrated in blue) would be the direction in which the CFrame would point, and the given angle (illustrated in red) would determine the rotation around said axis.

image

But ive found that this doesnt seem to be the case. Here’s an example:

I have this function here called update(), which accepts an angle (radians) and rotates a part to have that given angle.

local function update(deg)

The function then gets the tangent of that angle so that it may attempt to produce a unit vector to give to the fromAxisAngle() constructor:

local TangentAngle = math.tan(deg)
local Vector = Vector3.new(0, TangentAngle, 1).Unit

Now lastly, I give the vector to the constructor and apply the newly created CFrame to the object:

local Axis = CFrame.fromAxisAngle(Vector, 0) --angle is omitted for now, should not affect anything anyways
Motor.C0 = Axis + Motor.C0.Position

to sum up the whole function:

local function update(deg)
     local TangentAngle = math.tan(deg)
     local Vector = Vector3.new(0, TangentAngle, 1).Unit

    local Axis = CFrame.fromAxisAngle(Vector, 0)
    Motor.C0 = Axis + Motor.C0.Position
end

But this doesnt end up moving the part at all!
I attempted to make my own function of the expected behavior, to see if my code had any issues:

local function AxisAngle(Axis, angle)
	local frame = CFrame.lookAt(Vector3.new(), Axis)
	return frame
end

When this function was used in place of the fromAxisAngle() constructor, the part began moving exactly as expected.

Am I misunderstanding how the constructor works, or was there an error in my code? any help would be appreciated.

1 Like

What is the intended kind of movement you’re trying to do?

CFrame.fromAxisAngle( axis, angle ) constructs a CFrame that represents a pure rotation transform of angle radians around the specified axis. So for example,

local rotCF = CFrame.fromAxisAngle( Vector3.yAxis, 0.5*math.pi )

gives you a CFrame that represents a 90-degree rotation about the Y axis. You can of course supply any arbitrary Vector3 to be the rotation axis, it doesn’t need to be one of the bases.

Multiplying this rotation CFrame on the left ( e.g. part.CFrame = rotCF * part.CFrame) will rotate the part 90 degrees on the world Y-axis, about the world origin**; i.e. world 0,0,0 will be the pivot point of the rotation. If the part isn’t already at the world origin, the rotation will move it too, like it’s on the end of an arm that starts at the world origin. **More correctly, what multiplication on the left really means that the transform is applied in the coordinate space of the Parent, i.e. the same space in which the Part’s position and orientation are specified. For a Part that’s just in the workspace and not welded to other things, this is world space.

Multiplying it on the right, part.CFrame = part.CFrame * rotCF will spin the part around it’s own y-Axis, aka the part.CFrame.UpVector, without changing the world positon of the part.

To clarify your original point, no the axis of the axis-angle does not become the CFrame’s LookVector; it’s not the direction the CFrame points.

2 Likes

Thank you for the explanation. Better understanding how this function works may save me hours of work here, thank you.

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