distance between two points

BlitzMax Forums/BlitzMax Beginners Area/distance between two points

hub(Posted 2006) [#1]
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 !


Scott Shaver(Posted 2006) [#2]
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


Tom Darby(Posted 2006) [#3]
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...


Rck(Posted 2006) [#4]
For pro geometry, Wikipedia: Rational Trig


hub(Posted 2006) [#5]
many thanks for your help !
Nice link Rck !