CFrame

The CFrame data type, short for coordinate frame, contains 3D positional and rotational data. It has two components: the positional component (X, Y, Z) and the rotational component (R00, R01, R02, R10 ... R21, R22). Unlike Vector3 which is used to represent rotations as Euler angles, CFrame's rotational component uses a 3×3 rotation matrix. CFrames also offer more functionality that deals with rotations than Vector3.
== Usage ==
CFrame, along with Vector3, is used by properties in Roblox API that determine the location and orientation of objects, such as parts, s and s.
To avoid gimbal lock, CFrame is preferred over Vector3 or other representations of Euler angles because CFrames use a rotation matrix which does not encounter gimbal lock.
== Data type ==
Rotation matrix components
 	RightVector	UpVector	-LookVector
XVector	R00 	R01 	R02
YVector	R10 	R11 	R12
ZVector	R20 	R21 	R22
=== Constructors ===
There are many constructors for CFrame. Constructors that take angle parameters uses radians, not degrees. Constructors also take other forms of rotation besides Euler angles and rotation matrix: axis-angle, and quaternion.
;CFrame.new()
:Creates an identity CFrame.
;CFrame.new(v: )
:Creates CFrame from the position of the Vector3 v.
;CFrame.new(x: , y: , z: )
:Creates CFrame from the coordinates (x, y, z).
;CFrame.new(x: , y: , z: , qX: , qY: , qZ: , qW: )
:Creates CFrame from position (x, y, z) and quaternion (qX, qY, qZ, qW).
;CFrame.new(x: , y: , z: , R00: , R01: , R02: , R10: , R11: , R12: , R20: , R21: , R22: )
:Creates CFrame from position (x, y, z) and rotation matrix (R00, R01, R02, R10, R11, R12, R20, R21, R22).
;CFrame.fromEulerAnglesYXZ(rx: , ry: , rz: )
;CFrame.fromOrientation
:Creates a CFrame rotated around the three axes, relative to the CFrame, in Z, X, Y order using the angles (rx, ry, rz).
;CFrame.fromEulerAnglesXYZ(rx: , ry: , rz: )
;CFrame.Angles
:Creates a CFrame rotated around the three axes, relative to the CFrame, in Z, Y, X order using the angles (rx, ry, rz).
;CFrame.fromAxisAngle(v: , r: )
:Creates a rotated CFrame from a unit vector and a rotation in radians.
;CFrame.fromMatrix(pos: , vX: , vY: , vZ: )
:Creates a CFrame from a translation and the columns of a rotation matrix. If vZ is excluded, the third column is calculated as vX:Cross(vY).Unit.
;CFrame.lookAt(at: , lookAt: , up: )
:Creates a CFrame with the position at and facing towards lookAt with the optional parameter up specifying the upward direction.
===Properties===
;identity 
:A CFrame with no translation or rotation. Note that this is a constant and must be accessed globally through the CFrame global, not a CFrame object itself.
;Position 
:The positional component of the CFrame.
;Rotation 
:A copy of the CFrame with no translation.
;X 
:The positional component of the CFrame on the X axis.
;Y 
:The positional component of the CFrame on the Y axis.
;Z 
:The positional component of the CFrame on the Z axis.
;LookVector 
:The front-facing directional vector of the CFrame.
;RightVector 
:The right-facing directional vector of the CFrame.
;UpVector 
:The up-facing directional vector of the CFrame.
;XVector 
:The first column in the rotation matrix of the CFrame.
;YVector 
:The second column in the rotation matrix of the CFrame.
;ZVector 
:The third column in the rotation matrix of the CFrame.
=== Methods ===
There are many methods of CFrame that can be used instead of having to calculate the results. Some methods of CFrame use the terms World and Object, both of which are used to distinguish positional data that is a vector of the place's origin ("World") from other positional data that is a vector of another position ("Object"). Some other methods convert the CFrame's rotational data to other forms of rotational data: the components of its rotation matrix, Euler angles or axis-angle.
;CFrame:Inverse(): 
:Returns the inverse of the CFrame.
;CFrame:Lerp(goal: , alpha: ): 
:Returns a CFrame interpolated between itself and goal by the fraction alpha.
;CFrame:Orthonormalize(): 
:Returns a CFrame that went through the Gram-Schmidt process.
;CFrame:ToWorldSpace(cf: ): 
:Returns a CFrame transformed from Object to World coordinates. Equivalent to CFrame * cf. Also works with tuples.
;CFrame:ToObjectSpace(cf: ): 
:Returns a CFrame transformed from World to Object coordinates. Equivalent to CFrame:Inverse() * cf. Also works with tuples.
;CFrame:PointToWorldSpace(v3: ): 
:Returns a Vector3 transformed from Object to World coordinates. Also works with tuples.
;CFrame:PointToObjectSpace(v3: ): 
:Returns a Vector3 transformed from World to Object coordinates. Also works with tuples.
;CFrame:VectorToWorldSpace(v3: ): 
:Returns a Vector3 rotated from Object to World coordinates. Also works with tuples.
;CFrame:VectorToObjectSpace(v3: ): 
:Returns a Vector3 rotated from World to Object coordinates. Also works with tuples.
;CFrame:GetComponents(): 
;CFrame:components
:Returns all components of the CFrame in the following order: x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22.
;CFrame:ToEulerAnglesYXZ(): (, , )
;CFrame:ToOrientation
:Returns approximate angles of the part's orientation that could be used to generate the CFrame by applying the angles in Z, X, Y order.
;CFrame:ToEulerAnglesXYZ(): (, , )
:Returns approximate angles of the part's orientation that could be used to generate the CFrame by applying the angles in Z, Y, X order.
;CFrame:ToAxisAngle(cf: )
:Returns the orientation of the CFrame in axis-angle representation.
===Operators===
; * : 
:Returns composition of two CFrames.
; * : 
:Returns Vector3 transformed from Object to World coordinates.
; + : 
:Returns CFrame translated by Vector3.
; - : 
:Returns CFrame translated by -Vector3.
== Referenced by ==
== External links ==
* CFrames on the Roblox Creator Documentation
* CFrame data type on the Roblox Creator Documentation
Category:Roblox types
Category:Reference types