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

polar2cart: Polar to Cartesian Coordinate Reconstruction

Converting polar representation back to rectangular coordinates​

The polar2cart functions perform the inverse transformation of cart2polar, reconstructing Cartesian coordinates from polar and spherical representations.

2D Cartesian Reconstruction​

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

x=rcos⁡(θ)x = r \cos(\theta) y=rsin⁡(θ)y = r \sin(\theta)

3D Cartesian Reconstruction​

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

x=rcos⁡(θ)sin⁡(ϕ)x = r \cos(\theta) \sin(\phi) y=rsin⁡(θ)sin⁡(ϕ)y = r \sin(\theta) \sin(\phi) z=rcos⁡(ϕ)z = r \cos(\phi)

Function Variants​

FunctionInputOutputDescription
polar2cart(polar)vec2vec22D polar to Cartesian (θ,r)→(x,y)(\theta,r) \rightarrow (x,y)
polar2cart3D(r,phi,theta)float,float,floatvec33D spherical to Cartesian
ライブエディター

const fragment = () => {
      const r = 0.3
      const phi = uv.x.mul(3.14)
      const theta = uv.y.mul(6.28)
      const sphere3d = polar2cart3D(r, phi, theta)
      const projection = sphere3d.xy.add(0.5)
      const depth = sphere3d.z.mul(2).add(0.5)
      return vec4(vec3(projection, depth), 1)
}
結果
Loading...