Dart Documentationbox2dMathBox

MathBox class

class MathBox {
 static const double TWO_PI = math.PI * 2.0;

 MathBox();

 /**
  * Given a value within the range specified by [fromMin] and [fromMax],
  * returns a value with the same relative position in the range specified
  * from [toMin] and [toMax]. For example, given a [val] of 2 in the
  * "from range" of 0-4, and a "to range" of 10-20, would return 15.
  */
 static num translateAndScale(num val, num fromMin, num fromMax, num toMin,
     num toMax) {
   final num mult = (val - fromMin) / (fromMax - fromMin);
   final num res = toMin + mult * (toMax - toMin);
   return res;
 }

 /** Solve [matrix]x = [b] without calculating the inverse of [matrix].
  *  [matrix] must be a 3x3 matrix and [b] must be a vec3. */
 static vec3 solve33(mat3 matrix, vec3 b) {
   vec3 out = cross(matrix.col1, matrix.col2);
   num det = dot(matrix.col0, out);
   if (det != 0.0) det = 1.0 / det;

   out = cross(matrix.col1, matrix.col2);
   num x = det * dot(b, out);
   out = cross(b, matrix.col2);
   num y = det * dot(matrix.col0, out);
   out = cross(matrix.col1, b);
   num z = det * dot(matrix.col0, out);
   out.setComponents(x, y, z);
   return out;
 }

 /** Solve [matrix]x = [b] without calculating the inverse of [matrix].
  *  [matrix] must be a 2x2 or 3x3 matrix, and in the latter case the top-left
  *  2x2 elements will be used. [b] must be a vec2. */
 static vec2 solve22(dynamic matrix, vec2 b) {
   assert(matrix is mat2 || matrix is mat3);
   num a11 = matrix.col0.x, a12 = matrix.col1.x,
       a21 = matrix.col0.y, a22 = matrix.col1.y;
   num det = a11 * a22 - a12 * a21;
   if (det != 0.0) det = 1.0 / det;
   final vec2 out = new vec2(a22 * b.x - a12 * b.y, a11 * b.y - a21 * b.x);
   out.scale(det);
   return out;
 }
}

Static Properties

const double TWO_PI #

TWO_PI = math.PI * 2.0

Static Methods

num translateAndScale(num val, num fromMin, num fromMax, num toMin, num toMax) #

Given a value within the range specified by fromMin and fromMax, returns a value with the same relative position in the range specified from toMin and toMax. For example, given a val of 2 in the "from range" of 0-4, and a "to range" of 10-20, would return 15.

static num translateAndScale(num val, num fromMin, num fromMax, num toMin,
   num toMax) {
 final num mult = (val - fromMin) / (fromMax - fromMin);
 final num res = toMin + mult * (toMax - toMin);
 return res;
}

vec3 solve33(mat3 matrix, vec3 b) #

Solve matrixx = b without calculating the inverse of matrix. matrix must be a 3x3 matrix and b must be a vec3.

static vec3 solve33(mat3 matrix, vec3 b) {
 vec3 out = cross(matrix.col1, matrix.col2);
 num det = dot(matrix.col0, out);
 if (det != 0.0) det = 1.0 / det;

 out = cross(matrix.col1, matrix.col2);
 num x = det * dot(b, out);
 out = cross(b, matrix.col2);
 num y = det * dot(matrix.col0, out);
 out = cross(matrix.col1, b);
 num z = det * dot(matrix.col0, out);
 out.setComponents(x, y, z);
 return out;
}

vec2 solve22(matrix, vec2 b) #

Solve matrixx = b without calculating the inverse of matrix. matrix must be a 2x2 or 3x3 matrix, and in the latter case the top-left 2x2 elements will be used. b must be a vec2.

static vec2 solve22(dynamic matrix, vec2 b) {
 assert(matrix is mat2 || matrix is mat3);
 num a11 = matrix.col0.x, a12 = matrix.col1.x,
     a21 = matrix.col0.y, a22 = matrix.col1.y;
 num det = a11 * a22 - a12 * a21;
 if (det != 0.0) det = 1.0 / det;
 final vec2 out = new vec2(a22 * b.x - a12 * b.y, a11 * b.y - a21 * b.x);
 out.scale(det);
 return out;
}

Constructors

new MathBox() #

MathBox();