I have got a line with two points and a single point. I need to check whether the single point is between the line (i.e. between the two points) given, including the two points given.

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
end

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.

At the scale of the screenshots, the solution will apply.

Algorithms for geographic coordinates will be added in the near future. It is an implementation detail that we also plan to hide from end users, who don’t care about all this GIS idiosyncrasy.

Hence OP example in the question is wrong, as that point is NOT on the line.

Or, maybe, OP is intending those terms in a slight different way from the geometrical one. As you would when you say that Florence is between Milan and Rome.