From 0373255087377122eeb10e006ffb8aa1b57e611c Mon Sep 17 00:00:00 2001 From: rgl Date: Mon, 3 Feb 2020 22:42:28 +0100 Subject: after a year or so of work, i dare create a proper repo. --- libgeometry/rframe.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 libgeometry/rframe.c (limited to 'libgeometry/rframe.c') diff --git a/libgeometry/rframe.c b/libgeometry/rframe.c new file mode 100644 index 0000000..06d63f2 --- /dev/null +++ b/libgeometry/rframe.c @@ -0,0 +1,51 @@ +#include +#include +#include "../geometry.h" + +Point2 +rframexform(Point2 p, RFrame rf) +{ + Matrix m = { + rf.bx.x, rf.bx.y, -dotvec2(rf.bx, rf.p), + rf.by.x, rf.by.y, -dotvec2(rf.by, rf.p), + 0, 0, 1, + }; + return xform(p, m); +} + +Point3 +rframexform3(Point3 p, RFrame3 rf) +{ + Matrix3 m = { + rf.bx.x, rf.bx.y, rf.bx.z, -dotvec3(rf.bx, rf.p), + rf.by.x, rf.by.y, rf.by.z, -dotvec3(rf.by, rf.p), + rf.bz.x, rf.bz.y, rf.bz.z, -dotvec3(rf.bz, rf.p), + 0, 0, 0, 1, + }; + return xform3(p, m); +} + +Point2 +invrframexform(Point2 p, RFrame rf) +{ + Matrix m = { + rf.bx.x, rf.bx.y, -dotvec2(rf.bx, rf.p), + rf.by.x, rf.by.y, -dotvec2(rf.by, rf.p), + 0, 0, 1, + }; + invm(m); + return xform(p, m); +} + +Point3 +invrframexform3(Point3 p, RFrame3 rf) +{ + Matrix3 m = { + rf.bx.x, rf.bx.y, rf.bx.z, -dotvec3(rf.bx, rf.p), + rf.by.x, rf.by.y, rf.by.z, -dotvec3(rf.by, rf.p), + rf.bz.x, rf.bz.y, rf.bz.z, -dotvec3(rf.bz, rf.p), + 0, 0, 0, 1, + }; + invm3(m); + return xform3(p, m); +} -- cgit v1.2.3