|
39 | 39 | transform_deriv_params(::PolarFromCartesian, x::AbstractVector) = error("PolarFromCartesian has no parameters")
|
40 | 40 |
|
41 | 41 | 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) |
43 | 44 | end
|
44 | 45 | function transform_deriv(::CartesianFromPolar, x::Polar)
|
45 |
| - sθ = sin(x.θ) |
46 |
| - cθ = cos(x.θ) |
| 46 | + sθ, cθ = sincos(x.θ) |
47 | 47 | @SMatrix [cθ -x.r*sθ ;
|
48 | 48 | sθ x.r*cθ ]
|
49 | 49 | end
|
@@ -133,14 +133,13 @@ end
|
133 | 133 | transform_deriv_params(::SphericalFromCartesian, x::AbstractVector) = error("SphericalFromCartesian has no parameters")
|
134 | 134 |
|
135 | 135 | 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θ * cϕ, x.r * sθ * cϕ, x.r * sϕ) |
137 | 139 | end
|
138 | 140 | function transform_deriv(::CartesianFromSpherical, x::Spherical{T}) where T
|
139 |
| - sθ = sin(x.θ) |
140 |
| - cθ = cos(x.θ) |
141 |
| - sϕ = sin(x.ϕ) |
142 |
| - cϕ = cos(x.ϕ) |
143 |
| - |
| 141 | + sθ, cθ = sincos(x.θ) |
| 142 | + sϕ, cϕ = sincos(x.ϕ) |
144 | 143 | @SMatrix [cθ*cϕ -x.r*sθ*cϕ -x.r*cθ*sϕ ;
|
145 | 144 | sθ*cϕ x.r*cθ*cϕ -x.r*sθ*sϕ ;
|
146 | 145 | sϕ zero(T) x.r * cϕ ]
|
@@ -168,11 +167,11 @@ end
|
168 | 167 | transform_deriv_params(::CylindricalFromCartesian, x::AbstractVector) = error("CylindricalFromCartesian has no parameters")
|
169 | 168 |
|
170 | 169 | 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) |
172 | 172 | end
|
173 | 173 | function transform_deriv(::CartesianFromCylindrical, x::Cylindrical{T}) where {T}
|
174 |
| - sθ = sin(x.θ) |
175 |
| - cθ = cos(x.θ) |
| 174 | + sθ, cθ = sincos(x.θ) |
176 | 175 | @SMatrix [cθ -x.r*sθ zero(T) ;
|
177 | 176 | sθ x.r*cθ zero(T) ;
|
178 | 177 | zero(T) zero(T) one(T) ]
|
|
0 commit comments