 Thread: How to get X+Y distance?

1. How to get X+Y distance?

I have a problem here, I want to get the ABS of x+y, but I can only stick to one of then...

In a zelda-like game I would need both distances as one value, how can I do that?

---

As an example, if I have lots of dots on screen, and I set the scale posion to the dots in relation to the mouse pointer, instead of getting a cool water effect I got some sort of horizontal/ vertical effect, because I can only stick to abs Y or abs X, and not a general distance value.  Reply With Quote

2. Re: How to get X+Y distance?

sqrt(x pow 2 + y pow 2)

i.e. square root of (x² + y²)

EDIT: Also you can do abs(x+y), I don't see why you say you can only do abs of x or y and not both. It won't get you a circle though, you need the formula above for that.  Reply With Quote

3. Re: How to get X+Y distance?

I'm not entirely sure what you want.

The euclidean distance between two points- the shortest distance between them, is given as sqrt(x pow 2 + y pow 2) as Dynasoft gave. However, if what you're asking for is the "Manhattan Distance", that is, the distance when you can only travel vertically or horizontally, that is given as:

Max(Abs(>X Point 1<->X Point 2<), Abs(>Y Point 1<->Y Point 2<))

The distance if you can only travel horizontally, vertically or diagonally, is given as:

Abs(>X Point 1<->X Point 2<)+Abs(>Y Point 1<->Y Point 2<)
(the chebyshev distance)

Thank sketchy's snippet editor for those.  Reply With Quote

4. Re: How to get X+Y distance?

>> Thank sketchy's snippet editor for those.

I have done a search for this with 200 results but most highlighting 'editor.' Do you know of a link to this? This would be very useful if it contains more examples as above.  Reply With Quote

5. Re: How to get X+Y distance?

Sketchy's generally the guy to go to for his stuff!

Its incredibly handy if you use those formulas a lot!  Reply With Quote

6. Re: How to get X+Y distance?

This one works too!  Reply With Quote

7. Re: How to get X+Y distance?

Thanks for the links. That is so cool. I do enjoy the possibilities of tweaking MMF with the math - sometimes to the point of distraction I wonder if there is/are any snippet repository beyond what comes with the download. I was working on a parabola that would probably work into this scheme and would be happy to post it ?somewhere?

thanks again - ak  Reply With Quote

8. Re: How to get X+Y distance?

Snippet is a life saver, thanks A LOT for who did this!  Reply With Quote Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•