Using comments within the code itself, can you provide an line by line explanation of the below JavaScript file? The file itself deals with WebGl and if that helps you. Please & thank you JavaScript File:   function inverse2(m) {      var a = mat2();      var d = det2(m);      a[0][0] = m[1][1]/d;      a[0][1] = -m[0][1]/d;      a[1][0] = -m[1][0]/d;      a[1][1] = m[0][0]/d;      return a; }   function inverse3(m) {     var a = mat3();     var d = det3(m);       var a00 = [        vec2(m[1][1], m[1][2]),        vec2(m[2][1], m[2][2])     ];     var a01 = [        vec2(m[1][0], m[1][2]),        vec2(m[2][0], m[2][2])     ];     var a02 = [        vec2(m[1][0], m[1][1]),        vec2(m[2][0], m[2][1])     ];     var a10 = [        vec2(m[0][1], m[0][2]),        vec2(m[2][1], m[2][2])     ];     var a11 = [        vec2(m[0][0], m[0][2]),        vec2(m[2][0], m[2][2])     ];     var a12 = [        vec2(m[0][0], m[0][1]),        vec2(m[2][0], m[2][1])     ];     var a20 = [        vec2(m[0][1], m[0][2]),        vec2(m[1][1], m[1][2])     ];     var a21 = [        vec2(m[0][0], m[0][2]),        vec2(m[1][0], m[1][2])     ];     var a22 = [        vec2(m[0][0], m[0][1]),        vec2(m[1][0], m[1][1])     ];      a[0][0] = det2(a00)/d;    a[0][1] = -det2(a10)/d;    a[0][2] = det2(a20)/d;    a[1][0] = -det2(a01)/d;    a[1][1] = det2(a11)/d;    a[1][2] = -det2(a21)/d;    a[2][0] = det2(a02)/d;    a[2][1] = -det2(a12)/d;    a[2][2] = det2(a22)/d;      return a;   }   function inverse4(m) {     var a = mat4();     var d = det4(m);       var a00 = [        vec3(m[1][1], m[1][2], m[1][3]),        vec3(m[2][1], m[2][2], m[2][3]),        vec3(m[3][1], m[3][2], m[3][3])     ];     var a01 = [        vec3(m[1][0], m[1][2], m[1][3]),        vec3(m[2][0], m[2][2], m[2][3]),        vec3(m[3][0], m[3][2], m[3][3])     ];     var a02 = [        vec3(m[1][0], m[1][1], m[1][3]),        vec3(m[2][0], m[2][1], m[2][3]),        vec3(m[3][0], m[3][1], m[3][3])     ];     var a03 = [        vec3(m[1][0], m[1][1], m[1][2]),        vec3(m[2][0], m[2][1], m[2][2]),        vec3(m[3][0], m[3][1], m[3][2])     ];     var a10 = [        vec3(m[0][1], m[0][2], m[0][3]),        vec3(m[2][1], m[2][2], m[2][3]),        vec3(m[3][1], m[3][2], m[3][3])     ];     var a11 = [        vec3(m[0][0], m[0][2], m[0][3]),        vec3(m[2][0], m[2][2], m[2][3]),        vec3(m[3][0], m[3][2], m[3][3])     ];     var a12 = [        vec3(m[0][0], m[0][1], m[0][3]),        vec3(m[2][0], m[2][1], m[2][3]),        vec3(m[3][0], m[3][1], m[3][3])     ];     var a13 = [        vec3(m[0][0], m[0][1], m[0][2]),        vec3(m[2][0], m[2][1], m[2][2]),        vec3(m[3][0], m[3][1], m[3][2])     ];     var a20 = [        vec3(m[0][1], m[0][2], m[0][3]),        vec3(m[1][1], m[1][2], m[1][3]),        vec3(m[3][1], m[3][2], m[3][3])     ];     var a21 = [        vec3(m[0][0], m[0][2], m[0][3]),        vec3(m[1][0], m[1][2], m[1][3]),        vec3(m[3][0], m[3][2], m[3][3])     ];     var a22 = [        vec3(m[0][0], m[0][1], m[0][3]),        vec3(m[1][0], m[1][1], m[1][3]),        vec3(m[3][0], m[3][1], m[3][3])     ];     var a23 = [        vec3(m[0][0], m[0][1], m[0][2]),        vec3(m[1][0], m[1][1], m[1][2]),        vec3(m[3][0], m[3][1], m[3][2])     ];       var a30 = [        vec3(m[0][1], m[0][2], m[0][3]),        vec3(m[1][1], m[1][2], m[1][3]),        vec3(m[2][1], m[2][2], m[2][3])     ];     var a31 = [        vec3(m[0][0], m[0][2], m[0][3]),        vec3(m[1][0], m[1][2], m[1][3]),        vec3(m[2][0], m[2][2], m[2][3])     ];     var a32 = [        vec3(m[0][0], m[0][1], m[0][3]),        vec3(m[1][0], m[1][1], m[1][3]),        vec3(m[2][0], m[2][1], m[2][3])     ];     var a33 = [        vec3(m[0][0], m[0][1], m[0][2]),        vec3(m[1][0], m[1][1], m[1][2]),        vec3(m[2][0], m[2][1], m[2][2])     ];    a[0][0] = det3(a00)/d;    a[0][1] = -det3(a10)/d;    a[0][2] = det3(a20)/d;    a[0][3] = -det3(a30)/d;    a[1][0] = -det3(a01)/d;    a[1][1] = det3(a11)/d;    a[1][2] = -det3(a21)/d;    a[1][3] = det3(a31)/d;    a[2][0] = det3(a02)/d;    a[2][1] = -det3(a12)/d;    a[2][2] = det3(a22)/d;    a[2][3] = -det3(a32)/d;    a[3][0] = -det3(a03)/d;    a[3][1] = det3(a13)/d;    a[3][2] = -det3(a23)/d;    a[3][3] = det3(a33)/d;      return a; } function inverse(m) {    if(!isMatrix(m)) throw("inverse: m not a matrix");    if(m.length == 2) return inverse2(m);    if(m.length == 3) return inverse3(m);    if(m.length == 4) return inverse4(m); }   //---------------------------------------------------------   // normal matrix function normalMatrix(m, flag) {     if(m.type!='mat4') throw "normalMatrix: input not a mat4";     var a = inverse(transpose(m));     if(arguments.length == 1 &&flag == false) return a;       var b = mat3();     for(var i=0;i<3;i++) for(var j=0; j<3; j++) b[i][j] = a[i][j];       return b; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%
Using comments within the code itself, can you provide an line by line explanation of the below JavaScript file? The file itself deals with WebGl and if that helps you.
Please & thank you
JavaScript File:
 
function inverse2(m)
{
     var a = mat2();
     var d = det2(m);
     a[0][0] = m[1][1]/d;
     a[0][1] = -m[0][1]/d;
     a[1][0] = -m[1][0]/d;
     a[1][1] = m[0][0]/d;
     return a;
}

 

function inverse3(m)
{
    var a = mat3();
    var d = det3(m);

 

    var a00 = [
       vec2(m[1][1], m[1][2]),
       vec2(m[2][1], m[2][2])
    ];
    var a01 = [
       vec2(m[1][0], m[1][2]),
       vec2(m[2][0], m[2][2])
    ];
    var a02 = [
       vec2(m[1][0], m[1][1]),
       vec2(m[2][0], m[2][1])
    ];
    var a10 = [
       vec2(m[0][1], m[0][2]),
       vec2(m[2][1], m[2][2])
    ];
    var a11 = [
       vec2(m[0][0], m[0][2]),
       vec2(m[2][0], m[2][2])
    ];
    var a12 = [
       vec2(m[0][0], m[0][1]),
       vec2(m[2][0], m[2][1])
    ];
    var a20 = [
       vec2(m[0][1], m[0][2]),
       vec2(m[1][1], m[1][2])
    ];
    var a21 = [
       vec2(m[0][0], m[0][2]),
       vec2(m[1][0], m[1][2])
    ];
    var a22 = [
       vec2(m[0][0], m[0][1]),
       vec2(m[1][0], m[1][1])
    ];

 

   a[0][0] = det2(a00)/d;
   a[0][1] = -det2(a10)/d;
   a[0][2] = det2(a20)/d;
   a[1][0] = -det2(a01)/d;
   a[1][1] = det2(a11)/d;
   a[1][2] = -det2(a21)/d;
   a[2][0] = det2(a02)/d;
   a[2][1] = -det2(a12)/d;
   a[2][2] = det2(a22)/d;

 

   return a;

 

}

 

