In order to solve the problem of low spraying efficiency and excessive paint waste caused by overspray when the robot automatically sprays irregular plane, a method of spray trajectory planning with boundary-constrained considering spray gun changing posture is proposed. The static spraying model of the spray gun with variable posture, and the dynamic spraying model of the spray gun along the arc path are established separately, an optimization method for the symmetry of coating distribution based on the variable spray angle when the gun spraying along the arc path is proposed. Orthogonal experiment method based on numerical simulation is used to clarify the influence of boundary curve shape and spray gun posture on boundary constraint distance, the prediction of the value range of the boundary constraint distance at the boundary of different curvature radius is realized. Within the range of the value of the boundary constraint, combined with the equal division method of the plane intercept line and the distance search method, a boundary constraint spray path generation algorithm is established by setting a uniform boundary constraint distance value. Finally, a multivariable spraying parameter optimization algorithm based on PSO is established, the spraying velocity, spraying height and spraying angle in the dynamic spraying process are solved, and the coating uniformity is optimized. The effectiveness and feasibility of the proposed spray trajectory planning method is verified by robot spraying experiment for any irregular plane.