Distance between SimpleVectors

Started by bigfishcatcher, September 05, 2008, 01:57:23 AM

Previous topic - Next topic

bigfishcatcher

Is there a way to get a float value to represents the distance between SimpleVectors

Thanks

paulscode

A method like this should work:

public float distanceBetweenVectors( SimpleVector a, SimpleVector b )
{
    return (float) Math.sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) + (a.z-b.z)*(a.z-b.z) );
}


bigfishcatcher

Thanks, that really makes my life easier.


paulscode


EgonOlsen

Another way to do it:


s1.calcSub(s2).length();


Maybe i should add that method to SimpleVector...

AGP

While you're at it, why not a calculateAngle(SimpleVector origin, SimpleVector p1, SimpleVector p2)?