mirror of
git://git.9front.org/plan9front/plan9front
synced 2025-01-12 11:10:06 +00:00
libgeometry: add matrix minor and cofactor functions
This commit is contained in:
parent
34e7b54c13
commit
e94d21ee3a
3 changed files with 66 additions and 1 deletions
|
@ -84,6 +84,8 @@ void smulm(Matrix, double);
|
|||
void transposem(Matrix);
|
||||
double detm(Matrix);
|
||||
double tracem(Matrix);
|
||||
double minorm(Matrix, int, int);
|
||||
double cofactorm(Matrix, int, int);
|
||||
void adjm(Matrix);
|
||||
void invm(Matrix);
|
||||
Point2 xform(Point2, Matrix);
|
||||
|
@ -97,6 +99,8 @@ void smulm3(Matrix3, double);
|
|||
void transposem3(Matrix3);
|
||||
double detm3(Matrix3);
|
||||
double tracem3(Matrix3);
|
||||
double minorm3(Matrix3, int, int);
|
||||
double cofactorm3(Matrix3, int, int);
|
||||
void adjm3(Matrix3);
|
||||
void invm3(Matrix3);
|
||||
Point3 xform3(Point3, Matrix3);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
.TH GEOMETRY 2
|
||||
.SH NAME
|
||||
Flerp, fclamp, Pt2, Vec2, addpt2, subpt2, mulpt2, divpt2, lerp2, dotvec2, vec2len, normvec2, edgeptcmp, ptinpoly, Pt3, Vec3, addpt3, subpt3, mulpt3, divpt3, lerp3, dotvec3, crossvec3, vec3len, normvec3, identity, addm, subm, mulm, smulm, transposem, detm, tracem, adjm, invm, xform, identity3, addm3, subm3, mulm3, smulm3, transposem3, detm3, tracem3, adjm3, invm3, xform3, Quat, Quatvec, addq, subq, mulq, smulq, sdivq, dotq, invq, qlen, normq, slerp, qrotate, rframexform, rframexform3, invrframexform, invrframexform3, centroid, barycoords, centroid3, vfmt, Vfmt, GEOMfmtinstall \- computational geometry library
|
||||
Flerp, fclamp, Pt2, Vec2, addpt2, subpt2, mulpt2, divpt2, lerp2, dotvec2, vec2len, normvec2, edgeptcmp, ptinpoly, Pt3, Vec3, addpt3, subpt3, mulpt3, divpt3, lerp3, dotvec3, crossvec3, vec3len, normvec3, identity, addm, subm, mulm, smulm, transposem, detm, tracem, minorm, cofactorm, adjm, invm, xform, identity3, addm3, subm3, mulm3, smulm3, transposem3, detm3, tracem3, minorm3, cofactorm3, adjm3, invm3, xform3, Quat, Quatvec, addq, subq, mulq, smulq, sdivq, dotq, invq, qlen, normq, slerp, qrotate, rframexform, rframexform3, invrframexform, invrframexform3, centroid, barycoords, centroid3, vfmt, Vfmt, GEOMfmtinstall \- computational geometry library
|
||||
.SH SYNOPSIS
|
||||
.de PB
|
||||
.PP
|
||||
|
@ -95,6 +95,8 @@ void smulm(Matrix m, double s);
|
|||
void transposem(Matrix m);
|
||||
double detm(Matrix m);
|
||||
double tracem(Matrix m);
|
||||
double minorm(Matrix m, int row, int col);
|
||||
double cofactorm(Matrix m, int row, int col);
|
||||
void adjm(Matrix m);
|
||||
void invm(Matrix m);
|
||||
Point2 xform(Point2 p, Matrix m);
|
||||
|
@ -108,6 +110,8 @@ void smulm3(Matrix3 m, double s);
|
|||
void transposem3(Matrix3 m);
|
||||
double detm3(Matrix3 m);
|
||||
double tracem3(Matrix3 m);
|
||||
double minorm3(Matrix3 m, int row, int col);
|
||||
double cofactorm3(Matrix3 m, int row, int col);
|
||||
void adjm3(Matrix3 m);
|
||||
void invm3(Matrix3 m);
|
||||
Point3 xform3(Point3 p, Matrix3 m);
|
||||
|
@ -386,6 +390,16 @@ Computes the trace of
|
|||
.I m
|
||||
and returns the result.
|
||||
.TP
|
||||
.B minorm(\fIm\fP,\fIrow\fP,\fIcol\fP)
|
||||
Computes the minor of
|
||||
.I m
|
||||
and returns the result.
|
||||
.TP
|
||||
.B cofactorm(\fIm\fP,\fIrow\fP,\fIcol\fP)
|
||||
Computes the cofactor of
|
||||
.I m
|
||||
and returns the result.
|
||||
.TP
|
||||
.B adjm(\fIm\fP)
|
||||
Transforms the matrix
|
||||
.I m
|
||||
|
@ -454,6 +468,16 @@ Computes the trace of
|
|||
.I m
|
||||
and returns the result.
|
||||
.TP
|
||||
.B minorm3(\fIm\fP,\fIrow\fP,\fIcol\fP)
|
||||
Computes the minor of
|
||||
.I m
|
||||
and returns the result.
|
||||
.TP
|
||||
.B cofactorm3(\fIm\fP,\fIrow\fP,\fIcol\fP)
|
||||
Computes the cofactor of
|
||||
.I m
|
||||
and returns the result.
|
||||
.TP
|
||||
.B adjm3(\fIm\fP)
|
||||
Transforms the matrix
|
||||
.I m
|
||||
|
|
|
@ -84,6 +84,24 @@ tracem(Matrix m)
|
|||
return m[0][0] + m[1][1] + m[2][2];
|
||||
}
|
||||
|
||||
double
|
||||
minorm(Matrix m, int row, int col)
|
||||
{
|
||||
int i, j;
|
||||
double subm[2][2];
|
||||
|
||||
for(i = 0; i < 3-1; i++)
|
||||
for(j = 0; j < 3-1; j++)
|
||||
subm[i][j] = m[i < row? i: i+1][j < col? j: j+1];
|
||||
return subm[0][0]*subm[1][1] - subm[0][1]*subm[1][0];
|
||||
}
|
||||
|
||||
double
|
||||
cofactorm(Matrix m, int row, int col)
|
||||
{
|
||||
return minorm(m, row, col)*((row+col)&1 == 0? 1: -1);
|
||||
}
|
||||
|
||||
void
|
||||
adjm(Matrix m)
|
||||
{
|
||||
|
@ -238,6 +256,25 @@ tracem3(Matrix3 m)
|
|||
return m[0][0] + m[1][1] + m[2][2] + m[3][3];
|
||||
}
|
||||
|
||||
double
|
||||
minorm3(Matrix3 m, int row, int col)
|
||||
{
|
||||
int i, j;
|
||||
Matrix subm;
|
||||
|
||||
memset(subm, 0, sizeof subm);
|
||||
for(i = 0; i < 4-1; i++)
|
||||
for(j = 0; j < 4-1; j++)
|
||||
subm[i][j] = m[i < row? i: i+1][j < col? j: j+1];
|
||||
return detm(subm);
|
||||
}
|
||||
|
||||
double
|
||||
cofactorm3(Matrix3 m, int row, int col)
|
||||
{
|
||||
return minorm3(m, row, col)*((row+col)&1 == 0? 1: -1);
|
||||
}
|
||||
|
||||
void
|
||||
adjm3(Matrix3 m)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue