From 182455bcda62eb3bf7e9d98331debe97155829e3 Mon Sep 17 00:00:00 2001 From: johnnwallace <jw0535@princeton.edu> Date: Sun, 2 Jun 2024 22:58:08 -0400 Subject: [PATCH] make traj_eval_trajnsform more efficient and add comment --- src/modules/interface/pptraj.h | 1 + src/modules/src/pptraj.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/modules/interface/pptraj.h b/src/modules/interface/pptraj.h index ed0b8bce8d..0ae10f7629 100644 --- a/src/modules/interface/pptraj.h +++ b/src/modules/interface/pptraj.h @@ -137,6 +137,7 @@ bool is_traj_eval_valid(struct traj_eval const *ev); // evaluate a single polynomial piece struct traj_eval poly4d_eval(struct poly4d const *p, float t); +// rotate and then translate a traj_eval object void traj_eval_transform(struct traj_eval *ev, struct vec shift, float rotation); // ----------------------------------// diff --git a/src/modules/src/pptraj.c b/src/modules/src/pptraj.c index 65d6fac004..0fe297a073 100644 --- a/src/modules/src/pptraj.c +++ b/src/modules/src/pptraj.c @@ -331,10 +331,12 @@ struct traj_eval poly4d_eval(struct poly4d const *p, float t) void traj_eval_transform(struct traj_eval *ev, struct vec shift, float rotation) { + struct mat33 rotator = mrotz(normalize_radians(rotation)); + // rotate position, velocity, acceleration - ev->pos = mvmul(mrotz(normalize_radians(rotation)), ev->pos); - ev->vel = mvmul(mrotz(normalize_radians(rotation)), ev->vel); - ev->acc = mvmul(mrotz(normalize_radians(rotation)), ev->acc); + ev->pos = mvmul(rotator, ev->pos); + ev->vel = mvmul(rotator, ev->vel); + ev->acc = mvmul(rotator, ev->acc); // shift ev->yaw += normalize_radians(rotation);