# Calculate the distance between two points

## Recommended Posts

how do I calculate the distance between two x,y points?

I tried with the opcode:

`0509: 17@ = distance_between_XY \$TEMPVAR_FLOAT_1 \$TEMPVAR_FLOAT_2 and_XY 14@ 15@ `

but the value returned was a big float

is there any way to get the distance in meters or something?

thanks

##### Share on other sites

First you'll need the X1,Y1 and X2,Y2 coordinates.

Then calculate the Square root(01FB - var,int) of: ((X2-X1)^2 + (Y2-Y1)^2)

##### Share on other sites

`0509: 0@ = distance_between_XY 1@ 2@ and_XY 3@ 4@0092: 0@ = float 0@ to_integer `

##### Share on other sites

Also, default result appears to be meters.

##### Share on other sites

Pythagorean theorem ftw!

##### Share on other sites

Pythagorean theorem ftw!

Actually its the Euclidean metric*

The Pythagorean theorem describes the relation among the three sides of a right angle rectangle; namely that the sum of the two squares of the rectangle sides² is equal to the sum of the square of the hypotenuse.

*Sorry for the typo, Mister Euklid

Edited by The_Siggi
##### Share on other sites

Well the formula for calculating the length of a vector by its endpoints in a two-dimensional plane could actually be derived from the Pythagorean theorem.

Distance Formula

Better apologize to Mister Pythagoras too.

##### Share on other sites

Thank you all for the help

##### Share on other sites

Well the formula for calculating the length of a vector by its endpoints in a two-dimensional plane could actually be derived from the Pythagorean theorem.

Distance Formula

Better apologize to Mister Pythagoras too.

The Euclidean metric is based on the statement of Pythagorean theorem, and the method uni posted above uses the first one

## Create an account

Register a new account

×