Jump to content
Sign in to follow this  
corgano

distance between 2 points (Answered)

Recommended Posts

corgano

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

Share this post


Link to post
Share on other sites
martin

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.

  • Like 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 this post


Link to post
Share on other sites
trancexx

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 this post


Link to post
Share on other sites
UEZ

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
  • Like 1

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
corgano

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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.