1 # this example is adapted from a MetaPost example by Hans Hagen
3 import sys
; sys
.path
.insert(0, "../..")
5 from solve
import scalar
, vector
, solver
7 # define the inner quadrilateral
13 # some points of the outer squares are equal to points of the inner quadrilateral
23 # complete the definition of the outer squares
29 z13
= vector([z12
.x
-z1diff
.y
, z12
.y
+z1diff
.x
])
30 z14
= vector([z11
.x
-z1diff
.y
, z11
.y
+z1diff
.x
])
31 z23
= vector([z22
.x
-z2diff
.y
, z22
.y
+z2diff
.x
])
32 z24
= vector([z21
.x
-z2diff
.y
, z21
.y
+z2diff
.x
])
33 z33
= vector([z32
.x
-z3diff
.y
, z32
.y
+z3diff
.x
])
34 z34
= vector([z31
.x
-z3diff
.y
, z31
.y
+z3diff
.x
])
35 z43
= vector([z42
.x
-z4diff
.y
, z42
.y
+z4diff
.x
])
36 z44
= vector([z41
.x
-z4diff
.y
, z41
.y
+z4diff
.x
])
38 # define the centers of the outer squares
44 # define the crossing point by some equations
46 solver
.eq(z0
, z1
+ scalar()*(z3
-z1
))
47 solver
.eq(z0
, z2
+ scalar()*(z4
-z2
))
49 # finally draw the result
52 return path
.line(float(p1
.x
), float(p1
.y
), float(p2
.x
), float(p2
.y
))
54 def square(p1
, p2
, p3
, p4
):
55 return path
.path(path
.moveto(float(p1
.x
), float(p1
.y
)),
56 path
.lineto(float(p2
.x
), float(p2
.y
)),
57 path
.lineto(float(p3
.x
), float(p3
.y
)),
58 path
.lineto(float(p4
.x
), float(p4
.y
)),
63 c
.stroke(square(z11
, z12
, z13
, z14
))
64 c
.stroke(square(z21
, z22
, z23
, z24
))
65 c
.stroke(square(z31
, z32
, z33
, z34
))
66 c
.stroke(square(z41
, z42
, z43
, z44
))
68 c
.stroke(line(z11
, z13
), [style
.linestyle
.dashed
, style
.linewidth
.Thin
])
69 c
.stroke(line(z12
, z14
), [style
.linestyle
.dashed
, style
.linewidth
.Thin
])
70 c
.stroke(line(z21
, z23
), [style
.linestyle
.dashed
, style
.linewidth
.Thin
])
71 c
.stroke(line(z22
, z24
), [style
.linestyle
.dashed
, style
.linewidth
.Thin
])
72 c
.stroke(line(z31
, z33
), [style
.linestyle
.dashed
, style
.linewidth
.Thin
])
73 c
.stroke(line(z32
, z34
), [style
.linestyle
.dashed
, style
.linewidth
.Thin
])
74 c
.stroke(line(z41
, z43
), [style
.linestyle
.dashed
, style
.linewidth
.Thin
])
75 c
.stroke(line(z42
, z44
), [style
.linestyle
.dashed
, style
.linewidth
.Thin
])
77 c
.stroke(square(p
, q
, r
, s
), [color
.rgb
.red
, style
.linewidth
.THick
])
79 c
.stroke(line(z1
, z3
), [color
.rgb
.green
])
80 c
.stroke(line(z2
, z4
), [color
.rgb
.green
])
82 c
.fill(path
.circle(float(z0
.x
), float(z0
.y
), 0.1), [color
.rgb
.blue
])