@@ -51,10 +51,44 @@ def get_target_point(path, targetL):
51
51
return [x , y , ti ]
52
52
53
53
54
- def line_collision_check (first , second , obstacle_list , robot_radius = 0.0 ):
54
+ def is_point_collision (x , y , obstacle_list , robot_radius ):
55
+ """
56
+ Check whether a single point collides with any obstacle.
57
+
58
+ This function calculates the Euclidean distance between the given point (x, y)
59
+ and each obstacle center. If the distance is less than or equal to the sum of
60
+ the obstacle's radius and the robot's radius, a collision is detected.
61
+
62
+ Args:
63
+ x (float): X-coordinate of the point to check.
64
+ y (float): Y-coordinate of the point to check.
65
+ obstacle_list (List[Tuple[float, float, float]]): List of obstacles defined as (ox, oy, radius).
66
+ robot_radius (float): Radius of the robot, used to inflate the obstacles.
67
+
68
+ Returns:
69
+ bool: True if the point is in collision with any obstacle, False otherwise.
70
+ """
71
+ for (ox , oy , obstacle_radius ) in obstacle_list :
72
+ d = math .hypot (ox - x , oy - y )
73
+ if d <= obstacle_radius + robot_radius :
74
+ return True # Collided
75
+ return False
76
+
77
+
78
+ def line_collision_check (first , second , obstacle_list , robot_radius = 0.0 , sample_step = 0.2 ):
55
79
"""
56
80
Check if the line segment between `first` and `second` collides with any obstacle.
57
81
Considers the robot_radius by inflating the obstacle size.
82
+
83
+ Args:
84
+ first (List[float]): Start point of the line [x, y]
85
+ second (List[float]): End point of the line [x, y]
86
+ obstacle_list (List[Tuple[float, float, float]]): Obstacles as (x, y, radius)
87
+ robot_radius (float): Radius of robot
88
+ sample_step (float): Distance between sampling points along the segment
89
+
90
+ Returns:
91
+ bool: True if collision-free, False otherwise
58
92
"""
59
93
x1 , y1 = first [0 ], first [1 ]
60
94
x2 , y2 = second [0 ], second [1 ]
@@ -64,19 +98,18 @@ def line_collision_check(first, second, obstacle_list, robot_radius=0.0):
64
98
length = math .hypot (dx , dy )
65
99
66
100
if length == 0 :
67
- return True # Degenerate case
101
+ # Degenerate case: point collision check
102
+ return not is_point_collision (x1 , y1 , obstacle_list , robot_radius )
68
103
69
- steps = int (length / 0.2 ) + 1 # Sampling every 0.2m along the segment
104
+ steps = int (length / sample_step ) + 1 # Sampling every sample_step along the segment
70
105
71
106
for i in range (steps + 1 ):
72
107
t = i / steps
73
108
x = x1 + t * dx
74
109
y = y1 + t * dy
75
110
76
- for (ox , oy , size ) in obstacle_list :
77
- d = math .hypot (ox - x , oy - y )
78
- if d <= size + robot_radius :
79
- return False # Collision
111
+ if is_point_collision (x , y , obstacle_list , robot_radius ):
112
+ return False # Collision found
80
113
81
114
return True # Safe
82
115
@@ -149,7 +182,7 @@ def main():
149
182
(3 , 10 , 2 ),
150
183
(7 , 5 , 2 ),
151
184
(9 , 5 , 2 )
152
- ] # [x,y,size ]
185
+ ] # [x,y,radius ]
153
186
rrt = RRT (start = [0 , 0 ], goal = [6 , 10 ],
154
187
rand_area = [- 2 , 15 ], obstacle_list = obstacleList ,
155
188
robot_radius = 0.3 )
0 commit comments