# distance between 2 points (Answered)

## Recommended Posts

I need a simple way to mesure the distance between 2 points. Couldnt find in help file or in search.

Say I wanted to find the distance (in pixles) between 200,300, and 400, 100.

How would I do it?

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Subtraction!

##### Share on other sites

Subtraction!

Nonsense!

The distance between points x,y and a,b is

((a-x)2 + (b-y)2)0.5

it's just the hypotenuse of the triangle (or the diagonal of the square) made by the line between the points and the vertical and horizontal lines through the points.

• 1

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

##### Share on other sites

Yes, but for example, how do I calcuate the distance between, let's say, three points?

Come on, this is a joke... you got that, right? :Р

.

eMyvnE

##### Share on other sites

You can use Pythagoras to calculate distance between 2 points (2D):

```Func Pixel_Distance(\$x1, \$y1, \$x2, \$y2) ;Pythagoras theorem for 2D
Local \$a, \$b, \$c
If \$x2 = \$x1 And \$y2 = \$y1 Then
Return 0
Else
\$a = \$y2 - \$y1
\$b = \$x2 - \$x1
\$c = Sqrt(\$a * \$a + \$b * \$B)
Return \$c
EndIf
EndFunc   ;==>Pixel_Distance```

If you want to calculate the distance for more than 2 point just calculate it between each points and sum the results.

The slope of two points: m = (y2 - y1) / (x2 - x1)

Just have a look to my GDI+ examples "Simple Ball Collision Simulation" where I used it!

UEZ

Edited by UEZ
• 1

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

##### Share on other sites

You can use Pythagoras to calculate distance between 2 points (2D):

```Func Pixel_Distance(\$x1, \$y1, \$x2, \$y2) ;Pythagoras theorem for 2D
Local \$a, \$b, \$c
If \$x2 = \$x1 And \$y2 = \$y1 Then
Return 0
Else
\$a = \$y2 - \$y1
\$b = \$x2 - \$x1
\$c = Sqrt(\$a * \$a + \$b * \$B)
Return \$c
EndIf
EndFunc   ;==>Pixel_Distance```

If you want to calculate the distance for more than 2 point just calculate it between each points and sum the results.

Just have a look to my GDI+ examples "Simple Ball Collision Simulation" where I used it!

UEZ

Thankyou all, i have found what i have been looking for.

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

## Create an account

Register a new account

×

• Wiki

• Back

• Git