Created
February 1, 2016 22:38
-
-
Save xorgy/ede0eae2c0f14dbeae9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function xyz_to_ρ (x, y, z) { | |
return Math.sqrt((x * x) + (y * y) + (z * z)); | |
} | |
function zρ_to_θ (z, ρ) { | |
return Math.acos(z / ρ); | |
} | |
function yx_to_φ (y, x) { | |
return Math.atan(y / x); | |
} | |
function xyz_to_ρθφ (x, y, z) { | |
const ρ = xyz_to_ρ(x, y, z); | |
const θ = zρ_to_θ(z, ρ); | |
const φ = yx_to_φ(y, x); | |
return [ρ, θ, φ]; | |
} | |
function ρθφ_to_x (ρ, θ, φ) { | |
return ρ * Math.sin(θ) * Math.cos (φ); | |
} | |
function ρθφ_to_y (ρ, θ, φ) { | |
return ρ * Math.sin(θ) * Math.sin (φ); | |
} | |
function ρθ_to_z (ρ, θ) { | |
return ρ * Math.cos(θ); | |
} | |
function ρθφ_to_xyz (ρ, θ, φ) { | |
const x = ρθφ_to_x(ρ, θ, φ); | |
const y = ρθφ_to_y(ρ, θ, φ); | |
const z = ρθ_to_z(ρ, θ); | |
return [x, y, z]; | |
} | |
module.exports = { | |
xyz_to_ρ, | |
zρ_to_θ, | |
yx_to_φ, | |
xyz_to_ρθφ, | |
ρθφ_to_x, | |
ρθφ_to_y, | |
ρθ_to_z, | |
ρθφ_to_xyz | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment