QML基礎型別之matrix4x4

it_xiangqiang發表於2020-11-29

matrix4x4型別是4行4列矩陣
matrix4x4型別具有16個值,每個值都可以通過QML中的屬性m11至m44(按行/列順序)訪問。 可以使用Qt.matrix4x4()函式來組成此型別的值。 matrix4x4中的每個屬性都儲存為實數(在ARM上為單精度,在x86上為雙精度)。
matrix4x4型別具有以下冪函式,可以在QML中呼叫:

/*
**功能簽名
描述
例***/
matrix4x4 times(matrix4x4 other)
//返回此matrix4x4與另一個matrix4x4相乘的matrix4x4結果。

  var a = Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
  var b = Qt.matrix4x4(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19);
  var c = a.times(b);
  console.log(c.toString());
  // QMatrix4x4(120, 130, 140, 150, 280, 306, 332, 358, 440, 482,
  //524, 566, 600, 658, 716, 774)


vector4d times(vector4d vector)
//返回vector4d的結果,該結果是使用已應用矩陣的pre-vector根據此matrix4x4變換向量的結果
  var a = Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
  var b = Qt.vector4d(5,6,7,8);
  var c = a.times(b);
  console.log(c.toString()); // QVector4D(70, 174, 278, 382)



vector3d times(vector3d vector)
//返回vector3d的結果,該結果是使用已應用矩陣的pre-vector根據此matrix4x4變換向量的結果

  var a = Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
  var b = Qt.vector3d(5,6,7);
  var c = a.times(b);
  console.log(c.toString()); // QVector3D(0.155556, 0.437037, 0.718518)



matrix4x4 times(real factor)
//返回此matrix4x4與標量因子相乘的matrix4x4結果

  var a = Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
  var b = 4.48;
  var c = a.times(b);
  console.log(c.toString());
  // QMatrix4x4(4.48, 8.96, 13.44, 17.92, 22.4, 26.88, 31.36, 35.84,
  // 40.32, 44.8, 49.28, 53.76, 58.24, 62.72, 67.2, 71.68)



matrix4x4 plus(matrix4x4 other)
//返回此matrix4x4與另一個matrix4x4相加後的matrix4x4結果

  var a = Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
  var b = Qt.matrix4x4(5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
  var c = a.plus(b);
  console.log(c.toString());
  // QMatrix4x4(6, 8, 10, 12, 14, 16, 18, 20, 22,
  // 24, 26, 28, 30, 32, 34, 36)



matrix4x4 minus(matrix4x4 other)
//返回從此matrix4x4中減去其他matrix4x4的結果的matrix4x4

  var a = Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
  var b = Qt.matrix4x4(5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
  var c = a.minus(b);
  console.log(c.toString());
  // QMatrix4x4(-4, -4, -4, -4, -4, -4, -4, -4, -4,
  // -4, -4, -4, -4, -4, -4, -4)



vector4d row(int which)
//返回由此指定的vector4d行。 注意:哪個是基於0的矩陣訪問。

  var a = Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
  var b = Qt.vector4d(a.m21, a.m22, a.m23, a.m24);
  var c = a.row(2); // zero based access!  so not equal to b
  console.log(b.toString() + " " + c.toString());
  // QVector4D(5, 6, 7, 8) QVector4D(9, 10, 11, 12)



vector4d column(int which)
//返回由此指定的vector4d列。 注意:哪個是基於0的矩陣訪問。

  var a = Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
  var b = Qt.vector4d(a.m12, a.m22, a.m32, a.m42);
  var c = a.column(2); // zero based access!  so not equal to b
  console.log(b.toString() + " " + c.toString());
  // QVector4D(2, 6, 10, 14) QVector4D(3, 7, 11, 15)



real determinant()
//返回此矩陣的行列式

  var a = Qt.matrix4x4(1,0,0,0,0,2,0,0,0,0,3,0,100,200,300,1);
  var b = a.determinant();
  console.log(b); // 6



matrix4x4 inverted()
//返回此矩陣的逆矩陣(如果存在),否則返回恆等矩陣。

  var a = Qt.matrix4x4(1,0,0,0,0,2,0,0,0,0,3,0,100,200,300,1);
  var b = a.inverted();
  console.log(b.toString());
  // QMatrix4x4(1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.333333, 0, -100,
  // -100, -100, 1)



matrix4x4 transposed()
//返回此矩陣的轉置

  var a = Qt.matrix4x4(1,0,0,0,0,2,0,0,0,0,3,0,100,200,300,1);
  var b = a.transposed();
  console.log(b.toString());
  // QMatrix4x4(1, 0, 0, 100, 0, 2, 0, 200, 0, 0, 3, 300, 0, 0, 0, 1)



bool fuzzyEquals(matrix4x4 other, real epsilon)
/*如果此matrix4x4大約等於另一個matrix4x4,則返回true。 如果此屬性的每個屬性都在另一個屬性的epsilon內,則近似值將為true。 請注意,epsilon是可選引數,預設epsilon為0.00001。*/
  var a = Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
  var b = Qt.matrix4x4(1.0001,2.0001,3.0002,4.0003,5.0001,6.0002,
                       7.0002,8.0004, 9.0001,10.0003,
                       11.0003,12.0004,13.0001,
                       14.0002,15.0003,16.0004);
  var c = a.fuzzyEquals(b);        // default epsilon
  var d = a.fuzzyEquals(b, 0.005); // supplied epsilon
  console.log(c + " " + d); // false true



相關文章