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]
[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]
