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 implementation #193

Merged
merged 1 commit into from
Dec 28, 2023
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: 17 additions & 11 deletions src/rotations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ end
"""
GslibAngles(θ₁, θ₂, θ₃)

GSLIB ZXY rotation convention following the left-hand rule.
All angles are in degrees and the signal convention is CW, CCW, CCW
positive. Y is the principal axis.
GSLIB YXZ 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.

## References

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

function Base.convert(::Type{R}, rot::RotZYX) where {R<:GslibAngles}
rottype(::Type{<:GslibAngles}) = RotYXZ

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

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

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

MineSight YZX rotation convention following the right-hand rule.
MineSight YXZ 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.
The second rotation is a rotation around the new X-axis, which moves the Y-axis into the
The first rotation `θ₁` is a horizontal rotation around the Z-axis, with positive being clockwise.
The second rotation `θ₂` is a rotation around the new X-axis, which moves the Y-axis into the
desired position, with positive direction of rotation is up.
The third rotation is a rotation around the new Y-axis, which moves the X-axis into the
The third rotation `θ₃` is a rotation around the new Y-axis, which moves the X-axis into the
desired position, with positive direction of rotation is up.

## References
Expand Down
35 changes: 16 additions & 19 deletions test/rotations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,31 @@
@test datamine * v₁ ≈ [3.0810411262386967, 1.2425629737653001, 1.7214014158973259]
@test datamine * v₂ ≈ [0.7601180732526871, 0.5597366702348654, 0.09442126195411826]

# GSLIB convention
gslib = GslibAngles(70, -30, 20)

@test gslib * v₁ ≈ [3.0810411262386967, 1.2425629737653001, 1.7214014158973259]
@test gslib * v₂ ≈ [0.7601180732526871, 0.5597366702348654, 0.09442126195411826]

# Vulcan convention
vulcan = VulcanAngles(70, -30, -20)

@test vulcan * v₁ ≈ [3.0810411262386967, 1.2425629737653001, 1.7214014158973259]
@test vulcan * v₂ ≈ [0.7601180732526871, 0.5597366702348654, 0.09442126195411826]

# 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]

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

@test minisight * v₁ ≈ [3.7410191941252595, -0.034675177060507156, 0.059774754555877996]
@test minisight * v₂ ≈ [0.8592918193713616, 0.4018496819077273, -0.011593201115905286]
@test minesight * v₁ ≈ [3.7410191941252595, -0.034675177060507156, 0.059774754555877996]
@test minesight * v₂ ≈ [0.8592918193713616, 0.4018496819077273, -0.011593201115905286]

# comparing conventions
@test datamine ≈ gslib
@test datamine ≈ vulcan
@test gslib ≈ vulcan
@test gslib ≈ minesight

# rotation conversion
rot = RotZXY(0.1, 0.2, 0.3)
@test DatamineAngles(rot) ≈ GslibAngles(rot) ≈ VulcanAngles(rot) ≈ rot
@test DatamineAngles(rot) ≈ VulcanAngles(rot) ≈ rot

θ₁, θ₂, θ₃ = -15, 45, 30
rot = RotZYX(deg2rad(θ₃), -deg2rad(θ₂), deg2rad(θ₁ - 90))
Expand All @@ -44,13 +43,11 @@
vulcan = VulcanAngles(rot)
@test Rotations.params(vulcan) ≈ [θ₁, θ₂, θ₃]

rot = RotZYX(-deg2rad(θ₃), deg2rad(θ₂), deg2rad(θ₁ - 90))
gslib = GslibAngles(rot)
@test Rotations.params(gslib) ≈ [θ₁, θ₂, θ₃]

θ₁, θ₂, θ₃ = 30, 15, -15
rot = RotYXZ(-deg2rad(θ₃), deg2rad(θ₂), -deg2rad(θ₁))
minisight = MinesightAngles(rot)
@test minisight ≈ rot
@test Rotations.params(minisight) ≈ [θ₁, θ₂, θ₃]
gslib = GslibAngles(rot)
minesight = MinesightAngles(rot)
@test gslib ≈ minesight ≈ rot
@test Rotations.params(gslib) ≈ [θ₁, θ₂, θ₃]
@test Rotations.params(minesight) ≈ [θ₁, θ₂, θ₃]
end