This answer quotes ChatGPT

In the Astar algorithm, if a path traverses an obstacle, a common solution is to use trajectory collision detection to detect whether the path is legitimate. If the path intersects an obstacle, the path needs to be corrected to avoid the obstacle and create a legal path again.

Here are some ideas to help you implement trajectory collision detection and generate a new point function:

1. Divide the path into a series of segments

Divide the original path into a series of segments at certain intervals. These segments can be straight lines or curved segments.

2. Detect whether the segment intersects with obstacles

For each segment, collision detection algorithm(such as line segment-polygon intersection detection) is used to detect whether it intersects with obstacles. If so, it indicates that the segment cannot pass through, and you need to create a new legal path.

3, generate a new waypoint

If a small section is found to intersect with an obstacle, you can consider generating a legal path. There are many ways to generate new waypoints. The following are some common methods:

4. Path correction based on elastic collision

This method divides the path into a series of small segments, calculates the collision point between each segment and the obstacle, and then makes elastic correction on the path at the point to make the path bypass the obstacle. This method can produce relatively smooth path, but requires more complex mathematical calculation.

5. Path correction based on repulsive force field

This method uses the concept of repulsive force field to generate a repulsive force field around an obstacle, making the path bypass the obstacle along the direction of the repulsive force field. This method is relatively simple, but may result in uneven paths.

6. Path correction based on Random walk

This method is based on the idea of random walk. The path is randomly walked for a distance from the collision point, and then the path is reconnected. This method is relatively simple, but may produce unstable paths.

In short, trajectory collision detection is a complicated problem, which needs to be selected according to the specific situation. The above ideas are for reference only, and the specific implementation needs to be adjusted according to the actual situation.