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

cart2polar: Cartesian to Polar Coordinate Transformation

Converting rectangular coordinates to polar representation​

The cart2polar functions transform Cartesian coordinates into polar coordinate systems, providing radius and angular components for both 2D and 3D spaces.

2D Polar Transformation​

For 2D Cartesian coordinates (x,y)(x, y), the polar transformation produces (θ,r)(\theta, r):

θ=atan2(y,x)\theta = \text{atan2}(y, x) r=x2+y2r = \sqrt{x^2 + y^2}

3D Spherical Transformation​

For 3D Cartesian coordinates (x,y,z)(x, y, z), the spherical transformation produces (r,ϕ,θ)(r, \phi, \theta):

r=x2+y2+z2r = \sqrt{x^2 + y^2 + z^2} ϕ=arccos⁡(zr)\phi = \arccos\left(\frac{z}{r}\right) θ=atan2(y,x)\theta = \text{atan2}(y, x)

Function Variants​

FunctionInputOutputDescription
cart2polar(st)vec2vec22D polar coordinates (θ,r)(\theta, r)
cart2polar3D(st)vec3vec33D spherical coordinates (r,ϕ,θ)(r, \phi, \theta)
ライブエディター

const fragment = () => {
      const center = uv.sub(0.5)
      const polar = cart2polar(center)
      const angle = polar.x
      const radius = polar.y
      const pattern = angle.mul(8).sin().mul(0.5).add(0.5)
      const radialMask = smoothstep(0.02, 0.05, radius)
      return vec4(vec3(pattern.mul(radialMask)), 1)
}
結果
Loading...