In this paper, we propose a Grid-based Non-uniform Probability Density Sampling Probabilistic Roadmap algorithm (GN-PRM) in response to the challenges of difficult sampling in narrow passages and low-probability map generation in traditional Probabilistic Roadmap algorithms (PRM). The improved algorithm incorporates grid-based processing for map segmentation, employing non-uniform probability density sampling based on the different attributes of each block to enhance sampling probability in narrow passages. Additionally, considering the computational cost and frequent ineffective searches in traditional PRM algorithms during pathfinding, this paper optimizes the time required for query route planning by altering connection strategies to improve the algorithm’s runtime. Finally, the simulation results indicate that, with a reduction of over 50% in undirected line segments and a reduction of over 85% in runtime, the GN-PRM algorithm achieves a 100% success rate in complex planning scenarios with a sampling point value of K = 500. In comparison, the traditional PRM algorithm has a success rate of no more than 10%, with a sampling point value of K = 500.