# FreeBSD Manual Pages

MATRIX(3) Library Functions Manual MATRIX(3)NAMEident, matmul, matmulr, determinant, adjoint, invertmat, xformpoint, xformpointd, xformplane, pushmat, popmat, rot, qrot, scale, move, xform, ixform, persp, look, viewport - Geometric transformationsSYNOPSIS#include<draw.h>#include<geometry.h>voidident(Matrixm)voidmatmul(Matrixa,Matrixb)voidmatmulr(Matrixa,Matrixb)doubledeterminant(Matrixm)voidadjoint(Matrixm,Matrixmadj)doubleinvertmat(Matrixm,Matrixinv)Point3xformpoint(Point3p,Space*to,Space*from)Point3xformpointd(Point3p,Space*to,Space*from)Point3xformplane(Point3p,Space*to,Space*from)Space*pushmat(Space*t)Space*popmat(Space*t)voidrot(Space*t,doubletheta,intaxis)voidqrot(Space*t,Quaternionq)voidscale(Space*t,doublex,doubley,doublez)voidmove(Space*t,doublex,doubley,doublez)voidxform(Space*t,Matrixm)voidixform(Space*t,Matrixm,Matrixinv)intpersp(Space*t,doublefov,doublen,doublef)voidlook(Space*t,Point3eye,Point3look,Point3up)voidviewport(Space*t,Rectangler,doubleaspect)DESCRIPTIONThese routines manipulate 3-space affine and projective transforma- tions, represented as 4x4 matrices, thus: typedef double Matrix[4][4];Identstores an identity matrix in its argument.Matmulstoresaxbina.Matmulrstoresbxainb.Determinantreturns the determinant of matrixm.Adjointstores the adjoint (matrix of cofactors) ofminmadj.Invertmatstores the inverse of matrixminminv, returningm's determinant. Shouldmbe singular (determinant zero),invertmatstores its adjoint inminv. The rest of the routines described here manipulateSpacesand transformPoint3s. APoint3is a point in three-space, represented by its homo- geneous 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) ifwa0, and a ``point at infinity'' ifw=0. ASpaceis 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 theSpace's parent. The matrices transform points to and from the ``root coordinate system,'' which is represented by a nullSpacepointer.Pushmatcreates a newSpace. Its argument is a pointer to the parent space. Its result is a newly allocated copy of the parent, but with itsnextpointer pointing at the parent.Popmatdiscards theSpacethat is its argument, returning a pointer to the stack. Nominally, these two functions define a stack of transformations, butpushmatcan be called multiple times on the sameSpacemultiple times, creating a transformation tree.XformpointandXformpointdboth transform points from theSpacepointed to byfromto the space pointed to byto. Either pointer may be null, indicating the root coordinate system. The difference between the two functions is thatxformpointddividesx,y,z, andwbyw, ifwa0, making (x,y,z) the Euclidean coordinates of the point.Xformplanetransforms planes or normal vectors. A plane is specified by the coefficients (a,b,c,d) of its implicit equationax+by+cz+d=0. Since this representation is dual to the homogeneous representation of points,libgeometryrepresents planes byPoint3structures, with (a,b,c,d) stored in (x,y,z,w). The remaining functions transform the coordinate system represented by aSpace. TheirSpace*argument must be non-null -- you can't modify the rootSpace.Rotrotates by angletheta(in radians) about the givenaxis, which must be one ofXAXIS,YAXISorZAXIS.Qrottrans- forms by a rotation about an arbitrary axis, specified byQuaternionq.Scalescales the coordinate system by the given scale factors in the directions of the three axes.Movetranslates by the given displace- ment in the three axial directions.Xformtransforms the coordinate system by the givenMatrix. If the ma- trix's inverse is knownapriori, callingixformwill save the work of recomputing it.Perspdoes a perspective transformation. The transformation maps the frustum with apex at the origin, central axis down the positiveyaxis, and apex anglefovand clipping planesy=nandy=finto the double-unit cube. The planey=nmaps toy'=-1,y=fmaps toy'=1.Lookdoes a view-pointing transformation. Theeyepoint is moved to the origin. The line through theeyeandlookpoints is aligned with the y axis, and the plane containing theeye,lookanduppoints is ro- tated into thex-yplane.Viewportmaps the unit-cube window into the given screen viewport. The viewport rectanglerhasr.minat the top left-hand corner, andr.maxjust outside the lower right-hand corner. Argumentaspectis the as- pect ratio (dx/dy) of the viewport's pixels (not of the whole view- port). 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 theyaxis, withxto the left andzup. The viewport hasxincreasing to the right andyincreasing down. The window'sycoordinates are mapped, unchanged, into the viewport'szcoordinates.SOURCE/src/libgeometry/matrix.cSEE ALSOMATRIX(3)

NAME | SYNOPSIS | DESCRIPTION | SOURCE | SEE ALSO

Want to link to this manual page? Use this URL:

<https://man.freebsd.org/cgi/man.cgi?query=matrix&sektion=3&manpath=FreeBSD+13.0-RELEASE+and+Ports>