computeRotationMatrix

This commit is contained in:
Florian Stecker 2019-02-11 15:28:37 +01:00
parent 91bd66f057
commit c322a2ce7a
2 changed files with 37 additions and 29 deletions

64
main.c
View File

@ -57,41 +57,47 @@ void destroyContext(DrawingContext *ctx)
workspace_free(ctx->ws);
}
void computeRotationMatrix(DrawingContext *ctx, gsl_matrix *result, const char *type)
{
gsl_matrix *tmp = getTempMatrix(ctx->ws);
gsl_matrix *rot_basis = getTempMatrix(ctx->ws);
gsl_matrix **gen = getTempMatrices(ctx->ws, 3);
ERROR(strlen(type) != 2, "Invalid call of computeRotationMatrix()\n");
initializeTriangleGenerators(gen, ctx->cartan);
gsl_matrix_set_identity(tmp);
multiply_right(tmp, gen[type[0]-'a'], ctx->ws);
multiply_right(tmp, gen[type[1]-'b'], ctx->ws);
gsl_eigen_nonsymmv_params(0, ctx->ws->work_nonsymmv);
int r = gsl_eigen_nonsymmv(tmp, ctx->ws->eval_complex, ctx->ws->evec_complex, ctx->ws->work_nonsymmv);
ERROR(r, "gsl_eigen_nonsymmv failed!\n");
LOOP(i) {
gsl_complex x = gsl_matrix_complex_get(ctx->ws->evec_complex, i, 0);
gsl_complex y = gsl_matrix_complex_get(ctx->ws->evec_complex, i, 1);
gsl_complex z = gsl_matrix_complex_get(ctx->ws->evec_complex, i, 2);
gsl_matrix_set(tmp, i, 0, GSL_REAL(x)+GSL_REAL(y));
gsl_matrix_set(tmp, i, 1, GSL_IMAG(x)-GSL_IMAG(y));
gsl_matrix_set(tmp, i, 2, GSL_REAL(z));
}
invert(tmp, result, ctx->ws);
releaseTempMatrices(ctx->ws, 5);
}
void updateMatrices(DrawingContext *ctx)
{
double angle[3];
LOOP(i) angle[i] = M_PI*ctx->k[i]/ctx->p[i];
cartanMatrix(ctx->cartan, angle[0], angle[1], angle[2], ctx->parameter);
if(!ctx->use_rotation_basis)
gsl_matrix_memcpy(ctx->cob, ctx->cartan); // is this a good choice of basis
else {
gsl_matrix *tmp = getTempMatrix(ctx->ws);
gsl_matrix *rot_basis = getTempMatrix(ctx->ws);
gsl_matrix **gen = getTempMatrices(ctx->ws, 3);
initializeTriangleGenerators(gen, ctx->cartan);
gsl_matrix_set_identity(tmp);
multiply_right(tmp, gen[0], ctx->ws);
multiply_right(tmp, gen[2], ctx->ws);
gsl_eigen_nonsymmv_params(0, ctx->ws->work_nonsymmv);
int r = gsl_eigen_nonsymmv(tmp, ctx->ws->eval_complex, ctx->ws->evec_complex, ctx->ws->work_nonsymmv);
ERROR(r, "gsl_eigen_nonsymmv failed!\n");
LOOP(i) {
gsl_complex x = gsl_matrix_complex_get(ctx->ws->evec_complex, i, 0);
gsl_complex y = gsl_matrix_complex_get(ctx->ws->evec_complex, i, 1);
gsl_complex z = gsl_matrix_complex_get(ctx->ws->evec_complex, i, 2);
gsl_matrix_set(tmp, i, 0, GSL_REAL(x)+GSL_REAL(y));
gsl_matrix_set(tmp, i, 1, GSL_IMAG(x)-GSL_IMAG(y));
gsl_matrix_set(tmp, i, 2, GSL_REAL(z));
}
invert(tmp, ctx->cob, ctx->ws);
releaseTempMatrices(ctx->ws, 5);
}
if(ctx->use_rotation_basis)
computeRotationMatrix(ctx, ctx->cob, "ac");
else
gsl_matrix_memcpy(ctx->cob, ctx->cartan); // is this a good choice of basis for any reason?
}
void print(DrawingContext *screen)

2
main.h
View File

@ -66,6 +66,7 @@ void drawSegment(DrawingContext *ctx, vector_t a, vector_t b);
void drawPolygon(DrawingContext *ctx, int segments, int sides, ...);
void drawTriangle(DrawingContext *ctx, const char *word);
void drawBox(DrawingContext *ctx, const char *word1, const char *word2);
void drawBoxLines(DrawingContext *ctx, const char *word1, const char *word2);
void drawBoxStd(DrawingContext *ctx, const char *word, char base);
void drawReflectors(DrawingContext *ctx);
void drawAttractors(DrawingContext *ctx);
@ -80,6 +81,7 @@ void setupContext(DrawingContext *ctx);
void destroyContext(DrawingContext *ctx);
void print(DrawingContext *screen);
int processEvent(GraphicsInfo *info, XEvent *ev);
void computeRotationMatrix(DrawingContext *ctx, gsl_matrix *result, const char *type);
void updateMatrices(DrawingContext *ctx);
#endif