Skip to content

Commit ba56935

Browse files
authored
perf: faster Spherical-Cylindrical transformation by direct computing (#78)
1 parent ff9ea6e commit ba56935

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
*.jl.cov
22
*.jl.*.cov
33
*.jl.mem
4+
5+
*Manifest.toml
6+
*.swp

src/coordinatesystems.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ function transform_deriv(::CartesianFromCylindrical, x::Cylindrical{T}) where {T
218218
end
219219
transform_deriv_params(::CartesianFromPolar, x::Cylindrical) = error("CartesianFromCylindrical has no parameters")
220220

221-
# Spherical <-> Cylindrical (TODO direct would be faster)
222221
function (::CylindricalFromSpherical)(x::Spherical)
223-
CylindricalFromCartesian()(CartesianFromSpherical()(x))
222+
sϕ, cϕ = sincos(x.ϕ)
223+
Cylindrical(x.r*cϕ,x.θ,x.r*sϕ)
224224
end
225225
function transform_deriv(::CylindricalFromSpherical, x::Spherical)
226226
M1 = transform_deriv(CylindricalFromCartesian(), CartesianFromSpherical()(x))
@@ -230,7 +230,7 @@ end
230230
transform_deriv_params(::CylindricalFromSpherical, x::Spherical) = error("CylindricalFromSpherical has no parameters")
231231

232232
function (::SphericalFromCylindrical)(x::Cylindrical)
233-
SphericalFromCartesian()(CartesianFromCylindrical()(x))
233+
Spherical(hypot(x.r,x.z),x.θ,atan(x.z,x.r))
234234
end
235235
function transform_deriv(::SphericalFromCylindrical, x::Cylindrical)
236236
M1 = transform_deriv(SphericalFromCartesian(), CartesianFromCylindrical()(x))

0 commit comments

Comments
 (0)