Jump to content

Calculate the distance between two points


Vinnex89

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

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

 

 

 

 

Link to comment
Share on other sites

Also, default result appears to be meters.

Link to comment
Share on other sites

 

Pythagorean theorem ftw! smile.gif

Actually its the Euclidean metric* monocle.gif

 

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 nervous.gif

Edited by The_Siggi
Link to comment
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. tounge.gif

23088_s.gif

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

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

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
  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.