Question

enter image description here

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.

Was it helpful?

Solution

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)

OTHER TIPS

you could use absolute value, i.e., abs(a - b)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top