1. ## Calculate vector distance

Simple snippets in calculating vector distances.

[highlight=vb.net]Private Structure Vector
Public x As Single
Public y As Single
Public z As Single
End Structure

Private Function VectorDistance(ByVal vec1 As Vector, ByVal vec2 As Vector) As Double
Return Math.Sqrt(Math.Pow(vec1.x - vec2.x, 2) + Math.Pow(vec1.y - vec2.y, 2) + Math.Pow(vec1.z - vec2.z, 2))
End Function[/highlight]

[highlight=c++]#include <math.h>

typedef struct {
float x;
float y;
float z;
} Vector;

float VectorDistance(Vector vec1, Vector vec2)
{
return sqrt(pow(vec1.x - vec2.x, 2) + pow(vec1.y - vec2.y, 2) + pow(vec1.z - vec2.z, 2));
}[/highlight]

2. ## The Following 4 Users Say Thank You to master131 For This Useful Post:

cgallagher21 (05-22-2011),Locke (05-22-2011),lolbie (05-22-2011),Yamato (05-22-2011)

3. This is nice. Always fun to learn/watch new codes I've never seen before.

4. Looks Great Master

5. nice you just learned that with c++? ;p

6. Nice brain tommy. Well this would be nice if u want to make a aimbot, with a specific angle of distance :P

7. Originally Posted by lolbie
nice you just learned that with c++? ;p
erm, no. I googled 3D Math craps and found some formulas.

8. what program do u guys use to compile this? Visual basic ?