www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: bigfishcatcher on September 05, 2008, 01:57:23 am

Title: Distance between SimpleVectors
Post by: bigfishcatcher on September 05, 2008, 01:57:23 am
Is there a way to get a float value to represents the distance between SimpleVectors

Thanks
Title: Re: Distance between SimpleVectors
Post by: paulscode on September 05, 2008, 02:22:44 am
A method like this should work:

Code: [Select]
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) );
}
Title: Re: Distance between SimpleVectors
Post by: bigfishcatcher on September 05, 2008, 02:33:47 am
Thanks, that really makes my life easier.

Title: Re: Distance between SimpleVectors
Post by: paulscode on September 05, 2008, 03:42:50 am
No problem  ;D
Title: Re: Distance between SimpleVectors
Post by: EgonOlsen on September 05, 2008, 09:24:13 am
Another way to do it:

Code: [Select]
s1.calcSub(s2).length();

Maybe i should add that method to SimpleVector...
Title: Re: Distance between SimpleVectors
Post by: AGP on September 06, 2008, 05:30:21 am
While you're at it, why not a calculateAngle(SimpleVector origin, SimpleVector p1, SimpleVector p2)?