18Matrix ::Matrix(
double v)
 
   20    for (
int i = 0; i < 4; i++)
 
   21        for (
int j = 0; j < 4; j++)
 
   22            x[i][j] = (i == j) ? v : 0.0;
 
   29        for (
double &item : row)
 
   40    for (
int i = 0; i < 4; i++)
 
   45            for (
int j = 0; j < 4; j++)
 
   52        for (
int j = 0; j < 4; j++)
 
   58                    double mulby = x[j][i];
 
   59                    for (
int k = 0; k < 4; k++)
 
   61                        x[j][k] -= mulby * x[i][k];
 
   62                        Out.x[j][k] -= mulby * 
Out.x[i][k];
 
   71void Matrix ::Transpose()
 
   74    for (
int i = 0; i < 4; i++)
 
   75        for (
int j = i; j < 4; j++)
 
   84Matrix &Matrix ::operator+=(
const Matrix &A)
 
   89    for (
int i = 0; i < 4; i++)
 
   90        for (
int j = 0; j < 4; j++)
 
   96Matrix &Matrix ::operator-=(
const Matrix &A)
 
  101    for (
int i = 0; i < 4; i++)
 
  102        for (
int j = 0; j < 4; j++)
 
  103            x[i][j] -= A.x[i][j];
 
  108Matrix &Matrix ::operator*=(
double v)
 
  111        for (
double &item : row)
 
  119Matrix &Matrix ::operator*=(
const Matrix &A)
 
  125    for (
int i = 0; i < 4; i++)
 
  126        for (
int j = 0; j < 4; j++)
 
  129            for (
int k = 0; k < 4; k++)
 
  130                sum += res.x[i][k] * A.x[k][j];
 
  137Matrix operator+(
const Matrix &A, 
const Matrix &B)
 
  140    for (
int i = 0; i < 4; i++)
 
  141        for (
int j = 0; j < 4; j++)
 
  142            res.x[i][j] = A.x[i][j] + B.x[i][j];
 
  147Matrix operator-(
const Matrix &A, 
const Matrix &B)
 
  150    for (
int i = 0; i < 4; i++)
 
  151        for (
int j = 0; j < 4; j++)
 
  152            res.x[i][j] = A.x[i][j] - B.x[i][j];
 
  157Matrix operator*(
const Matrix &A, 
const Matrix &B)
 
  160    for (
int i = 0; i < 4; i++)
 
  161        for (
int j = 0; j < 4; j++)
 
  164            for (
int k = 0; k < 4; k++)
 
  165                sum += A.x[i][k] * B.x[k][j];
 
  173Matrix operator*(
const Matrix &A, 
double v)
 
  176    for (
int i = 0; i < 4; i++)
 
  177        for (
int j = 0; j < 4; j++)
 
  178            res.x[i][j] = A.x[i][j] * v;
 
  183GuiderUtils::Vector operator*(
const GuiderUtils::Vector &v, 
const Matrix &M)
 
  185    GuiderUtils::Vector res;
 
  187    res.x = v.x * M.x[0][0] + v.y * M.x[0][1] + v.z * M.x[0][2] + M.x[0][3];
 
  188    res.y = v.x * M.x[1][0] + v.y * M.x[1][1] + v.z * M.x[1][2] + M.x[1][3];
 
  189    res.z = v.x * M.x[2][0] + v.y * M.x[2][1] + v.z * M.x[2][2] + M.x[2][3];
 
  214Matrix Translate(
const GuiderUtils::Vector &Loc)
 
  228Matrix Scale(
const GuiderUtils::Vector &v)
 
  238Matrix RotateX(
double Angle)
 
  241    double Cosine = cos(Angle);
 
  242    double Sine   = sin(Angle);
 
  244    res.x[1][1] = Cosine;
 
  247    res.x[2][2] = Cosine;
 
  257Matrix RotateY(
double Angle)
 
  260    double Cosine = cos(Angle);
 
  261    double Sine   = sin(Angle);
 
  263    res.x[0][0] = Cosine;
 
  266    res.x[2][2] = Cosine;
 
  271Matrix RotateZ(
double Angle)
 
  274    double Cosine = cos(Angle);
 
  275    double Sine   = sin(Angle);
 
  279    res.x[0][0] = Cosine;
 
  282    res.x[1][1] = Cosine;
 
  287Matrix Rotate(
const GuiderUtils::Vector &axis, 
double angle)
 
  290    double Cosine = cos(angle);
 
  291    double Sine   = sin(angle);
 
  293    res.x[0][0] = axis.x * axis.x + (1 - axis.x * axis.x) * Cosine;
 
  294    res.x[0][1] = axis.x * axis.y * (1 - Cosine) + axis.z * Sine;
 
  295    res.x[0][2] = axis.x * axis.z * (1 - Cosine) - axis.y * Sine;
 
  298    res.x[1][0] = axis.x * axis.y * (1 - Cosine) - axis.z * Sine;
 
  299    res.x[1][1] = axis.y * axis.y + (1 - axis.y * axis.y) * Cosine;
 
  300    res.x[1][2] = axis.y * axis.z * (1 - Cosine) + axis.x * Sine;
 
  303    res.x[2][0] = axis.x * axis.z * (1 - Cosine) + axis.y * Sine;
 
  304    res.x[2][1] = axis.y * axis.z * (1 - Cosine) - axis.x * Sine;
 
  305    res.x[2][2] = axis.z * axis.z + (1 - axis.z * axis.z) * Cosine;
 
  316Matrix Transform(
const GuiderUtils::Vector &v1, 
const GuiderUtils::Vector &v2, 
const GuiderUtils::Vector &v3)