Advertisement
Guest User

Delta-E_Color Analysis

a guest
Dec 29th, 2017
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. * @version      1.0
  3. * @package      Color Analysis for Colorchecker. color-analysis.jsx
  4. * @copyright    Copyright (C) 2013 José Pereira (www.jpereira.net). All rights reserved.
  5. * @license      GNU/GPL
  6. * color-analysis.jsx is free software. This version may have been modified pursuant
  7. * to the GNU General Public License, and as distributed it includes or
  8. * is derivative of works licensed under the GNU General Public License or
  9. * other free or open source software licenses.
  10. * http://www.gnu.org/copyleft/lgpl.html
  11. */
  12.  
  13. var arrayPatches = new Array(
  14. Array(37.99,   13.56,   14.06),
  15. Array(65.71,   18.13,   17.81),
  16. Array(49.93,   -4.88,   -21.93),
  17. Array(43.14,   -13.10,  21.91),
  18. Array(55.11,   8.84,    -25.40),
  19. Array(70.72,   -33.40,  -0.20),
  20. Array(62.66,   36.07,   57.10),
  21. Array(40.02,   10.41,   -45.96),
  22. Array(51.12,   48.24,   16.25),
  23. Array(30.33,   22.98,   -21.59),
  24. Array(72.53,   -23.71,  57.26),
  25. Array(71.94,   19.36,   67.86),
  26. Array(28.78,   14.18,   -50.30),
  27. Array(55.26,   -38.34,  31.37),
  28. Array(42.10,   53.38,   28.19),
  29. Array(81.73,   4.04,   79.82),
  30. Array(51.94,   49.99,   -14.57),
  31. Array(51.04,   -28.63,  -28.64),
  32. Array(96.54,   -0.43,   1.19),
  33. Array(81.26,   -0.64,   -0.34),
  34. Array(66.77,   -0.73,   -0.50),
  35. Array(50.87,   -0.15,   -0.27),
  36. Array(35.66,   -0.42,   -1.23),
  37. Array(20.46,   -0.08,   -0.97)
  38.                     );
  39.                        
  40.  
  41.  
  42.  
  43. if (documents.length == 0) {
  44.  alert("No hay documentos abiertos!");
  45. }
  46. else {
  47.    
  48.     var docRef = activeDocument;
  49.     var profile = getDocProfile();
  50.      app.preferences.rulerUnits = Units.PIXELS;
  51.      app.preferences.typeUnits = TypeUnits.PIXELS;
  52.      
  53.     if (docRef.mode != DocumentMode.LAB) {
  54.         docRef.changeMode(ChangeMode.LAB);
  55.        }
  56.     var artLayerRef = docRef.artLayers.add();
  57.          artLayerRef.name = "Patches"
  58.          try {
  59.             var cc = new ColorChecker();
  60.             cc.FindPatchesFromActiveDoc();
  61.           }catch (e) {
  62.               var hs = docRef.historyStates;
  63.               docRef.activeHistoryState = hs[hs.length-4];
  64.               }
  65.          
  66. }
  67.  
  68. function getSelectionColor( x, y, sampleSize ){
  69.      try{
  70.      
  71.           x = x - ( sampleSize / 2 );
  72.           y = y - ( sampleSize / 2 );
  73.           activeDocument.selection.select([[x, y], [x+sampleSize, y], [x+sampleSize, y+sampleSize], [x, y+sampleSize]], SelectionType.REPLACE, 0, false);
  74.           //activeDocument.activeLayer.applyAverage();
  75.           activeDocument.backgroundLayer.applyAverage();
  76.           var re = RegExp( '[123456789]' );
  77.           var sColor = new SolidColor();
  78.           if ( activeDocument.mode == DocumentMode.LAB ) {
  79.               var lv = re.exec(activeDocument.channels[0].histogram.toString() ).index/2;
  80.               sColor.lab.l = 100 * ( lv/255 );
  81.               sColor.lab.a = ( re.exec( activeDocument.channels[1].histogram.toString() ).index/2 ) - 128;
  82.               sColor.lab.b = ( re.exec( activeDocument.channels[2].histogram.toString() ).index/2 ) - 128;
  83.           }
  84.  
  85.           executeAction( charIDToTypeID('undo'), undefined, DialogModes.NO );
  86.           return sColor;
  87.      }catch(e){}
  88. }
  89.  
  90. // -------------------------------------------------------
  91. // 'FindPatchesFromActiveDoc' and  'ComputePatchCoordinates'  
  92. // are inspired by the work of Thomas Fors (Copyright (c) 2007).
  93. // from the script AcrCalibrator.
  94. // -------------------------------------------------------
  95. function ColorChecker() {
  96.    
  97.     this.x = new Array();                       // array of x-axis pixel coordinates of patches
  98.     this.y = new Array();                       // array of y-axiz pixel coordinates of patches
  99.     this.refColor = new Array();                // array of reference patch colors
  100.     this.measColor = new Array();               // array of measured patch colors
  101.  
  102. ColorChecker.prototype['FindPatchesFromActiveDoc'] = function () {
  103.     var tlX, tlY, blX, blY, brX, brY, trX, trY;
  104.    
  105.     // Read path to find corner patches
  106.     if ( activeDocument.pathItems.length == 1 ) {  
  107.         // document contains a single path
  108.         if ( activeDocument.pathItems[0].subPathItems[0].pathPoints.length == 4 ) {  
  109.             // path has exactly four points
  110.             tlX = activeDocument.pathItems[0].subPathItems[0].pathPoints[0].anchor[0];
  111.             tlY = activeDocument.pathItems[0].subPathItems[0].pathPoints[0].anchor[1];
  112.             blX = activeDocument.pathItems[0].subPathItems[0].pathPoints[1].anchor[0];
  113.             blY = activeDocument.pathItems[0].subPathItems[0].pathPoints[1].anchor[1];
  114.             brX = activeDocument.pathItems[0].subPathItems[0].pathPoints[2].anchor[0];
  115.             brY = activeDocument.pathItems[0].subPathItems[0].pathPoints[2].anchor[1];
  116.             trX = activeDocument.pathItems[0].subPathItems[0].pathPoints[3].anchor[0];
  117.             trY = activeDocument.pathItems[0].subPathItems[0].pathPoints[3].anchor[1];
  118.         }
  119.         else {
  120.             alert("Path must have exactly four points");
  121.         }
  122.     }
  123.     else {
  124.         alert ("You must define the chart area. See intructions!!");
  125.     }
  126.    
  127.     this.patchCornerString  = "("+Math.round(tlX)+","+Math.round(tlY)+") ";
  128.     this.patchCornerString += "("+Math.round(blX)+","+Math.round(blY)+") ";
  129.     this.patchCornerString += "("+Math.round(brX)+","+Math.round(brY)+") ";
  130.     this.patchCornerString += "("+Math.round(trX)+","+Math.round(trY)+")";
  131.  
  132.     // X,Y coords of corner patches (tl, bl, br, tr)
  133.     this.ComputePatchCoordinates(tlX,tlY, blX,blY, brX,brY, trX,trY);
  134. }
  135.  
  136. ColorChecker.prototype['ComputePatchCoordinates'] = function (tlX,tlY, blX,blY, brX,brY, trX,trY) {
  137.     var row, col,px,py;
  138.     var fin = new Array();
  139.     var salida = new Array();
  140.     var dif = new Array();
  141.     var cielab= new Array();
  142.     var arrDif = new Array();
  143.     var sampleColor=new SolidColor();
  144.     var  area = 30;
  145.    
  146.     ancho = trX - tlX;
  147.     alto =  blY - tlY;
  148.    
  149.     indiceX = Math.round(ancho/6);
  150.     indiceY = Math.round(alto/4);
  151.     i = 1;
  152.     for ( row = 1; row < 5; row++ ) {
  153.         for ( col = 1; col<7; col++ ) {
  154.             idx = row * 6 + col;                    // patch index
  155.            
  156.             lX = row * (blX - tlX) / 4 + tlX;       // left x coord of row
  157.             rX = row * (brX - trX) / 4 + trX;       // right x coord of row
  158.             this.x[idx] = col * (rX - lX) / 6 + lX; // x coord of patch
  159.             this.x[idx] = Math.round(this.x[idx]);
  160.            
  161.             tY = col * (trY - tlY) / 6 + tlY;       // top y coord of col
  162.             bY = col * (brY - blY) / 6 + blY;       // top y coord of col
  163.             this.y[idx] = row * (bY - tY) / 4 + tY; // y coord of patch
  164.             this.y[idx] = Math.round(this.y[idx]);
  165.            
  166.              x = this.x[idx]  - (indiceX/2)
  167.              y = this.y[idx]   - (indiceY/2)
  168.                                  
  169.              sampleColor = getSelectionColor(x,y,area);
  170.              
  171.              Circle(y-15,x-15,y+area,x+area);
  172.              
  173.              salida[i] = Array(sampleColor.lab.l, sampleColor.lab.a, sampleColor.lab.b );
  174.  
  175.              i++;
  176.         }
  177.    
  178.     }
  179.    
  180.    
  181.     informe( salida);
  182. }
  183.    
  184.     }
  185.  
  186. function informe(finArray){
  187.  
  188.         var valoresCIELAB = "";
  189.         var valoresDiferencia = "";
  190.         var valoresPromedioParches = "";
  191.         var valoresPromedioGlobal = "";
  192.         var valorPromedioTotal00 = 0;
  193.         var si = s();
  194.         var lumas = "";
  195.         var patchCoor = Array("A", "B", "C", "D");
  196.         var valorDeltaE = "";
  197.         var valoresOriginales = "";
  198.         var valorPromedioTotal = 0;
  199.         var SumLumDiff = 0;
  200.         var promedioDeC = 0;
  201.         var promedioDeT = 0;
  202.         var salida = "";
  203.         var j = 0;
  204.         var h = 1;
  205.         var dt = new Date();
  206.            
  207.  
  208.         var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
  209.         var Path = app.activeDocument.path;
  210.  
  211.         var contenido = "";
  212.    
  213.         var f = new File(Path + "/" + Name +"_color_analysis.txt");
  214.          
  215.         f.open("a+");
  216.        
  217.         for(i=1; i < 25; i++) {
  218.              if ((i -1)% 6 == 0) {
  219.                 j++;
  220.                 h = 1;
  221.              }
  222.              parche = patchCoor[j-1]+h;
  223.              h++;
  224.              
  225.              valorDeltaE = deltae(arrayPatches[i-1][0],finArray[i][0],arrayPatches[i-1][1],finArray[i][1],arrayPatches[i-1][2],finArray[i][2]);
  226.              valorPromedioTotal += parseFloat( valorDeltaE );
  227.              valoresCIELAB =  redondea(finArray[i][0],2) +"\t"+ fmtPos(finArray[i][1]) +"\t"+ fmtPos(finArray[i][2]);
  228.              valoresOriginales = redondea(arrayPatches[i-1][0],2)+"\t"+fmtPos(redondea(arrayPatches[i-1][1],2))+"\t"+fmtPos(redondea(arrayPatches[i-1][2],2));
  229.              valorDeltaE00 = deltaE2000(arrayPatches[i-1], finArray[i]);
  230.              valorPromedioTotal00 += parseFloat( valorDeltaE00 );
  231.              
  232.              cr1 = croma(finArray[i][1], finArray[i][2]);
  233.              tn1 = tono(finArray[i][1], finArray[i][2]);
  234.  
  235.              cr2 = croma(arrayPatches[i-1][1], arrayPatches[i-1][2]);
  236.              tn2 = tono(arrayPatches[i-1][1], arrayPatches[i-1][2]);             
  237.              
  238.              DeC = deltaCroma(cr1, cr2);
  239.              promedioDeC += parseFloat( DeC );
  240.              DeT = deltaTono( (arrayPatches[i-1][0] - finArray[i][0]), DeC, valorDeltaE)
  241.              promedioDeT += parseFloat( DeT );
  242.              
  243.              if (i > 18){
  244.                 lumIM = lab2luma(finArray[i]);
  245.                 lumCK = lab2luma( arrayPatches[i-1]);
  246.                 lumDiff = lumIM - lumCK;
  247.                 SumLumDiff += parseFloat(lumDiff);
  248.                 lumas += "\t"+parche +"\t\t"+Math.round(lumIM)+"\t\t"+Math.round(lumCK)+"\t\t"+fmtPos(redondea(lumDiff,1))+"\r"
  249.              }
  250.              
  251.              salida += "\t"+parche +"\t"+valoresCIELAB+ "\t\t"+ valoresOriginales+ "\t\t"+DeC+"\t\t"+DeT+"\t\t"+ valorDeltaE+"\t\t"+ valorDeltaE00 +"\r"
  252.              
  253.         }
  254.        
  255. var CAVG = redondea(promedioDeC/24,2)
  256. var TAVG = redondea(promedioDeT/24,2)
  257. var CIE76AVG = redondea(valorPromedioTotal/24,2);
  258. var CIE00AVG = redondea(valorPromedioTotal00/24,2);
  259. var LUMADIFF  = redondea(SumLumDiff/6,2);    
  260.        
  261.  f.write ( "\r" ) ;
  262.  f.write ( "IMAGE SUMMARY\r");
  263.  f.write ( "----------------------------------------------------------------------------------------------------\r" ) ;
  264.  f.write ( "\r\r" ) ;
  265.  f.write ( "\tProfile: "+profile+"\r");
  266.  f.write ( "\tPath: "+Path+"\r");
  267.  f.write ( "\tName: "+app.activeDocument.name+"\r");
  268.  f.write ( "\tDate: "+dt.getDate()+ "/" + dt.getMonth() + 1 + "/" +dt.getFullYear()+"\r");
  269.  f.write ( "\r" ) ;
  270.  f.write ( "\r" ) ;
  271.  f.write ( "COLOR ANALYSIS\r");
  272.  f.write ( "----------------------------------------------------------------------------------------------------\r" ) ;
  273.  f.write ( "\r\r" ) ;
  274.  f.write ( "\t\tResults\t\t\t\tReferences\r");
  275.  f.write ( "Sample\tL\t\t a\t b\t\tL\t\t a\t\t b\t\t\tdC\t\t\tdH\t\t\tCIE76\t\tCIE00\r");
  276.  f.write ( salida ) ;
  277.  f.write ( "\r" ) ;
  278.  f.write ( "Average\t\t\t\t\t\t\t\t\t\t\t\t\t"+CAVG+"\t\t"+TAVG+"\t\t"+CIE76AVG+"\t\t"+CIE00AVG ) ;
  279.  f.write ( "\r\r" ) ;
  280.  f.write ( "OECF ANALYSIS\r");
  281.  f.write ( "----------------------------------------------------------------------------------------------------\r" ) ;
  282.  f.write ( "\r\r" ) ;
  283.  f.write ( "Sample\t\tRes\t\tRef\t\tDif\r" ) ;
  284.  f.write ( lumas ) ;
  285.  f.write ( "Average\t\t\t\t\t\t"+LUMADIFF ) ;
  286.  f.write ( "\r\r\r\r\t\t\t\t\t\t\t\t"+si ) ;
  287.  
  288.  
  289.  
  290. try {
  291.      
  292.     var myWindow = new Window ("dialog", "Delta Report :: "+si);
  293.     var myInputGroup = myWindow.add ("panel");
  294.     myInputGroup.alignChildren = "left";
  295.     myInputGroup.add ("statictext", undefined, "ΔChroma Average:"+CAVG);
  296.     myInputGroup.add ("statictext", undefined, "ΔHue Average:"+TAVG);
  297.     myInputGroup.add ("statictext", undefined, "ΔCIE76 Average:"+CIE76AVG);
  298.     myInputGroup.add ("statictext", undefined, "ΔCIE00 Average:"+CIE00AVG);
  299.     myInputGroup.add ("statictext", undefined, "ΔLuminance Average:"+LUMADIFF);
  300.  
  301.     var myButtonGroup = myWindow.add ("group");
  302.     myButtonGroup.alignment = "center";
  303.     myButtonGroup.add ("button", undefined, "OK");
  304.     myWindow.show ();
  305. }catch (e) { alert(e)}
  306.              
  307. }
  308.  
  309. Array.prototype.max = function() {
  310. var max = this[0];
  311. var len = this.length;
  312. for (var i = 1; i < len; i++) if (this[i] > max) max = this[i];
  313. return max;
  314. }
  315.  
  316. function getDocProfile(){
  317.    var res = undefined;
  318.    try{
  319.       res =app.activeDocument.colorProfileName;
  320.    }catch(e){}
  321.    return res;
  322. }
  323.  
  324.  
  325. function Circle(Top,Left,Bottom,Right) {
  326.    
  327.    var docRef = activeDocument;
  328.    docRef.activeLayer=docRef.artLayers["Patches"];
  329.    
  330.    var Black = new SolidColor();
  331.         Black.rgb.hexValue = '000000';
  332.    var desc3 = new ActionDescriptor();
  333.    var ref1 = new ActionReference();
  334.         ref1.putProperty( charIDToTypeID('Chnl'), charIDToTypeID('fsel') );
  335.         desc3.putReference( charIDToTypeID('null'), ref1 );
  336.    var desc4 = new ActionDescriptor();
  337.         desc4.putUnitDouble( charIDToTypeID('Top '), charIDToTypeID('#Pxl'), Top );
  338.         desc4.putUnitDouble( charIDToTypeID('Left'), charIDToTypeID('#Pxl'), Left );
  339.         desc4.putUnitDouble( charIDToTypeID('Btom'), charIDToTypeID('#Pxl'), Bottom );
  340.         desc4.putUnitDouble( charIDToTypeID('Rght'), charIDToTypeID('#Pxl'), Right );
  341.         desc3.putObject( charIDToTypeID('T   '), charIDToTypeID('Elps'), desc4 );
  342.         desc3.putBoolean( charIDToTypeID('AntA'), true );
  343.         executeAction( charIDToTypeID('setd'), desc3, DialogModes.NO );
  344.         activeDocument.selection.stroke (Black, 2, StrokeLocation.INSIDE, ColorBlendMode.NORMAL, 100, false);
  345. }
  346.  
  347.  
  348. function redondea(rnum, rlength) {
  349.   var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
  350.   //fmt = padding_right(newnumber, '0', 2);
  351.   //return parseFloat(newnumber);
  352.   return newnumber.toFixed(2);
  353.   //return fmt;
  354. }
  355.  
  356. function padding_right(s, c, n) {
  357.     if (! s || ! c || s.length >= n) {
  358.         return s;
  359.     }
  360.     var max = (n - s.length)/c.length;
  361.     for (var i = 0; i < max; i++) {
  362.         s += c;
  363.     }
  364.     return s;
  365. }
  366.  
  367. function fmtPos(n){
  368. //añade un espacio a los valores positivos
  369. //para nivelarlos con los negativos
  370. if (n >= 0){
  371. return " "+n;
  372. }else{
  373. return n;
  374. }
  375.  
  376. }
  377.  
  378. function porcentage(a, b){
  379.     var valor = 0;
  380.     valor = parseFloat(a)*(parseFloat(b)/100);
  381.     return Math.abs(valor);
  382.    
  383.     }
  384.  
  385.  
  386. function promedio (a){
  387.     var output = 0;
  388.     for(var q=0; q< a.length; q++) {
  389.             output +=  parseFloat( a[q] ) ;
  390.         }
  391.     output = output/3;
  392.     return output.toFixed(2);
  393.     }
  394.  
  395.  
  396. function deltae(l1,l2,a1,a2,b1,b2) {
  397.     //CIE76 formula
  398.     var salida = 0;
  399.     salida =  Math.sqrt( Math.pow(l1-l2,2)  +  Math.pow(a1-a2,2) + Math.pow(b1-b2,2)  )
  400.     return salida.toFixed(2);
  401.     }
  402.    
  403. function croma(a,b) {
  404.     croma =  Math.sqrt( Math.pow(a,2) +  Math.pow(b,2) );
  405.     return croma.toFixed(2);
  406. }
  407.  
  408. function tono(a,b){
  409.  
  410.     tono =  Math.atan2(b,a);
  411.     tonoDeg = tono * 180 / Math.PI;
  412.    
  413.     if (tonoDeg < 0 ){
  414.         tonoDeg += 360;
  415.     }
  416.    
  417.     return tonoDeg.toFixed(2);
  418. }
  419.  
  420. function deltaCroma(c1,c2){
  421.  
  422. dC = Math.abs(c1 - c2);
  423. return dC.toFixed(2);
  424.  
  425. }
  426.  
  427. function s(){
  428.  
  429. a = unescape( '%62%79%3A' );
  430. b = unescape( '%77%77%77%2E%6A%70%65%72%65%69%72%61%2E%6E%65%74%09' );
  431. return b;
  432. }
  433.  
  434. function deltaTono(dl, dC, D76){
  435.  
  436. diff = Math.pow(D76,2)  -  Math.pow(dl,2) - Math.pow(dC,2);
  437.  
  438. if (diff > 0){
  439.     dT = Math.sqrt( diff  );
  440.     return dT.toFixed(2);
  441. }else{
  442.     return "0.00";
  443. }
  444.  
  445. }
  446.  
  447. function lab2XYZ(CIEL, CIEa, CIEb){
  448.  
  449. var result = new Array();
  450.  
  451. var_Y = ( CIEL + 16 ) / 116
  452. var_X = CIEa / 500 + var_Y
  453. var_Z = var_Y - CIEb / 200
  454.  
  455. if ( Math.pow(var_Y,3) > 0.008856 ) {
  456.     var_Y = Math.pow(var_Y,3);
  457. }else{                      
  458.     var_Y = ( var_Y - 16 / 116 ) / 7.787;
  459. }
  460. if ( Math.pow(var_X,3) > 0.008856 ) {
  461.     var_X = Math.pow(var_X,3);
  462. }else{                      
  463.     var_X = ( var_X - 16 / 116 ) / 7.787;
  464. }
  465. if ( Math.pow(var_Z,3) > 0.008856 ) {
  466.     var_Z = Math.pow(var_Z,3);
  467. }else{                      
  468.     var_Z = ( var_Z - 16 / 116 ) / 7.787;
  469. }
  470.  
  471.  
  472. // D65, 2° Observador
  473. X = 0.95047 * var_X ;    
  474. Y = 1.00000 * var_Y ;    
  475. Z = 1.08883 * var_Z ;  
  476.  
  477.  
  478. result[0] = X;
  479. result[1] = Y;
  480. result[2] = Z;
  481.      
  482. return result;
  483.  
  484. }
  485.  
  486. function xyz2rgb(X, Y, Z){
  487.  
  488. var result = new Array();
  489.  
  490. R = X *  3.2406 + Y * -1.5372 + Z * -0.4986;
  491. G = X * -0.9689 + Y *  1.8758 + Z *  0.0415;
  492. B = X *  0.0557 + Y * -0.2040 + Z *  1.0570;
  493.  
  494. if ( R > 0.0031308 ){
  495. R = 1.055 * ( Math.pow(R , ( 1 / 2.4 )) ) - 0.055;
  496. }else{                
  497. R = 12.92 * R;
  498. }
  499. if ( G > 0.0031308 ) {
  500. G = 1.055 * ( Math.pow(G , ( 1 / 2.4 )) ) - 0.055;
  501. }else{                
  502. G = 12.92 * G;
  503. }
  504. if ( B > 0.0031308 ){
  505. B = 1.055 * ( Math.pow(B , ( 1 / 2.4 )) ) - 0.055;
  506. }else{                  
  507. B = 12.92 * B;
  508. }
  509.  
  510. result[0] = Math.round(R * 255);
  511. result[1] = Math.round(G * 255);
  512. result[2] = Math.round(B * 255);
  513.      
  514. return result;
  515.  
  516. }
  517.  
  518. // calcula la luminosidad del observador
  519. function luminosidad(rgb){
  520.     Y = 0.2126*rgb[0] + 0.7152*rgb[1] + 0.0722*rgb[2];
  521.     return Y;
  522. }
  523.  
  524. function luminancia(pl){
  525.     YY = Math.pow( (pl/255), 2.2) * 100;
  526.     return YY;
  527. }
  528.  
  529. function lab2luma(cielab){
  530.  
  531.     XYZ = lab2XYZ(cielab[0], cielab[1], cielab[2]);
  532.     RGB = xyz2rgb(XYZ[0], XYZ[1], XYZ[2]);
  533.     PL = luminosidad(RGB);
  534.     Lum =  luminancia(PL);
  535.     return Lum;
  536.  
  537. }
  538.  
  539. function deltaE2000(lab1, lab2) {
  540.          L1 = lab1[0];
  541.          a1 = lab1[1];
  542.          b1 = lab1[2];
  543.  
  544.          L2 = lab2[0];
  545.          a2 = lab2[1];
  546.          b2 = lab2[2];
  547.  
  548.          Cab1 = Math.sqrt(a1 * a1 + b1 * b1);
  549.          Cab2 = Math.sqrt(a2 * a2 + b2 * b2);
  550.          CabAvg = (Cab1 + Cab2) / 2;
  551.          CabAvg7 = Math.pow(CabAvg, 7);
  552.          G = 1 + (1 - Math.sqrt(CabAvg7 / (CabAvg7 + 6103515625.0))) / 2;
  553.          ap1 = G * a1;
  554.          ap2 = G * a2;
  555.          Cp1 = Math.sqrt(ap1 * ap1 + b1 * b1);
  556.          Cp2 = Math.sqrt(ap2 * ap2 + b2 * b2);
  557.          CpProd = Cp1 * Cp2;
  558.          hp1 = Math.atan2(b1, ap1);
  559.          if (hp1 < 0) {
  560.          hp1 += 6.283185307179586476925286766559;
  561.          }
  562.          hp2 = Math.atan2(b2, ap2);
  563.          if (hp2 < 0) {
  564.          hp2 += 6.283185307179586476925286766559;
  565.          }
  566.          dL = L2 - L1;
  567.          dC = Cp2 - Cp1;
  568.          dhp = 0.0;
  569.          if (CpProd != 0) {
  570.             dhp = hp2 - hp1;
  571.             if (dhp > Math.PI) {
  572.                 dhp -= 6.283185307179586476925286766559;
  573.             } else if (dhp < -Math.PI) {
  574.                 dhp += 6.283185307179586476925286766559;
  575.             }
  576.          }
  577.          dH = 2 * Math.sqrt(CpProd) * Math.sin(dhp / 2);
  578.          Lp = (L1 + L2) / 2 - 50;
  579.          Cp = (Cp1 + Cp2) / 2;
  580.          hp = (hp1 + hp2) / 2;
  581.          if (Math.abs(hp1 - hp2) > Math.PI) {
  582.          hp -= Math.PI;
  583.          }
  584.          if (hp < 0) {
  585.          hp += 6.283185307179586476925286766559;
  586.          }
  587.          LpSqr = Lp * Lp;
  588.          Sl = 1 + 0.015 * LpSqr / Math.sqrt(20 + LpSqr);
  589.          Sc = 1 + 0.045 * Cp;
  590.          hphp = hp + hp;
  591.          T = 1 - 0.17 * Math.cos(hp - 0.52359877559829887307710723054658)
  592.                 + 0.24 * Math.cos(hphp)
  593.                 + 0.32 * Math.cos(hphp + hp + 0.10471975511965977461542144610932)
  594.                 - 0.20 * Math.cos(hphp + hphp - 1.0995574287564276334619251841478);
  595.  
  596.          Sh = 1 + 0.015 * Cp * T;
  597.          powerBase = hp - 4.799655442984406;
  598.          deltaThetaRad = 1.0471975511965977461542144610932 * Math.exp(-5.25249016001879 * powerBase * powerBase);
  599.          Cp7 = Math.pow(Cp, 7);
  600.          Rc = 2 * Math.sqrt(Cp7 / (Cp7 + 6103515625.0));
  601.          RT = -Math.sin(deltaThetaRad) * Rc;
  602.          dLSl = dL / Sl;
  603.          dCSc = dC / Sc;
  604.          dHSh = dH / Sh;
  605.          salida = Math.sqrt(dLSl * dLSl + dCSc * dCSc + dHSh * dHSh + RT * dCSc * dHSh);
  606.          return salida.toFixed(2);
  607.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement