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.

有帮助吗?

解决方案

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)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top