aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2021-02-26 19:37:12 +0530
committerArun Isaac2021-02-26 19:37:12 +0530
commit941b99c4615f3b97b220725ba5c9c00367e94e4e (patch)
tree4734f773ff6dfeae634d2809e07d2055b15696f0
parent9473d1260d7742fe8c8fdeab01688e4cc102f3ef (diff)
downloadnsmc-941b99c4615f3b97b220725ba5c9c00367e94e4e.tar.gz
nsmc-941b99c4615f3b97b220725ba5c9c00367e94e4e.tar.lz
nsmc-941b99c4615f3b97b220725ba5c9c00367e94e4e.zip
Add cone vector generation example.
* examples/generate-cone-vector.c: New file.
-rw-r--r--examples/generate-cone-vector.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/examples/generate-cone-vector.c b/examples/generate-cone-vector.c
new file mode 100644
index 0000000..32566b4
--- /dev/null
+++ b/examples/generate-cone-vector.c
@@ -0,0 +1,30 @@
+#include <nd-random.h>
+
+// Dimension of the vector to generate
+#define DIMENSION 10
+// Maximum angle from the axis of the cone
+#define THETA_MAX M_PI/4
+
+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 cone.
+ cone_random_vector(r, axis, 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;
+}