My question is based upon this question. I would like to have horizontal and vertical distance shown as x and y below, between 2 geospatial points p1 and p2.

Shall I find the M coordinate by :
M$lat = p1$lat
M$lon = p2$lon
and then compute x and y by :
x = distm(p1,M,fun = distHaversine)
y = distm(p1,M,fun = distHaversine)
Or there is a straightforward method to do this? In addition, How could I define a direction ? Imagine we have p3 on the left side of p1, then the new x will have the opposite direction, which with distm I'm not able to catch it.