CP Notebook

← all snippets

linearTransformation

75mm Apply the linear transformation (translation, rotation and scaling) which takes line p0-p1 to line q0-q1 to point r. 15mm

5 lines not tested

Needs: "Point.h"

content/geometry/linearTransformation.h — Per Austrin, Ulf Lundstrom

typedef Point<double> P;
P linearTransformation(P p0, P p1, P q0, P q1, P r) {
	P dp = p1-p0, dq = q1-q0, num(dp.cross(dq), dp.dot(dq));
	return q0 + P((r-p0).cross(num), (r-p0).dot(num))/dp.dist2();
}