summaryrefslogtreecommitdiff
path: root/libgeometry/rframe.c
blob: 06d63f255b44fb743c5a6f1a4b3d2bc9658df0e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <u.h>
#include <libc.h>
#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);
}