Jump to content

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

Link to comment
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.

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.
Link to comment
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

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

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

Link to comment
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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...