示例#1
0
z23 = vector([z22.x-z2diff.y, z22.y+z2diff.x])
z24 = vector([z21.x-z2diff.y, z21.y+z2diff.x])
z33 = vector([z32.x-z3diff.y, z32.y+z3diff.x])
z34 = vector([z31.x-z3diff.y, z31.y+z3diff.x])
z43 = vector([z42.x-z4diff.y, z42.y+z4diff.x])
z44 = vector([z41.x-z4diff.y, z41.y+z4diff.x])

# define the centers of the outer squares
z1 = 0.5*(z11 + z13)
z2 = 0.5*(z21 + z23)
z3 = 0.5*(z31 + z33)
z4 = 0.5*(z41 + z43)

# define the crossing point by some equations
z0 = vector(2)
solver.eq(z0, z1 + scalar()*(z3-z1))
solver.eq(z0, z2 + scalar()*(z4-z2))

# finally draw the result

def line(p1, p2):
    return path.line(float(p1.x), float(p1.y), float(p2.x), float(p2.y))

def square(p1, p2, p3, p4):
    return path.path(path.moveto(float(p1.x), float(p1.y)),
                     path.lineto(float(p2.x), float(p2.y)),
                     path.lineto(float(p3.x), float(p3.y)),
                     path.lineto(float(p4.x), float(p4.y)),
                     path.closepath())

c = canvas.canvas()
示例#2
0
import sys; sys.path.insert(0, "../..")
from pyx import *
from solve import scalar, vector, solver

A = vector([0, 0], "A")
B = vector([10, 5], "B")
C = vector([0, 10], "C")
D = vector([scalar(), 0], "D")

solver.eq((B-A)*(D-C), 0)

def line(p1, p2):
    return path.line(float(p1.x), float(p1.y), float(p2.x), float(p2.y))

c = canvas.canvas()

c.stroke(line(A, B))
c.stroke(line(C, D))

c.writeEPSfile()
c.writePDFfile()