fix defaults for x any y (to be strings)
[PyX.git] / design / invalid2.py
blobd8ac0040ea4838889e88dee561c5a86638f619ab
1 #!/usr/bin/env python3
2 import sys;sys.path.insert(0, "..")
3 from math import *
4 from pyx import *
5 # File for invalid parametrisations of Bezier curves
6 # Draws a sketch of the areas where invalid params are to be expected
8 def lhs(x, y, sign1):
9 if sign1 > 0:
10 return -3*y*(-x + abs(x))
11 else:
12 return -3*y*(-x - abs(x))
14 def rhs(x, y, sign2):
15 if sign2 > 0:
16 return (1-3*x) * (1-y + sqrt(1+y+y*y))
17 else:
18 return (1-3*x) * (1-y - sqrt(1+y+y*y))
20 def f(x, y):
21 xsigns = [-1, 1]
22 ysigns = [-1, 1]
23 if 0 < x < 1:
24 xsigns = [1]
25 if y > -1:
26 ysigns = [-1]
28 val = float("inf")
29 for sign1 in xsigns:
30 for sign2 in ysigns:
31 val = min(val, abs(lhs(x,y,sign1) - rhs(x,y,sign2)))
32 return val
34 xmin, xmax, xn = -2, 3, 250
35 xvalues = [xmin + (xmax-xmin)*i/(xn-1) for i in range(xn)]
36 ymin, ymax, yn = -3, 2, 250
37 yvalues = [ymin + (ymax-ymin)*i/(yn-1) for i in range(yn)]
39 d = []
40 for x in xvalues:
41 for y in yvalues:
42 d.append((x, y, log(f(x, y))))
44 g = graph.graphxy(width=10,
45 x=graph.axis.lin(title=r"$\Delta x$", min=xmin, max=xmax),
46 y=graph.axis.lin(title=r"$\Delta y$", min=ymin, max=ymax),
48 g.plot(graph.data.points(d, x=1, y=2, color=3, title=None),
49 [graph.style.density(gradient=color.rgbgradient.Rainbow)])
50 g.dolayout()
51 g.plot(graph.data.function("x(y)=(-1-2*y-sqrt((1+2*y)**2+3))/3.0"), [graph.style.line([style.linestyle.dotted])])
52 g.plot(graph.data.function("x(y)=(-1-2*y+sqrt((1+2*y)**2+3))/3.0", max=-1), [graph.style.line([style.linestyle.dotted])])
53 g.writePDFfile()