from settings access outformat; outformat="pdf"; unitsize(1mm); int pgw = 210; int pgh = 297; size(pgw, pgh); int sqsz = pgw; // C6: 114 x 162 mm int envh = 114; int envw = 162; string envfmt = "C6"; // A6: 105 x 148 mm // debugging tool bool with_labels = true; // It is unpractical to try emulating second quadrant. We will work in the // first quadrant with the origin at the bottom-left corner of the square (not // the whole page). Therefore, the bottom edge of the page is at y=(210-297) int pgbot = 210-297; //Force A4 size //draw((0,pgbot) -- (0, sqsz) -- (sqsz, sqsz) -- (sqsz, pgbot) -- cycle, invisible); // gimme a square? if (with_labels) draw(box((0,0), (210,210)), p=red); pair envc = (sqsz/2, sqsz/2); // Write a paper type to the image? if (with_labels) label(rotate(45)*scale(4)*Label(envfmt, envc, p=gray)); pair corn_vec = unit((1,1)) * (envw/2) + unit((1,-1)) * (envh/2); pair flip(pair p) { return p - unit((1, -1)) * envh; } pair[] corners = { envc + corn_vec, envc + flip(corn_vec), envc - corn_vec, envc - flip(corn_vec), }; // Draw the base rectangle draw(corners[0] -- corners[1] -- corners[2] -- corners[3] -- cycle, p=gray+dashed); if (with_labels) { label("$E_0$", corners[0]); label("$E_1$", corners[1]); label("$E_2$", corners[2]); label("$E_3$", corners[3]); } // Enlarge the sides: //llba: line at left bottom, A side pair llba = (1, 1); real llbb = dot(llba, corners[2]); pair llta = (1, -1); real lltb = dot(llta, corners[2]); pair lrba = (1, -1); real lrbb = dot(lrba, corners[0]); pair lrta = (1, 1); real lrtb = dot(lrta, corners[0]); pair lineinters(pair l1a, real l1b, pair l2a, real l2b) { // For some reason, solve does not like having the matrices right in the // parameters? (Or I made a stupid error in parentheses…) real[][] a = {{l1a.x, l1a.y}, {l2a.x, l2a.y}}; real[] b = {l1b, l2b}; real[] solution = solve(a,b); return (solution[0], solution[1]); } // Cutouts at all the sides: // Left: (cutout left first point) // Left edge: x = 0 = 1x + 0y pair cl1 = lineinters(llba, llbb, (1, 0), 0); pair cl2 = lineinters(llta, lltb, (1, 0), 0); // right pair cr1 = lineinters(lrba, lrbb, (1, 0), sqsz); pair cr2 = lineinters(lrta, lrtb, (1, 0), sqsz); // bottom pair cb1 = lineinters(llba, llbb, (0, 1), 0); pair cb2 = lineinters(lrba, lrbb, (0, 1), 0); // top pair ct1 = lineinters(llta, lltb, (0, 1), sqsz); pair ct2 = lineinters(lrta, lrtb, (0, 1), sqsz); if (with_labels) { label("$CL_1$", cl1); label("$CL_2$", cl2); label("$CR_1$", cr1); label("$CR_2$", cr2); label("$CT_1$", ct1); label("$CT_2$", ct2); label("$CB_1$", cb1); label("$CB_2$", cb2); } // We do not make the envelope fully symmetric, instead we trim the side // lobes near the cover. cr1 = (corners[0].x, sqsz); cb2 = (0, corners[3].y); // Draw the cutouts draw(cl1 -- corners[2] -- cl2); draw(cr1 -- corners[0] -- cr2); draw(cb1 -- corners[3] -- cb2); draw(ct1 -- corners[1] -- ct2); // Draw the outline of the whole template. This is handy when not printing on // the correctly sized paper. We are lazy and draw it piecewise. draw(cb2 -- cl2); draw(cl1 -- (0, sqsz) -- ct2); draw(ct1 -- cr1); draw(cr2 -- (sqsz, 0) -- cb1);