-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReachabilityCircleCheck.py
89 lines (73 loc) · 2.76 KB
/
ReachabilityCircleCheck.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This function finds intersection region of circles whose radius
is the wing length of robot. Although it doesn't say exact workspace
of the robot, but it gives an estimate about where it is
"""
# Libraries
from sympy.geometry import Circle, Point
# Own Modules
from RobotData import RobotData
__author__ = "Emre Cemal Gonen"
__copyright__ = "Copyright (C) 2019, Emre Cemal Gonen"
__credits__ = ["Prof. Dr. Volkan Patoglu", "Sabanci University"]
__version__ = "1.0"
__email__ = "[email protected]"
def circle_intersections(holds):
"""
This returns intersection points of the circles
:param holds: an array containing holds
:return: intersection points (x coordinates, y coordinates and middle point)
"""
def _check_point_in_circle(px, py):
"""
This sub-function checks whether a point is in a circle or not
:param px: X coordinate of the point
:param py: Y coordinate of the point
:return: Boolean
"""
distance_to_holds = []
for h in holds:
d_sq = (px - h.x) ** 2 + (py - h.y) ** 2
distance_to_holds.append(round(d_sq, 6))
return all(i <= round(circle_radius ** 2, 6) for i in distance_to_holds)
# Circle Radius same for all circles
circle_radius = RobotData.l1 + RobotData.l2 + RobotData.r
# Number of holds
hold_num = len(holds)
# Create of circles as Symbolic because Sympy has solver to find intersection points
circle_list = []
for i in range(hold_num):
circle_list.append(Circle(Point(holds[i].x, holds[i].y), circle_radius))
# Find Intersections
intersection_list = []
for i in range(hold_num):
circle = circle_list[i]
check_circles = circle_list[i + 1:]
for check in check_circles:
intersection_list.append(circle.intersection(check))
# Get Intersection Points
points = []
for intersections in intersection_list:
if len(intersections) == 1:
intersections.append(intersections[0])
p0 = intersections[0]
p1 = intersections[1]
points.append([(float(p0.x), float(p0.y)), (float(p1.x), float(p1.y))])
# Now all intersection points are found, but we desire only intersections of all circles
# Get the points only desired
xs = []
ys = []
for inter_points in points:
p0x = inter_points[0][0]
p0y = inter_points[0][1]
p1x = inter_points[1][0]
p1y = inter_points[1][1]
if _check_point_in_circle(p0x, p0y):
xs.append(p0x)
ys.append(p0y)
if _check_point_in_circle(p1x, p1y):
xs.append(p1x)
ys.append(p1y)
return xs, ys, sum(xs) / len(xs), sum(ys) / len(ys)