
Let A (red) and B (green) 2 distinct points anywhere in a 3D space.
I am looking for a function which take a point P, and returns the value in blue in the picture.
Each blue number in the picture is a sample return value of the function if provided this very position as argument.
The frame is defined by the 2 thick black horizontal and vertical lines. The blue arrow is just an illustration to show the gradient that results from this function. It doesn't indicate anything in particular.
My first guess would be:
Normalize everything by subtracting A from both B and P.
Get the projection P' of P against AB.
F(P) = |P'| / |AB|
I think this would work, but I wonder if there is an algebraic trick to avoid some useless step.
Any hint?