fix cross-device link error
[PyX.git] / design / invalid1.py
blob38ff94023f79f24c67a1f4e7bf38d3d6a471ba34
1 #!/usr/bin/env python
2 import sys;sys.path.insert(0, "..")
3 from math import *
4 from pyx import *
5 # File for invalid parametrisations of Bezier curves
6 # visualise the constraints
8 def fx(x, sign1):
9 if x < 1/3.0: # a_x > 0
10 if sign1 == "upper":
11 return -x + abs(x)
12 else:
13 return -x - abs(x)
14 else:
15 if sign1 == "upper":
16 return x - abs(x)
17 else:
18 return x + abs(x)
20 def boundx(x):
21 if x < 1/3.0:
22 return 1-3*x
23 else:
24 return 3*x-1
26 def fy(y, sign2):
27 if y < 0: # a_y > 0
28 if sign2 == "upper":
29 return 1-y + sqrt(1+y+y*y)
30 else:
31 return 1-y - sqrt(1+y+y*y)
32 else:
33 if sign2 == "upper":
34 return y-1 - sqrt(1+y+y*y)
35 else:
36 return y-1 + sqrt(1+y+y*y)
38 def boundy(y):
39 if y < 0:
40 return -3*y
41 else:
42 return 3*y
44 def doplot(xtitle, con):
45 g = graph.graphxy(width=10,
46 x=graph.axis.lin(title=xtitle, min=-5, max=5),
47 y=graph.axis.lin(),
48 key=graph.key.key(pos="tc"),
50 g.plot(graph.data.function("y(x)=0", points=2, title=None), [graph.style.line()])
51 g.plot(graph.data.function("y(x)=bound(x)", title=None, context=con, points=101), [graph.style.line()])
52 g.plot(graph.data.function("y(x)=f(x, 'upper')", title="upper sign", context=con, points=101), [graph.style.line([color.rgb.red])])
53 g.plot(graph.data.function("y(x)=f(x, 'lower')", title="lower sign", context=con, points=101), [graph.style.line([color.rgb.green])])
54 return g
57 c1 = doplot(r"$\Delta x$", {"f":fx, "bound":boundx})
58 c2 = doplot(r"$\Delta y$", {"f":fy, "bound":boundy})
59 c1.insert(c2, [trafo.translate(0, c1.bbox().bottom() - c2.bbox().top() - 0.5)])
60 c1.writePDFfile()