From 857265b89230fb8a50e23684fc9618e629b2c15a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 9 Jun 2018 18:21:29 +0300 Subject: [PATCH] sphere point intersection --- docs/source/sphere.rst | 9 +++++++++ include/cglm/call/sphere.h | 4 ++++ include/cglm/sphere.h | 14 ++++++++++++++ src/sphere.c | 6 ++++++ 4 files changed, 33 insertions(+) diff --git a/docs/source/sphere.rst b/docs/source/sphere.rst index 427200e..db238f4 100644 --- a/docs/source/sphere.rst +++ b/docs/source/sphere.rst @@ -21,6 +21,7 @@ Functions: #. :c:func:`glm_sphere_transform` #. :c:func:`glm_sphere_merge` #. :c:func:`glm_sphere_sphere` +#. :c:func:`glm_sphere_point` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -63,3 +64,11 @@ Functions documentation Parameters: | *[in]* **s1** sphere | *[in]* **s2** other sphere + +.. c:function:: bool glm_sphere_point(vec4 s, vec3 point) + + | check if sphere intersects with point + + Parameters: + | *[in]* **s** sphere + | *[in]* **point** point diff --git a/include/cglm/call/sphere.h b/include/cglm/call/sphere.h index 9a9a59f..02c3d55 100644 --- a/include/cglm/call/sphere.h +++ b/include/cglm/call/sphere.h @@ -29,4 +29,8 @@ CGLM_EXPORT bool glmc_sphere_sphere(vec4 s1, vec4 s2); +CGLM_EXPORT +bool +glmc_sphere_point(vec4 s, vec3 point); + #endif /* cglmc_sphere_h */ diff --git a/include/cglm/sphere.h b/include/cglm/sphere.h index 4c9d79b..a7501b9 100644 --- a/include/cglm/sphere.h +++ b/include/cglm/sphere.h @@ -82,4 +82,18 @@ glm_sphere_sphere(vec4 s1, vec4 s2) { return glm_vec_distance2(s1, s2) <= glm_pow2(s1[3] + s2[3]); } +/*! + * @brief check if sphere intersects with point + * + * @param[in] s sphere + * @param[in] point point + */ +CGLM_INLINE +bool +glm_sphere_point(vec4 s, vec3 point) { + float rr; + rr = s[3] * s[3]; + return glm_vec_distance2(point, s) <= rr; +} + #endif /* cglm_sphere_h */ diff --git a/src/sphere.c b/src/sphere.c index e6b46fc..003ef87 100644 --- a/src/sphere.c +++ b/src/sphere.c @@ -31,3 +31,9 @@ bool glmc_sphere_sphere(vec4 s1, vec4 s2) { return glm_sphere_sphere(s1, s2); } + +CGLM_EXPORT +bool +glmc_sphere_point(vec4 s, vec3 point) { + return glm_sphere_point(s, point); +}