Add lightcone
This commit is contained in:
1
Makefile
1
Makefile
@@ -15,7 +15,6 @@ EXAMPLES = \
|
|||||||
example/basic \
|
example/basic \
|
||||||
example/riemman \
|
example/riemman \
|
||||||
example/n-cube \
|
example/n-cube \
|
||||||
example/n-hilbert-cube \
|
|
||||||
example/light-cone \
|
example/light-cone \
|
||||||
example/lens
|
example/lens
|
||||||
|
|
||||||
|
|||||||
51
example/light-cone.c
Normal file
51
example/light-cone.c
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define KLEIN_IMPLEMENT
|
||||||
|
#include <klein/klein.h>
|
||||||
|
#include <klein/norm.h>
|
||||||
|
#include <klein/parm.h>
|
||||||
|
|
||||||
|
void lightcone(float *d_surface, int *coord, unsigned char * grid)
|
||||||
|
{
|
||||||
|
|
||||||
|
const int n = 3;
|
||||||
|
float norm = 0;
|
||||||
|
float sphere[4];
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
sphere[i] = ((float)coord[i] / grid[i]) - 0.5;
|
||||||
|
|
||||||
|
for(int i = 0; i < n; i++)
|
||||||
|
norm += sphere[i] * sphere[i];
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
sphere[i] = sphere[i] / sqrt(norm);
|
||||||
|
|
||||||
|
float d = ((float)coord[3]/grid[3]) ;
|
||||||
|
d_surface[0] = d* sphere[0];
|
||||||
|
d_surface[1] = d* sphere[1];
|
||||||
|
d_surface[2] = d* sphere[2];
|
||||||
|
d_surface[3] = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
char * file_name = "lightcone";
|
||||||
|
struct klein klein;
|
||||||
|
struct parm parametrization = {
|
||||||
|
.grid = (unsigned char[]){8, 8,8,8},
|
||||||
|
.m = 4,
|
||||||
|
.n = 4,
|
||||||
|
.f = lightcone,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
klein_parametrize(&klein, parametrization);
|
||||||
|
klein_normalize(&klein);
|
||||||
|
klein_export_file(klein, file_name);
|
||||||
|
|
||||||
|
free(klein.vertex);
|
||||||
|
free(klein.normals);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user