-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
53 lines (43 loc) · 1.91 KB
/
example.py
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
from intervalpylib import AreaCalculator, SymbolicEquationSolver, KrawczykSolver
import intervalpy as ival
import numpy as np
config = "2-RPR"
if config == "2-RPR":
# Choose solver
solver = KrawczykSolver("2-RPR")
# Choose drawer and its parameters (depend on the configuration)
drawer = AreaCalculator("2-RPR", [3, 15, 8])
# Choose grid
grid = AreaCalculator.make_grid2d(left_bottom=(-20, -20), right_top=(20, 20), N=128)
# Choose lengths of rods in the 2-RPR configuration
x_num = np.array([ival.Interval([3, 15])] * 2)
# Solve the area
inside, border = solver.solve(SymbolicEquationSolver("2-RPR", [8]), grid, x_num)
# Plot the computed area
drawer.uni_plotter(inside, border, size=2, ini_box=[[-20, 20]] * 2, title="Krawczyk")
elif config == "3-RPR":
# Choose solver
solver = KrawczykSolver("3-RPR")
# Choose parameters (this code just rotates the circles around the point 150 degrees)
import math
phi = math.radians(150)
x_a = [-15, 15, 0]
y_a = [-5 * np.sqrt(3), -5 * np.sqrt(3), 10 * np.sqrt(3)]
x_b = [-5, 5, 0]
y_b = [-5 * np.sqrt(3) / 3, -5 * np.sqrt(3) / 3, 10 * np.sqrt(3) / 3]
x_c = np.zeros(3)
y_c = np.zeros(3)
for i in range(3):
x_c[i] = x_a[i] - x_b[i] * np.cos(phi) + y_b[i] * np.sin(phi)
y_c[i] = y_a[i] - x_b[i] * np.sin(phi) - y_b[i] * np.cos(phi)
length = [12, 27]
# Choose drawer
drawer = AreaCalculator("3-RPR", [x_c, y_c, length[0], length[1]])
# Choose grid
grid = AreaCalculator.make_grid2d(left_bottom=(-20, -20), right_top=(20, 20), N=128)
# Choose lengths of rods in the 2-RPR configuration
x_num = np.array([ival.Interval(length)] * 3)
# Solve the area
inside, border = solver.solve(SymbolicEquationSolver("3-RPR", [x_c, y_c]), grid, x_num)
# Plot the computed area
drawer.uni_plotter(inside, border, size=2, ini_box=[[-20, 20]] * 2, title="Krawczyk")