You have the answer already, you subtract the x coordinate from one point to the other. You simply need to take the absolute value of that and then it doesn't matter which one is greater.
absoluteValue(Ax - Bx) = absoluteValue(Bx - Ax)
Вопрос
How can I find the distance between the two points as shown in the above picture.
I know I can use Pythagoras to find the 'actual' distance between the two points, but I want to find the X distance between them only.
Also, obviously I know I can subtract the x coordinate of point A from that of Point B, but this won't help because they might be the other way around (i.e., B might be on the left and A on the right).
Would be grateful if someone could advise the simplest method to discover this distance.
Решение
You have the answer already, you subtract the x coordinate from one point to the other. You simply need to take the absolute value of that and then it doesn't matter which one is greater.
absoluteValue(Ax - Bx) = absoluteValue(Bx - Ax)
Другие советы
you could use absolute value, i.e., abs(a - b)