メインコンテンツまでスキップ

rotateZ: Z-Axis Vector Rotation Transform

Matrix-based rotation around the Z-axis

The rotateZ functions provide Z-axis rotation transformations for 3D and 4D vectors using matrix operations. These functions generate rotation matrices that rotate vectors around the Z-axis by a specified angle.

The mathematical foundation uses a 4D rotation matrix:

Rz(θ)=(cosθsinθ00sinθcosθ0000100001)R_z(\theta) = \begin{pmatrix} \cos\theta & \sin\theta & 0 & 0 \\ -\sin\theta & \cos\theta & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}

This matrix rotates points in the XY-plane while preserving the Z-coordinate. The rotation follows the right-hand rule, where positive angles rotate counterclockwise when viewed from the positive Z-axis.

Available Functions

FunctionInput TypesDescription
rotateZVec3vec3, floatRotate 3D vector around Z-axis
rotateZVec3Centervec3, float, vec3Rotate 3D vector around Z-axis with custom center
rotateZVec4vec4, floatRotate 4D vector around Z-axis
rotateZVec4Centervec4, float, vec4Rotate 4D vector around Z-axis with custom center
ライブエディター
const fragment = () => {
      const angle = iTime.mul(1.5)
      const pos = vec3(uv.sub(0.5).mul(2), 0)
      const rotated = rotateZVec3(pos, angle)
      const color = rotated.xy.add(0.5).abs()
      return vec4(color, rotated.x.mul(0.5).add(0.5), 1)
}