55 lines
1.2 KiB
C
55 lines
1.2 KiB
C
#include <math.h>
|
|
#include <stdio.h>
|
|
|
|
#define KLEIN_IMPLEMENT
|
|
#include <klein/klein.h>
|
|
#include <klein/norm.h>
|
|
#include <klein/parm.h>
|
|
|
|
int p = 37;
|
|
int q = 1;
|
|
|
|
void lens(float *d_surface, int *coord, unsigned char * grid)
|
|
{
|
|
|
|
float norm = 0;
|
|
float sphere[4];
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
sphere[i] = ((float)coord[i] / grid[i]) - 0.5;
|
|
|
|
for(int i = 0; i < 4; i++)
|
|
norm += sphere[i] * sphere[i];
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
sphere[i] = sphere[i] / sqrt(norm);
|
|
|
|
d_surface[0] = (sphere[0] * cos(2 * M_PI / p)) - (sphere[1] * sin(2 * M_PI / p));
|
|
d_surface[1] = (sphere[0] * sin(2 * M_PI / p)) + (sphere[1] * cos(2 * M_PI / p));
|
|
d_surface[2] = (sphere[2] * cos(2 * M_PI * q / p)) - (sphere[3] * sin(2 * M_PI * q / p));
|
|
d_surface[3] = (sphere[2] * sin(2 * M_PI * q / p)) + (sphere[3] * cos(2 * M_PI * q / p));
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
char file_name[0xff];
|
|
struct klein klein;
|
|
struct parm parametrization = {
|
|
.grid = (unsigned char[]){8, 8,8,8},
|
|
.m = 4,
|
|
.n = 4,
|
|
.f = lens,
|
|
};
|
|
|
|
snprintf(file_name, 0xff, "%03d-%03d-cube.klein", p, q);
|
|
printf("writing %s\n", file_name);
|
|
|
|
klein_parametrize(&klein, parametrization);
|
|
klein_normalize(&klein);
|
|
klein_export_file(klein, file_name);
|
|
|
|
free(klein.vertex);
|
|
free(klein.normals);
|
|
return 0;
|
|
}
|