First semi-workable version in git.
Apart from miscalculated cutout corners it seems to be working.master
parent
f65156ce96
commit
95d2f45472
@ -0,0 +1,95 @@
|
||||
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?
|
||||
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(llba, corners[0]);
|
||||
pair lrta = (1, 1);
|
||||
real lrtb = dot(llta, 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);
|
||||
|
||||
// Draw the cutouts
|
||||
draw(cl1 -- corners[2] -- cl2);
|
||||
draw(cr1 -- corners[0] -- cr2);
|
||||
draw(cb1 -- corners[3] -- cb2);
|
||||
draw(ct1 -- corners[1] -- ct2);
|
Loading…
Reference in New Issue