Do you mean whether the point is lying on the line segment between two points? (Then your initial question should be answered no, as that point is slightly off the line)
Do you mean the point is in the “slice” of plane between the two points (as defines by the normal to the line segment connecting the two points, at those two points)? In that case, the latter question should be yes.
Yupp, it doesn’t check if the point is actually on the line. For that, you need to check if the norm of the cross product is (near) zero. My snippet above checks if the point is between the two endpoints assuming it is on the line.
Here’s an adjusted version that also checks for being on the segment:
function between(a, b, p; tol = 1e-10)::Bool
v1 = b - a
v2 = p - a
return isapprox(dot(v1, v2), norm(v1) * norm(v2); rtol = tol) &&
-tol <= dot(v1 / norm(v1), v2 / norm(v1)) <= 1 + tol
All this confusion is one of my main gripes with GIS standards. Back in the days, someone decided to give the name “line” to what actually is a line segment in mathematics.
@Chamika_Kasun you can always check the source code of our Meshes.jl submodule when you need to learn about these geometric algorithms, it is plain simple Julia code:
Don’t reinvent the wheel re-implementing these algorithms from scratch, because they can be quite tricky to get right. There are too many corner cases that we are still fixing with various industrial applications.