From b1811358664496f79ef8030dee1f5c53e1a8569f Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Fri, 18 Feb 2022 23:01:57 -0500 Subject: Initial implementation of point_within_cone() Initial implementation of point_within_cone(), without affine transformation of input to align cone on X axis --- src/spatial.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src') diff --git a/src/spatial.c b/src/spatial.c index f031ceb..98728df 100644 --- a/src/spatial.c +++ b/src/spatial.c @@ -12,6 +12,37 @@ static inline float dist(xas_spatial_coord a, xas_spatial_coord b) { + powf(b.z - a.z, 2.0f), 0.5f); } +static int point_within_cone(xas_spatial_coord coord, + xas_spatial_cone cone) { + float radius; + + /* + * XXX Perform an affine transformation of the point along with the cone, + * fixing the point of the cone at 0, 0, 0 with the open end facing to the + * right on the X axis + */ + + /* + * If the point is to the left of the cone point, then the point is not + * within the cone. + */ + if (coord.x < cone.coord.x) { + return 0; + } + + radius = tanf(cone.angle / 2.0f) * cone.coord.x; + + /* + * If the given point is outside the cone radius at its X coordinate, then + * it is outside of the cone. + */ + if (fabs(coord.y) < radius || fabs(coord.z) < radius) { + return 0; + } + + return 1; +} + static int buffer_realloc(xas_spatial_scene *scene, xas_spatial_buffer *buffer) { float seconds = scene->radius / scene->speed; -- cgit v1.2.3