File: invalid2.py

package info (click to toggle)
pyx3 0.17-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,328 kB
  • sloc: python: 27,656; makefile: 225; ansic: 130; sh: 17
file content (54 lines) | stat: -rw-r--r-- 1,585 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
import sys;sys.path.insert(0, "..")
from math import *
from pyx import *
# File for invalid parametrisations of Bezier curves
# Draws a sketch of the areas where invalid params are to be expected

def lhs(x, y, sign1):
    if sign1 > 0:
        return -3*y*(-x + abs(x))
    else:
        return -3*y*(-x - abs(x))

def rhs(x, y, sign2):
    if sign2 > 0:
        return (1-3*x) * (1-y + sqrt(1+y+y*y))
    else:
        return (1-3*x) * (1-y - sqrt(1+y+y*y))

def f(x, y):
    xsigns = [-1, 1]
    ysigns = [-1, 1]
    if 0 < x < 1:
        xsigns = [1]
    if y > -1:
        ysigns = [-1]

    val = float("inf")
    for sign1 in xsigns:
        for sign2 in ysigns:
            val = min(val, abs(lhs(x,y,sign1) - rhs(x,y,sign2)))
    return val

xmin, xmax, xn = -2, 3, 250
xvalues = [xmin + (xmax-xmin)*i/(xn-1) for i in range(xn)]
ymin, ymax, yn = -3, 2, 250
yvalues = [ymin + (ymax-ymin)*i/(yn-1) for i in range(yn)]

d = []
for x in xvalues:
    for y in yvalues:
        d.append((x, y, log(f(x, y))))

g = graph.graphxy(width=10,
    x=graph.axis.lin(title=r"$\Delta x$", min=xmin, max=xmax),
    y=graph.axis.lin(title=r"$\Delta y$", min=ymin, max=ymax),
)
g.plot(graph.data.points(d, x=1, y=2, color=3, title=None),
       [graph.style.density(gradient=color.rgbgradient.Rainbow)])
g.dolayout()
g.plot(graph.data.function("x(y)=(-1-2*y-sqrt((1+2*y)**2+3))/3.0"), [graph.style.line([style.linestyle.dotted])])
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])])
g.writePDFfile()