Fast point-to-triangle distance computation in 3D
This program is mostly based on the study by Jones (1995).
pkg> add https://github.com/KeitaNakamura/PointToTriangle.jl.git
Using the isbitstype
type of AbstractVector
, such as SVector
in StaticArrays.jl, is recommended for sake of performance.
julia> using PointToTriangle, StaticArrays
julia> a, b, c = rand(SVector{3}), rand(SVector{3}), rand(SVector{3});
julia> tri = PointToTriangle.Triangle(a, b, c);
julia> p = rand(SVector{3});
julia> d = PointToTriangle.vector(p, tri) # compute point-to-triangle distance vector
3-element SVector{3, Float64} with indices SOneTo(3):
0.21019419472595702
-0.2926549510617162
-0.1669372773882311
julia> using Plots
julia> plotlyjs()
julia> plot(map(Tuple, [a,b,c,a]))
julia> plot!(map(Tuple, [p,p+d]))
julia> using GLMakie
julia> lines([a b c a])
julia> lines!([p p+d])
![](https://private-user-images.githubusercontent.com/16015926/288962083-64818c53-fa8e-4bcb-81e1-29b5c88076cf.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ5NjkwNjEsIm5iZiI6MTcyNDk2ODc2MSwicGF0aCI6Ii8xNjAxNTkyNi8yODg5NjIwODMtNjQ4MThjNTMtZmE4ZS00YmNiLTgxZTEtMjliNWM4ODA3NmNmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI5VDIxNTkyMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTA0NGU5NTljZjRiNTY0YWU3YThkZTA4YjNkYzAwZmNjNmRkODQ4OTNmNDVjMDJhMGNmYjViYjk0MTE1ZGM0YzEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.IN2wGsbyUdTmKAD8cDT6WvZJ_L5zkv6s2roIoeCROa4)