function inverse4(m)
{
    var a = mat4();
    var d = det4(m);

 

    var a00 = [
       vec3(m[1][1], m[1][2], m[1][3]),
       vec3(m[2][1], m[2][2], m[2][3]),
       vec3(m[3][1], m[3][2], m[3][3])
    ];
    var a01 = [
       vec3(m[1][0], m[1][2], m[1][3]),
       vec3(m[2][0], m[2][2], m[2][3]),
       vec3(m[3][0], m[3][2], m[3][3])
    ];
    var a02 = [
       vec3(m[1][0], m[1][1], m[1][3]),
       vec3(m[2][0], m[2][1], m[2][3]),
       vec3(m[3][0], m[3][1], m[3][3])
    ];
    var a03 = [
       vec3(m[1][0], m[1][1], m[1][2]),
       vec3(m[2][0], m[2][1], m[2][2]),
       vec3(m[3][0], m[3][1], m[3][2])
    ];
    var a10 = [
       vec3(m[0][1], m[0][2], m[0][3]),
       vec3(m[2][1], m[2][2], m[2][3]),
       vec3(m[3][1], m[3][2], m[3][3])
    ];
    var a11 = [
       vec3(m[0][0], m[0][2], m[0][3]),
       vec3(m[2][0], m[2][2], m[2][3]),
       vec3(m[3][0], m[3][2], m[3][3])
    ];
    var a12 = [
       vec3(m[0][0], m[0][1], m[0][3]),
       vec3(m[2][0], m[2][1], m[2][3]),
       vec3(m[3][0], m[3][1], m[3][3])
    ];
    var a13 = [
       vec3(m[0][0], m[0][1], m[0][2]),
       vec3(m[2][0], m[2][1], m[2][2]),
       vec3(m[3][0], m[3][1], m[3][2])
    ];
    var a20 = [
       vec3(m[0][1], m[0][2], m[0][3]),
       vec3(m[1][1], m[1][2], m[1][3]),
       vec3(m[3][1], m[3][2], m[3][3])
    ];
    var a21 = [
       vec3(m[0][0], m[0][2], m[0][3]),
       vec3(m[1][0], m[1][2], m[1][3]),
       vec3(m[3][0], m[3][2], m[3][3])
    ];
    var a22 = [
       vec3(m[0][0], m[0][1], m[0][3]),
       vec3(m[1][0], m[1][1], m[1][3]),
       vec3(m[3][0], m[3][1], m[3][3])
    ];
    var a23 = [
       vec3(m[0][0], m[0][1], m[0][2]),
       vec3(m[1][0], m[1][1], m[1][2]),
       vec3(m[3][0], m[3][1], m[3][2])
    ];

 

    var a30 = [
       vec3(m[0][1], m[0][2], m[0][3]),
       vec3(m[1][1], m[1][2], m[1][3]),
       vec3(m[2][1], m[2][2], m[2][3])
    ];
    var a31 = [
       vec3(m[0][0], m[0][2], m[0][3]),
       vec3(m[1][0], m[1][2], m[1][3]),
       vec3(m[2][0], m[2][2], m[2][3])
    ];
    var a32 = [
       vec3(m[0][0], m[0][1], m[0][3]),
       vec3(m[1][0], m[1][1], m[1][3]),
       vec3(m[2][0], m[2][1], m[2][3])
    ];
    var a33 = [
       vec3(m[0][0], m[0][1], m[0][2]),
       vec3(m[1][0], m[1][1], m[1][2]),
       vec3(m[2][0], m[2][1], m[2][2])
    ];




   a[0][0] = det3(a00)/d;
   a[0][1] = -det3(a10)/d;
   a[0][2] = det3(a20)/d;
   a[0][3] = -det3(a30)/d;
   a[1][0] = -det3(a01)/d;
   a[1][1] = det3(a11)/d;
   a[1][2] = -det3(a21)/d;
   a[1][3] = det3(a31)/d;
   a[2][0] = det3(a02)/d;
   a[2][1] = -det3(a12)/d;
   a[2][2] = det3(a22)/d;
   a[2][3] = -det3(a32)/d;
   a[3][0] = -det3(a03)/d;
   a[3][1] = det3(a13)/d;
   a[3][2] = -det3(a23)/d;
   a[3][3] = det3(a33)/d;

 

   return a;
}
function inverse(m)
{
   if(!isMatrix(m)) throw("inverse: m not a matrix");
   if(m.length == 2) return inverse2(m);
   if(m.length == 3) return inverse3(m);
   if(m.length == 4) return inverse4(m);
}

 

//---------------------------------------------------------

 

// normal matrix



function normalMatrix(m, flag)
{
    if(m.type!='mat4') throw "normalMatrix: input not a mat4";
    var a = inverse(transpose(m));
    if(arguments.length == 1 &&flag == false) return a;

 

    var b = mat3();
    for(var i=0;i<3;i++) for(var j=0; j<3; j++) b[i][j] = a[i][j];

 

    return b;
}
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Adjacency Matrix
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education