distance between two points

BlitzMax Forums/BlitzMax Beginners Area/distance between two points

How to compute distance between to points ?

for example between
a(-150,20) and b(200,400)
or
a(10,25) and b(-250,140)
or
a(10,20) and b(100,56)

i use this formulae but not work properly :

dx = (bx-ax)^2
dy = (by-ay)^2
distance = sqr(dx+dy)

Thanks !

That looks right to me.

Function Vec2DDistance:Double(v1:Vector2D, v2:Vector2D)
Local ySeparation:Double = v2.y - v1.y
Local xSeparation:Double = v2.x - v1.x
Return Sqr(ySeparation*ySeparation + xSeparation*xSeparation)
End Function

Bear in mind that if you're calculating distance for comparative purposes (for example, you only want to find the shortest or longest distance in a set) and you don't need to know the exact distance itself, you can save time by skipping the square root and only comparing the sum of the squares...

For pro geometry, Wikipedia: Rational Trig

many thanks for your help !
Nice link Rck !