Example #1
0
/* Calculate the inverse of a 3x3 matrix
   http://en.wikipedia.org/wiki/Invertible_matrix */
void x3f_3x3_inverse(double *a, double *ainv)
{
  double A, B, C, D, E, F, G, H, I;
  double det;

  A = +(M11(a)*M22(a)-M12(a)*M21(a));
  B = -(M10(a)*M22(a)-M12(a)*M20(a));
  C = +(M10(a)*M21(a)-M11(a)*M20(a));

  D = -(M01(a)*M22(a)-M02(a)*M21(a));
  E = +(M00(a)*M22(a)-M02(a)*M20(a));
  F = -(M00(a)*M21(a)-M01(a)*M20(a));

  G = +(M01(a)*M12(a)-M02(a)*M11(a));
  H = -(M00(a)*M12(a)-M02(a)*M10(a));
  I = +(M00(a)*M11(a)-M01(a)*M10(a));

  det = M00(a)*A + M01(a)*B + M02(a)*C;

  M00(ainv) = A/det; M01(ainv) = D/det; M02(ainv) = G/det;
  M10(ainv) = B/det; M11(ainv) = E/det; M12(ainv) = H/det;
  M20(ainv) = C/det; M21(ainv) = F/det; M22(ainv) = I/det;
}
Example #2
0
/* Multiply a 3x3 matrix with a 3x3 matrix, giving a 3x3 matrix */
void x3f_3x3_3x3_mul(double *a, double *b, double *c)
{
  M00(c) = M00(a)*M00(b) + M01(a)*M10(b) + M02(a)*M20(b);
  M01(c) = M00(a)*M01(b) + M01(a)*M11(b) + M02(a)*M21(b);
  M02(c) = M00(a)*M02(b) + M01(a)*M12(b) + M02(a)*M22(b);

  M10(c) = M10(a)*M00(b) + M11(a)*M10(b) + M12(a)*M20(b);
  M11(c) = M10(a)*M01(b) + M11(a)*M11(b) + M12(a)*M21(b);
  M12(c) = M10(a)*M02(b) + M11(a)*M12(b) + M12(a)*M22(b);

  M20(c) = M20(a)*M00(b) + M21(a)*M10(b) + M22(a)*M20(b);
  M21(c) = M20(a)*M01(b) + M21(a)*M11(b) + M22(a)*M21(b);
  M22(c) = M20(a)*M02(b) + M21(a)*M12(b) + M22(a)*M22(b);
}
Example #3
0
void
DOMMatrixReadOnly::Stringify(nsAString& aResult)
{
  nsAutoString matrixStr;
  if (mMatrix3D) {
    matrixStr.AppendPrintf("matrix3d(%g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g)",
      M11(), M12(), M13(), M14(),
      M21(), M22(), M23(), M24(),
      M31(), M32(), M33(), M34(),
      M41(), M42(), M43(), M44());
  } else {
    matrixStr.AppendPrintf("matrix(%g, %g, %g, %g, %g, %g)", A(), B(), C(), D(), E(), F());
  }

  aResult = matrixStr;
}
Example #4
0
void
DOMMatrixReadOnly::Stringify(nsAString& aResult)
{
  nsAutoString matrixStr;
  if (mMatrix3D) {
    // We can't use AppendPrintf here, because it does locale-specific
    // formatting of floating-point values.
    matrixStr.AssignLiteral("matrix3d(");
    AppendFloat(matrixStr, M11()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, M12()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, M13()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, M14()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, M21()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, M22()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, M23()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, M24()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, M31()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, M32()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, M33()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, M34()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, M41()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, M42()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, M43()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, M44());
    matrixStr.AppendLiteral(")");
  } else {
    // We can't use AppendPrintf here, because it does locale-specific
    // formatting of floating-point values.
    matrixStr.AssignLiteral("matrix(");
    AppendFloat(matrixStr, A()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, B()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, C()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, D()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, E()); matrixStr.AppendLiteral(", ");
    AppendFloat(matrixStr, F());
    matrixStr.AppendLiteral(")");
  }

  aResult = matrixStr;
}
Example #5
0
/* Multiply a scalar with a 3x3 matrix, giving a 3x3 matrix */
void x3f_scalar_3x3_mul(double a, double *b, double *c)
{
  M00(c) = a*M00(b); M01(c) = a*M01(b); M02(c) = a*M02(b);
  M10(c) = a*M10(b); M11(c) = a*M11(b); M12(c) = a*M12(b);
  M20(c) = a*M20(b); M21(c) = a*M21(b); M22(c) = a*M22(b);
}
Example #6
0
void x3f_Bradford_D65_to_D50(double *a)
{
  M00(a) = +1.0478112 ; M01(a) = +0.0228866; M02(a) = -0.0501270;
  M10(a) = +0.0295424 ; M11(a) = +0.9904844; M12(a) = -0.0170491;
  M20(a) = -0.0092345 ; M21(a) = +0.0150436; M22(a) = +0.7521316;
}
Example #7
0
/* http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html */
void x3f_Bradford_D50_to_D65(double *a)
{
  M00(a) = +0.9555766 ; M01(a) = -0.0230393; M02(a) = +0.0631636;
  M10(a) = -0.0282895 ; M11(a) = +1.0099416; M12(a) = +0.0210077;
  M20(a) = +0.0122982 ; M21(a) = -0.0204830; M22(a) = +1.3299098;
}
Example #8
0
/* http://en.wikipedia.org/wiki/CIE_1931_color_space */
void x3f_CIERGB_to_XYZ(double *a)
{
  M00(a) = 0.49    ; M01(a) = 0.31    ; M02(a) = 0.20    ;
  M10(a) = 0.17697 ; M11(a) = 0.81240 ; M12(a) = 0.01063 ;
  M20(a) = 0.00    ; M21(a) = 0.01    ; M22(a) = 0.99    ;
}
Example #9
0
void x3f_3x3_identity(double *a)
{
  M00(a) = 1.0; M01(a) = 0.0; M02(a) = 0.0;
  M10(a) = 0.0; M11(a) = 1.0; M12(a) = 0.0;
  M20(a) = 0.0; M21(a) = 0.0; M22(a) = 1.0;
}
Example #10
0
void x3f_AdobeRGB_to_XYZ(double *a)
{
  M00(a) = 0.57667; M01(a) = 0.18556; M02(a) = 0.18823;
  M10(a) = 0.29737; M11(a) = 0.62736; M12(a) = 0.07529;
  M20(a) = 0.02703; M21(a) = 0.07069; M22(a) = 0.99134;
}
Example #11
0
/* http://www.adobe.com/digitalimag/pdfs/AdobeRGB1998.pdf */
void x3f_XYZ_to_AdobeRGB(double *a)
{
  M00(a) = +2.04159; M01(a) = -0.56501; M02(a) = -0.34473;
  M10(a) = -0.96924; M11(a) = +1.87597; M12(a) = +0.04156;
  M20(a) = +0.01344; M21(a) = -0.11836; M22(a) = +1.01517;
}
Example #12
0
void x3f_ProPhotoRGB_to_XYZ(double *a)
{
  M00(a) = 0.7977; M01(a) = 0.1352; M02(a) = 0.0313;
  M10(a) = 0.2880; M11(a) = 0.7119; M12(a) = 0.0001;
  M20(a) = 0.0000; M21(a) = 0.0000; M22(a) = 0.8249;
}
Example #13
0
/* http://en.wikipedia.org/wiki/ProPhoto_RGB_color_space */
void x3f_XYZ_to_ProPhotoRGB(double *a)
{
  M00(a) = +1.3460; M01(a) = -0.2556; M02(a) = -0.0511;
  M10(a) = -0.5446; M11(a) = +1.5082; M12(a) = +0.0205;
  M20(a) = +0.0000; M21(a) = +0.0000; M22(a) = +1.2123;
}
Example #14
0
/* Print a 3x3 matrix */
void x3f_3x3_print(x3f_verbosity_t level, double *a)
{
  x3f_printf(level, "%10g %10g %10g\n", M00(a), M01(a), M02(a));
  x3f_printf(level, "%10g %10g %10g\n", M10(a), M11(a), M12(a));
  x3f_printf(level, "%10g %10g %10g\n", M20(a), M21(a), M22(a));
}
Example #15
0
void x3f_3x3_ones(double *a)
{
  M00(a) = 1.0; M01(a) = 1.0; M02(a) = 1.0;
  M10(a) = 1.0; M11(a) = 1.0; M12(a) = 1.0;
  M20(a) = 1.0; M21(a) = 1.0; M22(a) = 1.0;
}
Example #16
0
/* http://en.wikipedia.org/wiki/SRGB */
void x3f_XYZ_to_sRGB(double *a)
{
  M00(a) = +3.2406; M01(a) = -1.5372; M02(a) = -0.4986;
  M10(a) = -0.9689; M11(a) = +1.8758; M12(a) = +0.0415;
  M20(a) = +0.0557; M21(a) = -0.2040; M22(a) = +1.0570;
}
Example #17
0
void x3f_sRGB_to_XYZ(double *a)
{
  M00(a) = 0.4124; M01(a) = 0.3576; M02(a) = 0.1805;
  M10(a) = 0.2126; M11(a) = 0.7152; M12(a) = 0.0722;
  M20(a) = 0.0193; M21(a) = 0.1192; M22(a) = 0.9505;
}
Example #18
0
void
GradDpElement :: computeStiffnessMatrix_ku(FloatMatrix &answer, MatResponseMode rMode, TimeStep *tStep)
{
    double dV;
    NLStructuralElement *elem = this->giveNLStructuralElement();
    FloatArray Nk;
    FloatMatrix B, DkuB, Dku;
    StructuralCrossSection *cs = elem->giveStructuralCrossSection();

    answer.clear();

    int nlGeo = elem->giveGeometryMode();

    for ( auto &gp: *elem->giveIntegrationRule(0) ) {

        GradDpMaterialExtensionInterface *dpmat = dynamic_cast< GradDpMaterialExtensionInterface * >(
            cs->giveMaterialInterface(GradDpMaterialExtensionInterfaceType, gp) );
        if ( !dpmat ) {
            OOFEM_ERROR("Material doesn't implement the required DpGrad interface!");
        }

        elem->computeBmatrixAt(gp, B);
        if ( nlGeo == 1 ) {
            if ( elem->domain->giveEngngModel()->giveFormulation() == AL ) {
                elem->computeBmatrixAt(gp, B);
            } else {
                elem->computeBHmatrixAt(gp, B);
            }
        }

        dpmat->givePDGradMatrix_ku(Dku, rMode, gp, tStep);
        this->computeNkappaMatrixAt(gp, Nk);
        dV = elem->computeVolumeAround(gp);
        DkuB.beProductOf(Dku, B);
        answer.plusProductUnsym(Nk, DkuB, -dV);

        if ( dpmat->giveAveragingType() == 2 ) {
            double dl1, dl2, dl3;
            FloatArray Gk;
            FloatMatrix D, DB, LDB;
            FloatMatrix Bk, BktM22, BktM22Gk, BktM12, BktM12Gk, M22(2, 2), M12(2, 2);
            FloatMatrix dL1(1, 3), dL2(1, 3), result1, result2, dLdS, n(2, 2);

            this->computeBkappaMatrixAt(gp, Bk);
            dpmat->givePDGradMatrix_uu(D, rMode, gp, tStep);
            dpmat->givePDGradMatrix_LD(dLdS, rMode, gp, tStep);
            this->computeNonlocalGradient(Gk, gp, tStep);

            dl1 = dLdS.at(3, 3);
            dl2 = dLdS.at(4, 4);
            dl3 = dLdS.at(5, 5);

            n.at(1, 1) = dLdS.at(1, 1);
            n.at(1, 2) = dLdS.at(1, 2);
            n.at(2, 1) = dLdS.at(2, 1);
            n.at(2, 2) = dLdS.at(2, 2);
            // first term Bk^T M22 G L1 D B
            // M22 = n2 \otimes n2
            M22.at(1, 1) = n.at(1, 2) * n.at(1, 2);
            M22.at(1, 2) = n.at(1, 2) * n.at(2, 2);
            M22.at(2, 1) = n.at(2, 2) * n.at(1, 2);
            M22.at(2, 2) = n.at(2, 2) * n.at(2, 2);
            // dL1
            dL1.at(1, 1) = dl1 * n.at(1, 1) * n.at(1, 1) + dl2 *n.at(1, 2) * n.at(1, 2);
            dL1.at(1, 2) = dl1 * n.at(2, 1) * n.at(2, 1) + dl2 *n.at(2, 2) * n.at(2, 2);
            dL1.at(1, 3) = dl1 * n.at(1, 1) * n.at(2, 1) + dl2 *n.at(1, 2) * n.at(2, 2);

            DB.beProductOf(D, B);
            LDB.beProductOf(dL1, DB);
            BktM22.beTProductOf(Bk, M22);
            ///@todo This can't possibly work if this is uncommented (!) / Mikael
            //BktM22Gk.beProductOf(BktM22,Gk);
            result1.beProductOf(BktM22Gk, LDB);
            answer.add(dV, result1);
            // This would be slightly shorter and faster;
            //GkLDB.beProductOf(Gk, LDB);
            //MGkLDB.beProductOf(M22, GkLDB);
            //answer.plusProductUnsym(Bk, MGkLDB, dV);

            // M12 + M21  = n1 \otimes n2 + n2 \otimes n1
            M12.at(1, 1) = n.at(1, 1) * n.at(1, 2) + n.at(1, 2) * n.at(1, 1);
            M12.at(1, 2) = n.at(1, 1) * n.at(2, 2) + n.at(1, 2) * n.at(2, 1);
            M12.at(2, 1) = n.at(2, 1) * n.at(1, 2) + n.at(2, 2) * n.at(1, 1);
            M12.at(2, 2) = n.at(2, 1) * n.at(2, 2) + n.at(2, 2) * n.at(2, 1);
            //dL2
            dL2.at(1, 1) = dl3 * ( n.at(1, 1) * n.at(1, 2) + n.at(1, 1) * n.at(1, 2) );
            dL2.at(1, 2) = dl3 * ( n.at(2, 1) * n.at(2, 2) + n.at(2, 1) * n.at(2, 2) );
            dL2.at(1, 3) = dl3 * ( n.at(1, 2) * n.at(2, 1) + n.at(1, 1) * n.at(2, 2) );

            LDB.beProductOf(dL2, DB);
            BktM12.beTProductOf(Bk, M12);
            ///@todo This can't possibly work if this is uncommented (!) / Mikael
            //BktM12Gk.beProductOf(BktM12,Gk);
            result2.beProductOf(BktM12Gk, LDB);
            answer.add(dV, result2);
            // This would be slightly shorter and faster;
            //GkLDB.beProductOf(Gk, LDB);
            //MGkLDB.beProductOf(M12, GkLDB);
            //answer.plusProductUnsym(Bk, MGkLDB, dV);
        }
    }
}
Example #19
0
/* Convert a 3x1 matrix to a 3x3 diagonal matrix */
void x3f_3x3_diag(double *a, double *b)
{
  M00(b) = M0(a); M01(b) = 0.0;   M02(b) = 0.0;
  M10(b) = 0.0;   M11(b) = M1(a); M12(b) = 0.0;
  M20(b) = 0.0;   M21(b) = 0.0;   M22(b) = M2(a);
}