MATRIX(3)
okay so bestie, welcome to MATRIX(3) โ the Library Functions Manual page for Geometric transformations, and itโs giving math-girl main character energy ๐ โจ. every single detail is staying, no cap.
๐ธ NAME ๐ธ
ident,matmul,matmulr,determinant,adjoint,invertmat,xformpoint,xformpointd,xformplane,pushmat,popmat,rot,qrot,scale,move,xform,ixform,persp,look,viewportโ Geometric transformations ๐ฆ
โจ SYNOPSIS โจ
first, the includes, bestie:
#include <draw.h>
#include <geometry.h>
then the whole function lineup, exactly as written:
void ident(Matrix m)
void matmul(Matrix a, Matrix b)
void matmulr(Matrix a, Matrix b)
double determinant(Matrix m)
void adjoint(Matrix m, Matrix madj)
double invertmat(Matrix m, Matrix inv)
Point3 xformpoint(Point3 p, Space *to, Space *from)
Point3 xformpointd(Point3 p, Space *to, Space *from)
Point3 xformplane(Point3 p, Space *to, Space *from)
Space *pushmat(Space *t)
Space *popmat(Space *t)
void rot(Space *t, double theta, int axis)
void qrot(Space *t, Quaternion q)
void scale(Space *t, double x, double y, double z)
void move(Space *t, double x, double y, double z)
void xform(Space *t, Matrix m)
void ixform(Space *t, Matrix m, Matrix inv)
int persp(Space *t, double fov, double n, double f)
void look(Space *t, Point3 eye, Point3 look, Point3 up)
void viewport(Space *t, Rectangle r, double aspect)
๐ DESCRIPTION ๐
okay so these routines manipulate 3-space affine and projective transformations, represented as 4ร4 matrices, like this:
typedef double Matrix[4][4];
the matrix girlies first:
identโ stores an identity matrix in its argument. โจmatmulโ storesaรbina.matmulrโ storesbรainb.determinantโ returns the determinant of matrixm.adjointโ stores the adjoint (matrix of cofactors) ofminmadj.invertmatโ stores the inverse of matrixminminv, returningmโs determinant. shouldmbe singular (determinant zero),invertmatstores its adjoint inminv. ๐ซถ
the rest of the routines described here manipulate Spaces and transform Point3s. a Point3 is a point in three-space, represented by its homogeneous coordinates:
typedef struct Point3 Point3;
struct Point3{
double x, y, z, w;
};
the homogeneous coordinates (x, y, z, w) represent the Euclidean point (x/w, y/w, z/w) if wโ 0, and a โpoint at infinityโ if w=0.
a Space is just a data structure describing a coordinate system:
typedef struct Space Space;
struct Space{
Matrix t;
Matrix tinv;
Space *next;
};
it contains a pair of transformation matrices and a pointer to the Spaceโs parent. the matrices transform points to and from the โroot coordinate system,โ which is represented by a null Space pointer.
pushmat creates a new Space. its argument is a pointer to the parent space. its result is a newly allocated copy of the parent, but with its next pointer pointing at the parent. popmat discards the Space that is its argument, returning a pointer to the stack. nominally, these two functions define a stack of transformations, but pushmat can be called multiple times on the same Space multiple times, creating a transformation tree. ๐ฑ
xformpoint and xformpointd both transform points from the Space pointed to by from to the space pointed to by to. either pointer may be null, indicating the root coordinate system. the difference between the two functions is that xformpointd divides x, y, z, and w by w, if wโ 0, making (x, y, z) the Euclidean coordinates of the point. ๐ซ
xformplane transforms planes or normal vectors. a plane is specified by the coefficients (a, b, c, d) of its implicit equation ax+by+cz+d=0. since this representation is dual to the homogeneous representation of points, libgeometry represents planes by Point3 structures, with (a, b, c, d) stored in (x, y, z, w). ๐ฆ
the remaining functions transform the coordinate system represented by a Space. their Space * argument must be non-null โ you canโt modify the root Space. rot rotates by angle theta (in radians) about the given axis, which must be one of XAXIS, YAXIS or ZAXIS. qrot transforms by a rotation about an arbitrary axis, specified by Quaternion q. ๐ฅ
scale scales the coordinate system by the given scale factors in the directions of the three axes. move translates by the given displacement in the three axial directions.
xform transforms the coordinate system by the given Matrix. if the matrixโs inverse is known a priori, calling ixform will save the work of recomputing it. ๐
persp does a perspective transformation. the transformation maps the frustum with apex at the origin, central axis down the positive y axis, and apex angle fov and clipping planes y=n and y=f into the double-unit cube. the plane y=n maps to y'=-1, y=f maps to y'=1.
look does a view-pointing transformation. the eye point is moved to the origin. the line through the eye and look points is aligned with the y axis, and the plane containing the eye, look and up points is rotated into the x-y plane. โจ
viewport maps the unit-cube window into the given screen viewport. the viewport rectangle r has r.min at the top left-hand corner, and r.max just outside the lower right-hand corner. argument aspect is the aspect ratio (dx/dy) of the viewportโs pixels (not of the whole viewport). the whole window is transformed to fit centered inside the viewport with equal slop on either top and bottom or left and right, depending on the viewportโs aspect ratio. the window is viewed down the y axis, with x to the left and z up. the viewport has x increasing to the right and y increasing down. the windowโs y coordinates are mapped, unchanged, into the viewportโs z coordinates. ๐
๐ SOURCE ๐
/src/libgeometry/matrix.c โ thatโs the source file, bestie. slay.
๐ SEE ALSO ๐
arith3(3)โ go read this one next, iykyk ๐
๐ xoxo, your Unix bestie โ source/version: /src/libgeometry/matrix.c; footer tag: MATRIX(3); date: not in the original, bestie. periodt. ๐ซถ
๐ฆ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 ยท LPL-1.02
- arch rolling: plan9port 20261021-2 ยท custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms