ID:268497
 
If anyone knows the standard linear distance formula, please post it here for me. I've lost my math notes and I need it for the procedure I'm working on! Thanks!

-LoW
:o

sqrt((x2-x1)^2 + (y2-y1)^2)
In response to Nubstar
Nubstar wrote:
:o

sqrt((x2-x1)^2 + (y2-y1)^2)

A few things worth noting:

  • In BYOND the power operator is **, instead of ^ as it is in some languages. (I prefer to show a formula with ^ though, so this is just a heads-up, not a critique of the post.)
  • You shouldn't use ** in your calculations if you can avoid it. Instead I'd either just multiply outright or use temporary values like dx=x2-x1.
  • If you can avoid using sqrt(), that's even better. Comparing squared distance is often as useful.

    Lummox JR
In response to Lummox JR
Many thanks. Is there a particular reason the x^y function is slower than long multiplication?
In response to Lord of Water
Many thanks. Is there a particular reason the x^y function is slower than long multiplication?

Well first of all ^ isn't really slow but it's the exclusive or operator :).

** is expensive since I'm sure it supports decimal values in the exponent so odds are it doesn't do a simple multiplication exansion.
In response to Theodis
That makes sense. Again, thanks to you forum guys. =D