Distance to simplicies

General interface

distancetosimplex yields a distance and barycentric coordinates of the projection point.

DistanceQueries.distancetosimplexFunction
d, λ = distancetosimplex(y, x::NTuple{M,SVector{N, T}})

Get the distance d::T to the simplex spanned by M points x and barycentric coordinates λ::NTuple{N, T} of the projection of y.

source
Todo

Distance to tetrahedron.

Line segment

Compute distancetolinesegment with projectontolinesegment and projectontoline.

Note

In contrast to distancetosimplex only one of the two (linearly dependent) barycentric coordinates, the line parameter t, is returned.

DistanceQueries.distancetolinesegmentMethod
d, t = distancetolinesegment(x, (a,b))

Compute distance of x to line segment (a,b).

Returns (d, t) with distance d and parameter 0 <= t <= 1 such that projection point is (1-t)*a + t*b.

source

Triangle

Compute distancetotriangle with projection point in barycentriccoordinates.

DistanceQueries.barycentriccoordinatesMethod
λ = barycentriccoordinates(x, (a,b,c)) # in 2d

Compute barycentric coordinates of x w.r.t. to planar triangle (a,b,c).

This function will always return finite barycentric coordinates, even if the triangle is degenerated.

source
DistanceQueries.distancetotriangleFunction
d, λ = distancetotriangle(x, (a,b,c))
d, λ = distancetotriangle(::Val{2}, x, (a,b,c)) # in 2d
d, λ = distancetotriangle(::Val{3}, x, (a,b,c)) # in 3d

Compute distance of x to triangle (a,b,c).

Returns (d, λ) with distance d and barycentric coordinates λ.

source