Skip to content

Commit 84fdbeb

Browse files
committed
Testing stuff to be moved later
1 parent 1f70997 commit 84fdbeb

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

development/points2line.jl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using LinearAlgebraX
2+
3+
"""
4+
points2line(x1::Union{Rational,Integer}, y1::Union{Rational,Integer}, x2::Union{Rational,Integer}, y2::Union{Rational,Integer})
5+
6+
Given points `x1,y1` and `x2,y2` return `a,b,c` such that both points satisfy `a*x + b*y = c`.
7+
"""
8+
function points2line(
9+
x1::Union{Rational,Integer},
10+
y1::Union{Rational,Integer},
11+
x2::Union{Rational,Integer},
12+
y2::Union{Rational,Integer},
13+
)
14+
M = [x1 y1 1; x2 y2 1]
15+
abc = collect(nullspacex(M))
16+
dlist = denominator.(abc)
17+
d = lcm(dlist...)
18+
abc *= d
19+
if abc[1] < 0
20+
abc *= -1
21+
end
22+
abc[3] *= -1
23+
24+
a, b, c = Int.(abc)
25+
26+
return a, b, c
27+
end
28+
29+
function points2line(z1, z2)
30+
x1, y1 = reim(z1)
31+
x2, y2 = reim(z2)
32+
return points2line(x1, y1, x2, y2)
33+
end
34+
35+
"""
36+
points2inequality(z1, z2, w)
37+
38+
Print an inequality for the halfspace bounded by the line through
39+
`z1` and `z2` that contains `w`.
40+
"""
41+
function points2inequality(z1, z2, w)
42+
a, b, c = points2line(z1, z2)
43+
44+
x, y = reim(w)
45+
46+
if a*x + b*y < c
47+
a, b, c = -a, -b, -c
48+
end
49+
println("$a*x + $b*y ≥ $c")
50+
end

development/polygon_example.jl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
include("points2line.jl")
2+
using SimpleDrawing, SimpleDrawingObjects, Clines, SimplexTableaux
3+
4+
function my_points()
5+
[1+im, 5+2im, 6+3im, 5+5im, 3+5im, 2+4im]
6+
end
7+
8+
function make_lines(plist)
9+
newdraw()
10+
w = 3 + 3im
11+
12+
P = FilledPolygon(plist)
13+
set_fillcolor!(P, "lightgray")
14+
draw(P)
15+
16+
draw_xaxis(8)
17+
draw_xaxis(-1)
18+
draw_xtick(1:7)
19+
20+
draw_yaxis(7)
21+
draw_yaxis(-1)
22+
draw_ytick(1:6)
23+
24+
np = length(plist)
25+
for i in 1:(np - 1)
26+
points2line(plist[i], plist[i + 1])
27+
points2inequality(plist[i], plist[i + 1], w)
28+
end
29+
points2line(plist[1], plist[end])
30+
points2inequality(plist[1], plist[end], w)
31+
32+
for p in plist
33+
P = Point(p)
34+
set_pointsize!(P, 3)
35+
draw(P)
36+
end
37+
38+
L = Line(0, 10, 10, 0)
39+
draw(L)
40+
L = Line(2, 0, 0, 2)
41+
draw(L)
42+
43+
finish()
44+
# np = length(plist)
45+
46+
end
47+
48+
make_lines() = make_lines(my_points())
49+
50+
function make_hex_Abc()
51+
A = [-1 4; -1 1; -2 -1; 0 -1; 1 -1; 3 -1]
52+
b = [3, -3, -15, -5, -2, 2]
53+
c = [1; 1]
54+
return A, b, c
55+
end
56+
57+
function make_hex_tableau()
58+
B = [1, 2, 3, 4, 7, 8]
59+
T = Tableau(make_hex_Abc()...)
60+
set_basis!(T, B)
61+
return T
62+
end

0 commit comments

Comments
 (0)