Skip to main content

center: Coordinate Centering Transformation

Converting unit coordinates to centered coordinate system

The center functions transform coordinates from the unit range [0,1][0,1] to the centered range [1,1][-1,1]. This operation centers coordinates around the origin, essential for symmetric operations and distance calculations.

Mathematical Foundation

For any coordinate value xx in the range [0,1][0,1]:

xcentered=2x1x_{centered} = 2x - 1

This linear transformation maps:

  • 010 \rightarrow -1 (minimum)
  • 0.500.5 \rightarrow 0 (center)
  • 111 \rightarrow 1 (maximum)

Function Variants

FunctionInput TypeOutput TypeDescription
centerFloat(x)floatfloatCenters scalar value
centerVec2(v)vec2vec2Centers 2D vector components
centerVec3(v)vec3vec3Centers 3D vector components
Live Editor
const fragment = () => {
      const centered = centerVec2(uv)
      const voronoi = centered.length().mul(centered.x.mul(centered.y).mul(100)).fract()
      const pattern = voronoi.step(0.8)
      return vec4(vec3(pattern), 1)
}