Skip to content

Instantly share code, notes, and snippets.

@anael-seghezzi
Last active January 6, 2017 06:57
Show Gist options
  • Save anael-seghezzi/c946c41dbd839a193553b245315277b2 to your computer and use it in GitHub Desktop.
Save anael-seghezzi/c946c41dbd839a193553b245315277b2 to your computer and use it in GitHub Desktop.
// hyper-sphere coordinates
void n_sphere(float *out, float *in, int n)
{
double x; int i;
x = in[0] * in[0] + in[1] * in[1];
out[1] = in[0] < 0 ? M_PI*2 - acos(in[1] / sqrt(x)) : acos(in[1] / sqrt(x));
for (i = 2; i < n; i++) {
x += in[i] * in[i];
out[i] = acos(in[i] / sqrt(x));
}
out[0] = sqrt(x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment