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

Fix GslibAngles and MinesightAngles rotations #197

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
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
28 changes: 14 additions & 14 deletions src/rotations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ end
"""
GslibAngles(θ₁, θ₂, θ₃)

GSLIB YXZ rotation convention following the left-hand rule.
GSLIB z-x'-y'' intrinsic rotation convention following the left-hand rule.
All angles are in degrees and the sign convention is CW, CCW, CW positive.
Y is the principal axis.

The first rotation `θ₁` is a rotation around the Z-axis, this is also called the azimuth.
The second rotation `θ₂` is a rotation around the X-axis, this is also called the dip.
The third rotation `θ₃` is a rotation around the Y-axis, this is also called the tilt.
The second rotation `θ₂` is a rotation around the new X-axis, this is also called the dip.
The third rotation `θ₃` is a rotation around the new Y-axis, this is also called the tilt.

## References

Expand All @@ -107,22 +107,22 @@ end
GslibAngles(θ₁::T, θ₂::T, θ₃::T) where {T} = GslibAngles{T}(θ₁, θ₂, θ₃)
GslibAngles(θ₁, θ₂, θ₃) = GslibAngles(promote(θ₁, θ₂, θ₃)...)

rottype(::Type{<:GslibAngles}) = RotYXZ
rottype(::Type{<:GslibAngles}) = RotZXY

function Base.convert(::Type{R}, rot::RotYXZ) where {R<:GslibAngles}
function Base.convert(::Type{R}, rot::RotZXY) where {R<:GslibAngles}
θ₁, θ₂, θ₃ = Rotations.params(rot)
R(-rad2deg(θ), rad2deg(θ₂), -rad2deg(θ))
R(-rad2deg(θ), rad2deg(θ₂), -rad2deg(θ))
end

function Base.convert(::Type{R}, rot::GslibAngles) where {R<:RotYXZ}
function Base.convert(::Type{R}, rot::GslibAngles) where {R<:RotZXY}
(; θ₁, θ₂, θ₃) = rot
R(-deg2rad(θ), deg2rad(θ₂), -deg2rad(θ))
R(-deg2rad(θ), deg2rad(θ₂), -deg2rad(θ))
end

"""
MinesightAngles(θ₁, θ₂, θ₃)

MineSight YXZ rotation convention following the right-hand rule.
MineSight z-x'-y'' intrinsic rotation convention following the right-hand rule.
All angles are in degrees and the sign convention is CW, CCW, CW positive.

The first rotation `θ₁` is a horizontal rotation around the Z-axis, with positive being clockwise.
Expand All @@ -145,14 +145,14 @@ end
MinesightAngles(θ₁::T, θ₂::T, θ₃::T) where {T} = MinesightAngles{T}(θ₁, θ₂, θ₃)
MinesightAngles(θ₁, θ₂, θ₃) = MinesightAngles(promote(θ₁, θ₂, θ₃)...)

rottype(::Type{<:MinesightAngles}) = RotYXZ
rottype(::Type{<:MinesightAngles}) = RotZXY

function Base.convert(::Type{R}, rot::RotYXZ) where {R<:MinesightAngles}
function Base.convert(::Type{R}, rot::RotZXY) where {R<:MinesightAngles}
θ₁, θ₂, θ₃ = Rotations.params(rot)
R(-rad2deg(θ), rad2deg(θ₂), -rad2deg(θ))
R(-rad2deg(θ), rad2deg(θ₂), -rad2deg(θ))
end

function Base.convert(::Type{R}, rot::MinesightAngles) where {R<:RotYXZ}
function Base.convert(::Type{R}, rot::MinesightAngles) where {R<:RotZXY}
(; θ₁, θ₂, θ₃) = rot
R(-deg2rad(θ), deg2rad(θ₂), -deg2rad(θ))
R(-deg2rad(θ), deg2rad(θ₂), -deg2rad(θ))
end
10 changes: 5 additions & 5 deletions test/rotations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
# GSLIB convention
gslib = GslibAngles(30, 15, -15)

@test gslib * v₁ ≈ [3.7410191941252595, -0.034675177060507156, 0.059774754555877996]
@test gslib * v₂ ≈ [0.8592918193713616, 0.4018496819077273, -0.011593201115905286]
@test gslib * v₁ ≈ [3.6750995527061767, 0.05226610022130146, 0.700650792097261]
@test gslib * v₂ ≈ [0.8312896937156777, 0.422146350014352, 0.17535650627123855]

# MineSight convention
minesight = MinesightAngles(30, 15, -15)

@test minesight * v₁ ≈ [3.7410191941252595, -0.034675177060507156, 0.059774754555877996]
@test minesight * v₂ ≈ [0.8592918193713616, 0.4018496819077273, -0.011593201115905286]
@test minesight * v₁ ≈ [3.6750995527061767, 0.05226610022130146, 0.700650792097261]
@test minesight * v₂ ≈ [0.8312896937156777, 0.422146350014352, 0.17535650627123855]

# comparing conventions
@test datamine ≈ vulcan
Expand All @@ -44,7 +44,7 @@
@test Rotations.params(vulcan) ≈ [θ₁, θ₂, θ₃]

θ₁, θ₂, θ₃ = 30, 15, -15
rot = RotYXZ(-deg2rad(θ), deg2rad(θ₂), -deg2rad(θ))
rot = RotZXY(-deg2rad(θ), deg2rad(θ₂), -deg2rad(θ))
gslib = GslibAngles(rot)
minesight = MinesightAngles(rot)
@test gslib ≈ minesight ≈ rot
Expand Down
Loading