Collision avoidance is an intensive discussion issue for navigation safety. This article introduces a new routing algorithm for finding optimal routes with collision detection and avoidance on raster charts or planes. After the required data structure of the raster chart is initialized, the maze routing algorithm is applied to obtain the particular route of each ship. Those ships that have potential to collide will be detected by simulating the particular routes with ship domains. The collision avoidance scheme can be achieved by using the collision-area-marking method with collision avoidance rules at sea. The algorithm has linear time and space complexities, and is sufficiently fast to perform real-time routing on the raster charts.