Skip to content

Commit 383c023

Browse files
committed
use sincos
1 parent 8008299 commit 383c023

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/coordinatesystems.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ end
3939
transform_deriv_params(::PolarFromCartesian, x::AbstractVector) = error("PolarFromCartesian has no parameters")
4040

4141
function (::CartesianFromPolar)(x::Polar)
42-
SVector(x.r * cos(x.θ), x.r * sin(x.θ))
42+
s,c = sincos(x.θ)
43+
SVector(x.r * c, x.r * s)
4344
end
4445
function transform_deriv(::CartesianFromPolar, x::Polar)
45-
= sin(x.θ)
46-
= cos(x.θ)
46+
sθ, cθ = sincos(x.θ)
4747
@SMatrix [cθ -x.r*sθ ;
4848
sθ x.r*cθ ]
4949
end
@@ -133,14 +133,13 @@ end
133133
transform_deriv_params(::SphericalFromCartesian, x::AbstractVector) = error("SphericalFromCartesian has no parameters")
134134

135135
function (::CartesianFromSpherical)(x::Spherical)
136-
SVector(x.r * cos(x.θ) * cos(x.ϕ), x.r * sin(x.θ) * cos(x.ϕ), x.r * sin(x.ϕ))
136+
sθ, cθ = sincos(x.θ)
137+
sϕ, cϕ = sincos(x.ϕ)
138+
SVector(x.r ** cϕ, x.r ** cϕ, x.r * sϕ)
137139
end
138140
function transform_deriv(::CartesianFromSpherical, x::Spherical{T}) where T
139-
= sin(x.θ)
140-
= cos(x.θ)
141-
= sin(x.ϕ)
142-
= cos(x.ϕ)
143-
141+
sθ, cθ = sincos(x.θ)
142+
sϕ, cϕ = sincos(x.ϕ)
144143
@SMatrix [cθ*-x.r**-x.r**sϕ ;
145144
*cϕ x.r**-x.r**sϕ ;
146145
zero(T) x.r * cϕ ]
@@ -168,11 +167,11 @@ end
168167
transform_deriv_params(::CylindricalFromCartesian, x::AbstractVector) = error("CylindricalFromCartesian has no parameters")
169168

170169
function (::CartesianFromCylindrical)(x::Cylindrical)
171-
SVector(x.r * cos(x.θ), x.r * sin(x.θ), x.z)
170+
sθ, cθ = sincos(x.θ)
171+
SVector(x.r * cθ, x.r * sθ, x.z)
172172
end
173173
function transform_deriv(::CartesianFromCylindrical, x::Cylindrical{T}) where {T}
174-
= sin(x.θ)
175-
= cos(x.θ)
174+
sθ, cθ = sincos(x.θ)
176175
@SMatrix [cθ -x.r*zero(T) ;
177176
sθ x.r*zero(T) ;
178177
zero(T) zero(T) one(T) ]

0 commit comments

Comments
 (0)