aboutsummaryrefslogtreecommitdiff
path: root/rframe.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-06-20 09:59:06 +0000
committerrodri <rgl@antares-labs.eu>2023-06-20 09:59:06 +0000
commit21c51914da3ce9eec7d39e26c445ca9de770dbae (patch)
treeca5a213e63466096d7c4cb9e72c52da56eda288b /rframe.c
parent302a41f84da0884d1ac07d653868c7d0e7604362 (diff)
downloadlibgeometry-master.tar.gz
libgeometry-master.tar.bz2
libgeometry-master.zip
fixed the rframe xforms.HEADmaster
also brought in the manpage.
Diffstat (limited to 'rframe.c')
-rw-r--r--rframe.c88
1 files changed, 72 insertions, 16 deletions
diff --git a/rframe.c b/rframe.c
index 2f7c682..aee3c03 100644
--- a/rframe.c
+++ b/rframe.c
@@ -2,50 +2,106 @@
#include <libc.h>
#include <geometry.h>
+/*
+ * implicit identity origin rframes
+ *
+ * static RFrame IRF2 = {
+ * .p = {0,0,1},
+ * .bx = {1,0,0},
+ * .by = {0,1,0},
+ * };
+ *
+ * static RFrame3 IRF3 = {
+ * .p = {0,0,0,1},
+ * .bx = {1,0,0,0},
+ * .by = {0,1,0,0},
+ * .bz = {0,0,1,0},
+ * };
+ *
+ * these rframes are used on every xform to keep the points in the
+ * correct plane (i.e. with proper w values); they are written here as a
+ * reference for future changes. the bases are ignored since they turn
+ * into an unnecessary identity xform.
+ *
+ * the implicitness comes from the fact that using the _irf* filters
+ * makes the rframexform equivalent to:
+ * rframexform(invrframexform(p, IRF), rf);
+ * and the invrframexform to:
+ * rframexform(invrframexform(p, rf), IRF);
+ */
+
+static Point2
+_irfxform(Point2 p)
+{
+ p.w--;
+ return p;
+}
+
+static Point2
+_irfxform⁻¹(Point2 p)
+{
+ p.w++;
+ return p;
+}
+
+static Point3
+_irfxform3(Point3 p)
+{
+ p.w--;
+ return p;
+}
+
+static Point3
+_irfxform3⁻¹(Point3 p)
+{
+ p.w++;
+ return p;
+}
+
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),
+ rf.bx.x, rf.by.x, 0,
+ rf.bx.y, rf.by.y, 0,
0, 0, 1,
};
- return xform(p, m);
+ invm(m);
+ return xform(subpt2(_irfxform⁻¹(p), rf.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),
+ rf.bx.x, rf.by.x, rf.bz.x, 0,
+ rf.bx.y, rf.by.y, rf.bz.y, 0,
+ rf.bx.z, rf.by.z, rf.bz.z, 0,
0, 0, 0, 1,
};
- return xform3(p, m);
+ invm3(m);
+ return xform3(subpt3(_irfxform3⁻¹(p), rf.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),
+ rf.bx.x, rf.by.x, 0,
+ rf.bx.y, rf.by.y, 0,
0, 0, 1,
};
- invm(m);
- return xform(p, m);
+ return _irfxform(addpt2(xform(p, m), rf.p));
}
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),
+ rf.bx.x, rf.by.x, rf.bz.x, 0,
+ rf.bx.y, rf.by.y, rf.bz.y, 0,
+ rf.bx.z, rf.by.z, rf.bz.z, 0,
0, 0, 0, 1,
};
- invm3(m);
- return xform3(p, m);
+ return _irfxform3(addpt3(xform3(p, m), rf.p));
}