A periodic optimization method for diffractive optical element which is used to project structured light of spot array, characterized in that the method comprises the following steps: calculating diffraction angles ( θ xi, θ yi) of individual target spots A; of a target spot array in X direction and Y direction based on coordinates ( x i, y i) of the target spots A i of the target spot array in X direction and Y direction and a distance a between the diffractive optical element and a target plane, where i is an integer, θ xi = arctan x i / y i 2 + a 2, and θ yi = arctan y i / x i 2 + a 2; selecting initially a period d j of the diffractive optical element, wherein the period is determined by a product of a pixel size and a number of pixels, and the number of pixels is a positive integer; calculating diffraction orders ( m i, n i) of the individual target spots A; in X direction and Y direction, wherein m i =sinθ xi / sinΔθ, n i = sinθ yi / sinΔθ, sinΔθ=λ / d j, λ is a wavelength of a light source; rounding the diffraction orders ( m i, n i) to obtain rounded diffraction orders ( m i ', n i'); calculating coordinates ( x i ', y i ') of actual projection spots A i ' in X direction and Y direction by using the rounded diffraction orders ( m i ', n i '); calculating an evaluation indicator of period optimization based on the coordinates of individual target spots A; and those of their corresponding actual projection spots A i '; adjusting the period d j to d j+1, and repeating the above steps - to calculate the evaluation indicator of period optimization with the period d j+1; and determining an optimal period of the diffractive optical element according to the evaluation indicators of period optimization, wherein the evaluation indicator of period optimization is: a distance mean between the individual target spots A i and their corresponding actual projection spots A i ', or a maximum distance between the individual target spots A i and their corresponding actual projection spots A i ', or a sum of distances between individual target spots A; and their corresponding actual projection spots A i ', or a maximum absolute difference of abscissas and/or ordinates between individual target spots A; and their corresponding actual projection spots A i '. calculating diffraction angles ( θ xi, θ yi) of individual target spots A; of a target spot array in X direction and Y direction based on coordinates ( x i, y i) of the target spots A i of the target spot array in X direction and Y direction and a distance a between the diffractive optical element and a target plane, where i is an integer, θ xi = arctan x i / y i 2 + a 2, and θ yi = arctan y i / x i 2 + a 2; selecting initially a period d j of the diffractive optical element, wherein the period is determined by a product of a pixel size and a number of pixels, and the number of pixels is a positive integer; calculating diffraction orders ( m i, n i) of the individual target spots A; in X direction and Y direction, wherein m i =sinθ xi / sinΔθ, n i = sinθ yi / sinΔθ, sinΔθ=λ / d j, λ is a wavelength of a light source; rounding the diffraction orders ( m i, n i) to obtain rounded diffraction orders ( m i ', n i'); calculating coordinates ( x i ', y i ') of actual projection spots A i ' in X direction and Y direction by using the rounded diffraction orders ( m i ', n i '); calculating an evaluation indicator of period optimization based on the coordinates of individual target spots A; and those of their corresponding actual projection spots A i '; adjusting the period d j to d j+1, and repeating the above steps - to calculate the evaluation indicator of period optimization with the period d j+1; and determining an optimal period of the diffractive optical element according to the evaluation indicators of period optimization,