When determining distance between two points using trigonometry like so:
x = p2.x - p1.x
y = p2.y - p1.y
distance = Math.sqrt(x * x + y * y)
Should I use the absolute value of X and Y? so:
x = Math.abs(p2.x - p1.x)
y = Math.abs(p2.y - p1.y)
distance = Math.sqrt(x * x + y * y)
Since distance can't be negative? I ask because all of the examples I see online, do not use absolute values, with this exception:
http://www.themathpage.com/alg/pythagorean-distance.htm
But the language I am working with (JavaScript) won't allow me try and get the square root of a negative number. I just want to confirm that getting the absolute value is correct, and doesn't change the distance / value returned.
The answer is, it does not matter because you immediately square $x$ and $y$. You will get the same answer. $\forall x\in\mathbb{R},x^2\ge 0$. So it will always be the case that $x^2=|x|^2$, and your computation of distance will not differ depending on whether or not you take the absolute value. So calling the function abs() is not necessary.