Skip to content

Commit 341dd17

Browse files
author
Thimoté Dupuch
committed
improved docs for intersectLineToPlane3D + getindex refactoring
1 parent 85df6a5 commit 341dd17

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

src/entities/GeneralTypes.jl

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,11 @@ struct PixelIndex{VALID, T <: Real}
55
end
66
PixelIndex(u::T, v::T; valid::Bool = true, depth = T(0)) where {T <: Real} = PixelIndex{valid, T}(u, v, depth)
77

8-
function Base.getindex(p::PixelIndex, i::Int)
9-
return if i === 1
10-
p.row
11-
elseif i === 2
12-
p.col
13-
elseif i === 3
14-
p.depth
15-
else
16-
DomainError("Camera only has rows and columns, cannot index to $i")
17-
end
18-
end
8+
Base.getindex(p::PixelIndex, i::Int) =
9+
i == 1 ? p.row :
10+
i == 2 ? p.col :
11+
i == 3 ? p.depth :
12+
throw(DomainError(i, "Camera only has rows, columns and depth"))
1913

2014

2115
const Vector2 = SVector{2, Float64}

src/services/Utils.jl

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,36 @@ function radialDistortion!(
8282
return nothing
8383
end
8484

85+
"""
86+
intersectLineToPlane3D(planenorm, planepnt, raydir, raypnt) -> point
87+
88+
Compute the unique intersection point between an infinite 3-D line (ray) and a plane.
89+
90+
# Arguments
91+
- `planenorm::AbstractVector{<:Real}` – plane normal vector (need not be unit-length)
92+
- `planepnt::AbstractVector{<:Real}` – any point lying on the plane
93+
- `raydir::AbstractVector{<:Real}` – direction vector of the line (need not be unit-length)
94+
- `raypnt::AbstractVector{<:Real}` – any point lying on the line
8595
96+
# Returns
97+
- `ψ::Vector{<:Real}` – coordinates of the intersection point
98+
99+
# Throws
100+
- `ErrorException` if the line is parallel to the plane (no intersection or line lies in plane).
101+
"""
86102
function intersectLineToPlane3D(
87103
planenorm::AbstractVector{<:Real},
88104
planepnt::AbstractVector{<:Real},
89105
raydir::AbstractVector{<:Real},
90106
raypnt::AbstractVector{<:Real}
91107
)
92-
ndotu = dot(planenorm, raydir)
93-
if ndotu 0
108+
n_dot_u = dot(planenorm, raydir)
109+
if n_dot_u 0
94110
error("no intersection or line is within plane")
95111
end
96112

97113
w = raypnt - planepnt
98-
si = -dot(planenorm, w) / ndotu
114+
si = -dot(planenorm, w) / n_dot_u # ray parameter at intersection
99115
ψ = w .+ si .* raydir .+ planepnt
100116
return ψ
101117
end

0 commit comments

Comments
 (0)