// Y Stitching Measurement (v1.2) // Demonstration of measuring Y-Stitch error from the position difference between two gratings. // Provided as-is by GenISys. // // Define Functions // // compare the x positions of two features; used to sort the features into ordervar compareX = function (a, b) { var compareX = function(a, b) { return a[0].CenterX - b[0].CenterX;} var compareY = function(a, b) { return a[0].CenterY - b[0].CenterY;} // compute the average of two angles in a 0-180 limited coordinate space var avgTwoAngles = function(a) { if (abs(a[0] - a[1]) > 90) { return ((a[0] + a[1] - 180) / 2.0); } else { return ((a[0] + a[1]) / 2.0); } } // there must be exactly four groups if (image.length != 4) { "Error: Must have 4 groups." } else { // extract first four groups from image, sort by coodinates of first measurements var groups = [0, 1, 2, 3].map(function(i) { return image[i]; }).sort(compareX); var left = [groups[0], groups[1]].sort(compareY); var right = [groups[2], groups[3]].sort(compareY); // use convenient labels for the quadrants to be used here; the upper two quadrants var UL = left[1]; var UR = right[1]; // Check that both groups have the same number of features, give error message if not. var c1 = UL.length; var c2 = UR.length; if (c1 != c2) { "Error: Groups must have same # of features." } else { var stsum = 0; // step through each feature in the grating, compute the difference in center Y position // taking rotation of the lines into account for (var i = 0; i < c1; i++) { m1 = UL[i]; m2 = UR[i]; var xcenter = (m1.E0CenterX + m1.E1CenterX + m2.E0CenterX + m2.E1CenterX) / 4; var t1 = ((m2.E0CenterY + m2.E1CenterY) / 2) + (tan(toRadians(avgTwoAngles([m2.E0Angle, m2.E1Angle]))) * (xcenter - (m2.E0CenterX + m2.E1CenterX) / 2)); var t2 = ((m1.E0CenterY + m1.E1CenterY) / 2) + (tan(toRadians(avgTwoAngles([m1.E0Angle, m1.E1Angle]))) * (xcenter - (m1.E0CenterX + m1.E1CenterX) / 2)); stsum = stsum + (t1 - t2); } // end for loop (stsum / c1); // the stitching error is the average of the individual line errors. } // end error check for number of grating elements } // end error check for number of groups