Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sincos #9

Merged
merged 1 commit into from
Oct 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions src/SkyCoords.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,36 @@ end
# -----------------------------------------------------------------------------
# Helper functions: Create rotation matrix about a given axis (x, y, z)

if !isdefined(Base, :sincos)
sincos(x::Real) = (sin(x), cos(x))
end

function xrotmat(angle)
s = sin(angle)
c = cos(angle)
s, c = sincos(angle)
Matrix33(1., 0., 0.,
0., c, s,
0., -s, c)
end

function yrotmat(angle)
s = sin(angle)
c = cos(angle)
s, c = sincos(angle)
Matrix33(c, 0., -s,
0., 1., 0.,
s, 0., c)
end

function zrotmat(angle)
s = sin(angle)
c = cos(angle)
s, c = sincos(angle)
Matrix33(c, s, 0.,
-s, c, 0.,
0., 0., 1.)
end

# (lon, lat) -> [x, y, z] unit vector
function coords2cart(lon, lat)
coslat = cos(lat)
Vector3(coslat*cos(lon), coslat*sin(lon), sin(lat))
sinlon, coslon = sincos(lon)
sinlat, coslat = sincos(lat)
Vector3(coslat * coslon, coslat * sinlon, sinlat)
end

# [x, y, z] unit vector -> (lon, lat)
Expand Down Expand Up @@ -271,12 +273,9 @@ end

function _separation(λ_1, ϕ_1, λ_2, ϕ_2)
Δλ = λ_2 - λ_1
sin_Δλ = sin(Δλ)
cos_Δλ = cos(Δλ)
sin_ϕ1 = sin(ϕ_1)
sin_ϕ2 = sin(ϕ_2)
cos_ϕ1 = cos(ϕ_1)
cos_ϕ2 = cos(ϕ_2)
sin_Δλ, cos_Δλ = sincos(Δλ)
sin_ϕ1, cos_ϕ1 = sincos(ϕ_1)
sin_ϕ2, cos_ϕ2 = sincos(ϕ_2)
return atan2(hypot(cos_ϕ2 * sin_Δλ,
cos_ϕ1 * sin_ϕ2 - sin_ϕ1 * cos_ϕ2 * cos_Δλ),
sin_ϕ1 * sin_ϕ2 + cos_ϕ1 * cos_ϕ2 * cos_Δλ)
Expand Down