diff options
author | Arun Isaac | 2021-02-26 19:44:19 +0530 |
---|---|---|
committer | Arun Isaac | 2021-02-26 19:44:19 +0530 |
commit | 0cfa01c973b6ead3b8a8d4dd84f2d28ece0bac04 (patch) | |
tree | 08e56c1e8d7330dba727409de15aadb69a44b612 /examples | |
parent | 941b99c4615f3b97b220725ba5c9c00367e94e4e (diff) | |
download | nsmc-0cfa01c973b6ead3b8a8d4dd84f2d28ece0bac04.tar.gz nsmc-0cfa01c973b6ead3b8a8d4dd84f2d28ece0bac04.tar.lz nsmc-0cfa01c973b6ead3b8a8d4dd84f2d28ece0bac04.zip |
Add hollow cone vector generation example.
* examples/generate-hollow-cone-vector.c: New file.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/generate-hollow-cone-vector.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/examples/generate-hollow-cone-vector.c b/examples/generate-hollow-cone-vector.c new file mode 100644 index 0000000..52cdc2d --- /dev/null +++ b/examples/generate-hollow-cone-vector.c @@ -0,0 +1,32 @@ +#include <nd-random.h> + +// Dimension of the vector to generate +#define DIMENSION 10 +// Minimum angle from the axis of the cone +#define THETA_MIN M_PI/4 +// Maximum angle from the axis of the cone +#define THETA_MAX M_PI/3 + +int main () +{ + // Initialize random number generator. + gsl_rng_env_setup(); + gsl_rng* r = gsl_rng_alloc(gsl_rng_default); + // Allocate vector to be generated. + gsl_vector *x = gsl_vector_alloc(DIMENSION); + // Allocate and initialize central axis of cone. + gsl_vector *axis = gsl_vector_alloc(DIMENSION); + gsl_vector_set_all(axis, 1/sqrt(DIMENSION)); + + // Generate random vector on spherical cap of hollow cone. + hollow_cone_random_vector(r, axis, THETA_MIN, THETA_MAX, x); + + // Print out generated vector. + gsl_vector_fprintf(stdout, x, "%g"); + + // Free allocated memory. + gsl_vector_free(axis); + gsl_vector_free(x); + gsl_rng_free(r); + return 0; +} |