How to find a relative position of an object that is not touching the ray? (As the example in the figure)

-The Point “A” to create a straight line (ray), and I would like to know where the “B” point would be located if crossing the ray?

check the links I put on that thread, go on to how those functions are used

You want the orthogonal projection of B on the line passing through the point A in the direction v (a normalized vector).

Then the projection B’ can be computed using the dot product:

B’ = A + v*dot(A, B - A)

Edit:

Note that if dot(A, B - A) is negative, then B’ does not belong to the ray.