This paper develops a tool path optimization method for robotic surface machining by sampling-based motion planning algorithms. In the surface machining process, the tool-tip position needs to strictly follow the tool path curve and the posture of the tool axis should be limited in a certain range. But the industrial robot has at least six degrees-of-freedom (Dof) and has redundant Dofs for surface machining. Therefore, the tool motion of surface machining can be optimized using the redundant Dofs considering the tool path constraints and limits of the tool axis orientation. Due to the complexity of the problem, the sampling-based motion planning method has been chosen to find the solution, which randomly explores the configuration space of the robot and generates a discrete path of valid robot state. During the solving process, the joint space of the robot is chosen as the configuration space of the problem and the constraints for the tool-tip following requirements are in the operation space. Combined with general collision checking, the limited region of the tool axis vector is used to verify the state’s validity of the configuration space. In the optimization process, the sum of the path length of each joint of the robot is set as the optimization objective. The algorithm is developed based on the open motion planning library (OMPL), which contains the state-of-the-art sampling-based motion planners. Finally, two examples are used to demonstrate the effiectiveness and optimality of the method.