diff options
author | XANTRONIX Development | 2022-02-18 23:01:57 -0500 |
---|---|---|
committer | XANTRONIX Development | 2022-02-18 23:03:10 -0500 |
commit | b1811358664496f79ef8030dee1f5c53e1a8569f (patch) | |
tree | 43e8d768ced4363fee18cedc21162c44b93ee52e /src | |
parent | 0325c2f9b1be6dbc76b97f23be15e6475da5a5fd (diff) | |
download | xas-b1811358664496f79ef8030dee1f5c53e1a8569f.tar.gz xas-b1811358664496f79ef8030dee1f5c53e1a8569f.tar.bz2 xas-b1811358664496f79ef8030dee1f5c53e1a8569f.zip |
Initial implementation of point_within_cone()
Initial implementation of point_within_cone(), without affine
transformation of input to align cone on X axis
Diffstat (limited to 'src')
-rw-r--r-- | src/spatial.c | 31 |
1 files changed, 31 insertions, 0 deletions
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; |