distance between two vectors

This commit is contained in:
Recep Aslantas
2017-04-09 21:14:26 +03:00
parent 86c585b9e5
commit bf18ca647e
4 changed files with 44 additions and 0 deletions

View File

@@ -117,6 +117,14 @@ CGLM_EXPORT
void
glmc_vec_proj(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT
float
glmc_vec_distance(vec3 v1, vec3 v2);
CGLM_EXPORT
float
glmc_vec4_distance(vec4 v1, vec4 v2);
#ifdef __cplusplus
}
#endif

View File

@@ -45,4 +45,10 @@ glm_make_deg(float *rad) {
*rad = *rad * 180.0f / CGLM_PI;
}
CGLM_INLINE
float
glm_pow2(float x) {
return x * x;
}
#endif /* cglm_util_h */

View File

@@ -16,6 +16,7 @@
#include "cglm-common.h"
#include "cglm-vec-ext.h"
#include "arch/simd/cglm-intrin.h"
#include "cglm-util.h"
/*!
* @brief copy all members of [a] to [dest]
@@ -493,4 +494,21 @@ glm_vec_proj(vec3 a, vec3 b, vec3 dest) {
dest);
}
CGLM_INLINE
float
glm_vec_distance(vec3 v1, vec3 v2) {
return sqrtf(glm_pow2(v2[0] - v1[0])
+ glm_pow2(v2[1] - v1[1])
+ glm_pow2(v2[2] - v1[2]));
}
CGLM_INLINE
float
glm_vec4_distance(vec4 v1, vec4 v2) {
return sqrtf(glm_pow2(v2[0] - v1[0])
+ glm_pow2(v2[1] - v1[1])
+ glm_pow2(v2[2] - v1[2])
+ glm_pow2(v2[3] - v1[3]));
}
#endif /* cglm_vec_h */

View File

@@ -162,3 +162,15 @@ void
glmc_vec_proj(vec3 a, vec3 b, vec3 dest) {
glm_vec_proj(a, b, dest);
}
CGLM_EXPORT
float
glmc_vec_distance(vec3 v1, vec3 v2) {
return glm_vec_distance(v1, v2);
}
CGLM_EXPORT
float
glmc_vec4_distance(vec4 v1, vec4 v2) {
return glm_vec4_distance(v1, v2);
}