Spatial Straight-Line Drawing Algorithm Based on Method of Discriminate Regions—A Control Algorithm of Motors

: A novelty algorithm of spatial straight-line drawing based on a method of discriminate regions is proposed in this paper based on Bresenham’s algorithm. Three-dimensional space is divided into innumerable three-dimensional meshes according to the given rule; the distance between the start and the end points of the three coordinates is ∆ x , ∆ y , and ∆ z , respectively; the distribution types of spatial straight line and the position of the end point are determined by judging the relationship among ∆ x , ∆ y , and ∆ z ; then, the active-passive directions can be determined. The plane of the ending point of the straight line in a three-dimensional mesh is divided into four regions; then, the discriminant is obtained; and this discriminant determine which region the point is located in The algorithm is verified and analyzed by the method of contrastive analysis; the results show that: the error of the algorithm is related to the step length L; the maximum theoretical error is 0.7071*L. The discriminants are all integers, so the problem of deviation from the theoretical straight line caused by the retention of decimals of signiﬁcant digits can be avoided. Finally, the algorithm is applied to the cooperative control of multiple motors, and conversion between unit grid number and pulse number of motors is performed.


Introduction
Straight line drawing is among the important fields of various industries, such as straight-line interpolation [1], stepper motor cooperative control [2], 3D printing [3], 3D model building [4], and image drawing [5]. To quickly draw straight lines, the speed of the applied algorithm is critical. The Bresenham's algorithm [6,7], DDA algorithm [8][9][10], and midpoint algorithm [11][12][13] are two-dimensional straight-line generation algorithms. Among which, the most famous is the Bresenham's algorithm, which is introduced during the 1960s. The advantage of Bresenham's algorithm is that all the operations are integers, without division or decimals. This approach is efficient at selecting a set of grid points to represent a straight line in a two-dimensional space. Space symmetry and simplifying computation are two major aspects of the algorithm towards high efficiency [14].
Stephenson et al. [15] present a line drawing algorithm based on runs of runs and discussed a number of special cases in the structure of runs and runs; it is proved that the algorithm can also be applied to short straight lines; this algorithm is formed to draw the line that has an identical iterative structure to Bresenham's algorithm, except that at each iteration, it is not a pixel that is set but a run of runs; thus, the speed of line drawing is improved. Li et al. [16] proposed a fast line drawing algorithm using circular subtraction based on Bresenham's algorithm. This algorithm makes use of the corresponding relationship between the two ends of the line and its symmetry to quickly draw multiple pixels, which enhances the speed of drawing straight lines. Liu et al. [1] extended Bresenham's algorithm to a spatial straight line; the straight line is decomposed into the motion of two planes, which realize a three-dimensional Bresenham's algorithm; the actual errors of the algorithm at each sampling point are less than the maximum theoretical error; however, because of the discriminant containing decimals, the actual line may deviate from the theoretical straight line due to the problem of retaining decimal digits. Dai et al. [2] also extended Bresenham's algorithm from two dimensions to three, and applied it to multidimensional stepper motor cooperative control. Although the control accuracy requirements can be met by this algorithm, it is triggered by the interruption of the timer during motion, which leads to a noncontinuous algorithm.
To solve the above problems, a spatial straight line drawing algorithm based on the method of discriminate regions is proposed in this paper. Our innovation is that the discriminant in our algorithm is the integer; only the coordinates of the starting and end point of the spatial straight line are needed to be input in this algorithm; then, the distribution of spatial straight lines in three-dimensional space and the location of the end point can be quickly determined, and then the corresponding discriminant is obtained and the selection points of lines in each three-dimensional mesh are determined. Finally, the selected points are connected to complete the spatial space line drawing. This method can avoid the decimal in the discriminant completely, so all the operations are integers in the algorithm of this paper; therefore, the problem of deviation from the theoretical straight line caused by the retention of decimals of significant digits will be avoided. This algorithm is applied to the cooperative control of the stepping motor. A proportional integral differential (PID) control algorithm is often used for the control of a single motor and the parameters need to be tuned [17]. This paper mainly explains the process of multistep motor cooperative control.

Space Line Drawing Algorithm
In this paper, Bresenham's algorithm is extended from a two-dimensional plane to a three-dimensional space. Meantime, in order to avoid the problem of deviation between the actual straight line and the theoretical straight line caused by the decimals of the discriminant, a method of discriminate regions is designed, and the discriminant is improved.

Analysis of the Two-Dimensional Straight Line of Bresenham's Algorithm
A recursive step method is used in Bresenham's algorithm [18]. The axis with the largest change is taken as the active direction and it progresses one grid at a time; the other direction is taken as the passive direction, along which whether to progress one grid is decided according to the sign of the discriminant, as shown in Figure 1.
Energies 2020, 13, x FOR PEER REVIEW 2 of 16 the corresponding relationship between the two ends of the line and its symmetry to quickly draw multiple pixels, which enhances the speed of drawing straight lines. Liu et al. [1] extended Bresenham's algorithm to a spatial straight line; the straight line is decomposed into the motion of two planes, which realize a three-dimensional Bresenham's algorithm; the actual errors of the algorithm at each sampling point are less than the maximum theoretical error; however, because of the discriminant containing decimals, the actual line may deviate from the theoretical straight line due to the problem of retaining decimal digits. Dai et al. [2] also extended Bresenham's algorithm from two dimensions to three, and applied it to multidimensional stepper motor cooperative control. Although the control accuracy requirements can be met by this algorithm, it is triggered by the interruption of the timer during motion, which leads to a noncontinuous algorithm. To solve the above problems, a spatial straight line drawing algorithm based on the method of discriminate regions is proposed in this paper. Our innovation is that the discriminant in our algorithm is the integer; only the coordinates of the starting and end point of the spatial straight line are needed to be input in this algorithm; then, the distribution of spatial straight lines in threedimensional space and the location of the end point can be quickly determined, and then the corresponding discriminant is obtained and the selection points of lines in each three-dimensional mesh are determined. Finally, the selected points are connected to complete the spatial space line drawing. This method can avoid the decimal in the discriminant completely, so all the operations are integers in the algorithm of this paper; therefore, the problem of deviation from the theoretical straight line caused by the retention of decimals of significant digits will be avoided. This algorithm is applied to the cooperative control of the stepping motor. A proportional integral differential (PID) control algorithm is often used for the control of a single motor and the parameters need to be tuned [17]. This paper mainly explains the process of multistep motor cooperative control.

Space Line Drawing Algorithm
In this paper, Bresenham's algorithm is extended from a two-dimensional plane to a threedimensional space. Meantime, in order to avoid the problem of deviation between the actual straight line and the theoretical straight line caused by the decimals of the discriminant, a method of discriminate regions is designed, and the discriminant is improved.

Analysis of the Two-Dimensional Straight Line of Bresenham's Algorithm
A recursive step method is used in Bresenham's algorithm [18]. The axis with the largest change is taken as the active direction and it progresses one grid at a time; the other direction is taken as the passive direction, along which whether to progress one grid is decided according to the sign of the discriminant, as shown in Figure 1.

Analysis of the Spatial Straight Line
From the starting to the ending points of the spatial straight line, the displacement of the three axes are generally different, but each axis will reach the corresponding end coordinates at the same time. The axis with the greatest distance from the beginning to the end of the straight line is the active direction and progresses a unit at a time; the other two axes are the passive directions and only progress at specific times to maintain their relative slopes (stop). The drawing speed and the precision of the straight line are directly determined by where and how long they will stop [19]. Therefore, the following spatial straight-line drawing algorithm is designed.
The starting point of spatial straight line is set as p s (x s , y s , z s ), and the end point is p e (x e , y e , z e ), where ∆x = x e − x s , ∆y = y e − y s , and ∆z = z e − z s . Therefore, the equation for the spatial straight line is: x As three-dimensional space has intrinsic symmetry [11], only the following types for spatial straight lines in which x, y, and z are all positive directions are discussed. Assume three-dimensional space consists of innumerable three-dimensional meshes; the side length of each grid is one pixel or one step angle. In this paper, three-dimensional space is regarded as a cube, and the six surfaces of the cube are, respectively, called: front surface, back surface, left surface, right surface, upper surface, and lower surface; each three-dimensional mesh is called a unit grid, the side length of unit grid is called a unit, and its length is L, in Figure 2.

Analysis of the Spatial Straight Line
From the starting to the ending points of the spatial straight line, the displacement of the three axes are generally different, but each axis will reach the corresponding end coordinates at the same time. The axis with the greatest distance from the beginning to the end of the straight line is the active direction and progresses a unit at a time; the other two axes are the passive directions and only progress at specific times to maintain their relative slopes (stop). The drawing speed and the precision of the straight line are directly determined by where and how long they will stop [19]. Therefore, the following spatial straight-line drawing algorithm is designed.
The starting point of spatial straight line is set as ( , , ), and the end point is ( , , ), where = − , = − , and = − . Therefore, the equation for the spatial straight line is: As three-dimensional space has intrinsic symmetry [11], only the following types for spatial straight lines in which , , and are all positive directions are discussed. Assume three-dimensional space consists of innumerable three-dimensional meshes; the side length of each grid is one pixel or one step angle. In this paper, three-dimensional space is regarded as a cube, and the six surfaces of the cube are, respectively, called: front surface, back surface, left surface, right surface, upper surface, and lower surface; each three-dimensional mesh is called a unit grid, the side length of unit grid is called a unit, and its length is L, in Figure 2.    (1) If ∆x > ∆y ≥ 0, ∆x > ∆z ≥ 0, the straight line is type 1 , as shown in Figure 2a, and the end point is on the right surface of the cube; this type of straight line corresponds to algorithm 1; x is taken as the active direction and it progresses one grid at a time; y and z are taken as passive directions, along which whether to progress one grid is decided according to the sign of the discriminant; (2) If ∆x = ∆y = ∆z ≥ 0, the straight line is type 2 , as shown in Figure 2a, and the end point is on the vertex opposite to the origin; this type of straight line corresponds to algorithm 2; x, y, and z are taken as the active direction, and progress one grid at a time; (3) If ∆y > ∆x ≥ 0, ∆y > ∆z ≥ 0, the straight line is type 3 , as shown in Figure 2a, and the end point is on the upper surface of the cube; this type of straight line corresponds to algorithm 3; y is taken as the active direction and it progresses one grid at a time, x and z are taken as passive directions, along which whether to progress one grid is decided according to the sign of the discriminant; (4) If ∆z > ∆x ≥ 0, ∆z > ∆y ≥ 0, the straight line is type 4 , as shown in Figure 2a, and the end point is on the front surface of the cube; this type of straight line corresponds to algorithm 4; z is taken as the active direction and it progresses one grid at a time, x and y are taken as passive directions, along which whether to progress one grid is decided according to the sign of the discriminant; (5) If ∆x = ∆y > ∆z ≥ 0, the straight line is type 5 , as shown in Figure 2a, the end point is on the intersection line of the upper surface and the right surface of the cube; This type of straight line corresponds to algorithm 5; x and y are taken as the active direction, and they are progress one grid at a time, z is taken as the passive direction along which whether to progress one grid is decided according to the sign of the discriminant; (6) If ∆y = ∆z > ∆x ≥ 0, the straight line is type 6 , as shown in Figure 2a, and the end point is on the intersection line of the upper surface and the front surface of the cube; this type of straight line corresponds to algorithm 6, y and z are taken as the active directions, and they progress one grid at a time; x is taken as the passive direction, along which whether to progress one grid is decided according to the sign of the discriminant; (7) If ∆x = ∆z > ∆y ≥ 0, the straight line is type 7 , as shown in Figure 2a, and the end point is on the intersection line of the front surface and the right surface of the cube; this type of straight line corresponds to algorithm 7; x and z are taken as the active directions, and they progress one grid at a time; y is taken as the passive direction, along which whether to progress one grid is decided according to the sign of the discriminant.
Seven types of straight lines correspond to seven algorithms. By judging the relationship of ∆x, ∆y, and ∆z, the position of the end of the straight line is determined, so as to determine the corresponding algorithm. The flow chart of this algorithm is shown in Figure 3. directions, along which whether to progress one grid is decided according to the sign of the discriminant; (4) If > ≥ 0, > ≥ 0, the straight line is type ④, as shown in Figure 2a, and the end point is on the front surface of the cube; this type of straight line corresponds to algorithm 4; z is taken as the active direction and it progresses one grid at a time, x and y are taken as passive directions, along which whether to progress one grid is decided according to the sign of the discriminant; (5) If = > ≥ 0, the straight line is type ⑤, as shown in Figure 2a, the end point is on the intersection line of the upper surface and the right surface of the cube; This type of straight line corresponds to algorithm 5; x and are taken as the active direction, and they are progress one grid at a time, z is taken as the passive direction along which whether to progress one grid is decided according to the sign of the discriminant; (6) If = > ≥ 0, the straight line is type ⑥, as shown in Figure 2a, and the end point is on the intersection line of the upper surface and the front surface of the cube; this type of straight line corresponds to algorithm 6, y and are taken as the active directions, and they progress one grid at a time; x is taken as the passive direction, along which whether to progress one grid is decided according to the sign of the discriminant; (7) If = > ≥ 0, the straight line is type ⑦, as shown in Figure 2a, and the end point is on the intersection line of the front surface and the right surface of the cube; this type of straight line corresponds to algorithm 7; x and are taken as the active directions, and they progress one grid at a time; y is taken as the passive direction, along which whether to progress one grid is decided according to the sign of the discriminant.
Seven types of straight lines correspond to seven algorithms. By judging the relationship of , , and , the position of the end of the straight line is determined, so as to determine the corresponding algorithm. The flow chart of this algorithm is shown in Figure 3.

Method of Discriminate Regions
The basic principle of all the above algorithms is the same, except for the variable (Δ , Δ , and Δ ). The corresponding algorithm is determined by judging the relationship among Δ , Δ , and Δ .
As an example, this algorithm 1 is designed and discussed in this paper; and the method of discriminate regions is proposed.
Three-dimensional space is divided into innumerable three-dimensional meshes; one of the unit grid is taken, as shown in Figure 4a.

Method of Discriminate Regions
The basic principle of all the above algorithms is the same, except for the variable (∆x, ∆y, and ∆z). The corresponding algorithm is determined by judging the relationship among ∆x, ∆y, and ∆z. As an example, this algorithm 1 is designed and discussed in this paper; and the method of discriminate regions is proposed.
Three-dimensional space is divided into innumerable three-dimensional meshes; one of the unit grid is taken, as shown in Figure 4a. For case ①, the end point of the straight line is on the right surface of the cube, so the end point of all the straight lines in the unit grid is also on the right surface of the unit grid. Figure 4a shows a straight line in a unit grid, and the coordinate system here is the local coordinate system of each unit grid. Where p is the selection point of point , the origin of the ( + 1) unit grid, and the starting point of the straight line in the ( + 1) unit grid. p is the intersection of the theoretical straight line and the upper right surface of the unit grid; because the selection point of p is an integer point, as shown in Figure 4a, the selection point of p can only be one of A, B, C, D. Each time a point is selected, it will serve as the origin of the local coordinate system of the next unit grid and the starting point of the line in the next unit grid, where ( = 0, 1, 2 … n). The right surface of the unit grid is divided into four regions (a, b, c, and d) by four lines (e, f, g and h); the corresponding selection points of each region are A, B, C, and D, respectively, as shown in Figure 4b. According to the discriminant, the location of point p in the region is determined, and the selection point is chosen. The coordinates of the four points (A, B, C, and D) are, respectively, A( + 1, + 1, ), B( + 1, , ), C( + 1, , + 1), and D( + 1, + 1, + 1) ,where d is the distance between the actual y coordinate of point p and y , d is the distance between the actual coordinate of point , and ( + 1), is the distance between the actual coordinate of point and , and is the distance between the actual z coordinate of point and ( + 1). The y and z coordinates are determined using Equation (1), as follows: Then, the discriminant is obtained as: For case 1 , the end point of the straight line is on the right surface of the cube, so the end point of all the straight lines in the unit grid is also on the right surface of the unit grid. Figure 4a shows a straight line in a unit grid, and the coordinate system here is the local coordinate system of each unit grid. Where p i is the selection point of point i, the origin of the (i + 1) unit grid, and the starting point of the straight line in the (i + 1) unit grid. p i+1 is the intersection of the theoretical straight line and the upper right surface of the unit grid; because the selection point of p i+1 is an integer point, as shown in Figure 4a, the selection point of p i+1 can only be one of A, B, C, D. Each time a point is selected, it will serve as the origin of the local coordinate system of the next unit grid and the starting point of the line in the next unit grid, where (i = 0, 1, 2 . . . n). The right surface of the unit grid is divided into four regions (a, b, c, and d) by four lines (e, f, g and h); the corresponding selection points of each region are A, B, C, and D, respectively, as shown in Figure 4b. According to the discriminant, the location of point p i+1 in the region is determined, and the selection point is chosen. The coordinates of the four points (A, B, C, and D) are, respectively, A(x i + 1, y i + 1, z i ), B(x i + 1, y i , z i ), C(x i + 1, y i , z i + 1), and D(x i + 1, y i + 1, z i + 1),where d y1 is the distance between the actual y coordinate of point p i+1 and y i , d y2 is the distance between the actual y coordinate of point p i+1, and (y i + 1), d z1 is the distance between the actual z coordinate of point p i+1 and z i , and d z2 is the distance between the actual z coordinate of point p i+1 and (z i + 1). The y and z coordinates are determined using Equation (1), as follows: Then, the discriminant is obtained as: Energies 2020, 13, 5002 6 of 16

Improved Discriminant
To simplify the discriminant in Equation (5), d y and d z being all multiplied by ∆x; then, an improved discriminant is proposed: because ∆x > 0, M i and d y have the same sign, and N i and d z have the same sign. Therefore, we can decide which point to choose next from the signs of M i and N i . From Equation (6), the discriminant at i = i + 1 is: Then, the recursive equations are obtained as: As the starting point of the spatial straight line is p s (x s , y s , z s ), it is obtained that: Considering Equation (6), the initial value of the discriminant is obtained as:

The Process of Discriminate Region
Considering the positive and negative signs of the above discriminants M i and N i , which region the point p i+1 is in can be determined, and then which point of A, B, C, and D will be selected.
(1) If M i > 0 and N i < 0, the point p i+1 is in region a; the point A will be selected at this point.
(2) If M i < 0 and N i < 0, the point p i+1 is in region b; the point B will be selected at this point. Therefore, only the signs of M i and N i are needed to judge to determine the next selection point. Assuming that n steps are required from the starting point to ending point of the spatial straight line, the judging algorithm flow chart is given in Figure 5.

Algorithm Verification Based On Matlab
For the purpose of verification of the algorithm in this paper, it is assumed that the starting point of the spatial straight line is (0, 0, 0), 300 integers of 0-100 are randomly generated in MATLAB, and three numbers of them are a group of coordinates as the end point of a straight line; There are totally 100 groups, and one group of them is taken as an example, such as (8, 6, 5); therefore, Δ = 8, Δ = 6, and Δ = 5.
From Equation (10), the initial value of the discriminants are = 4 and for N = 2. The above algorithm is used to draw the spatial straight lines, as shown in Figure 6.

Algorithm Verification Based on Matlab
For the purpose of verification of the algorithm in this paper, it is assumed that the starting point of the spatial straight line is p s (0, 0, 0), 300 integers of 0-100 are randomly generated in MATLAB, and three numbers of them are a group of coordinates as the end point of a straight line; There are totally 100 groups, and one group of them is taken as an example, such as p e (8, 6, 5); therefore, ∆x = 8, ∆y = 6, and ∆z = 5.
From Equation (10), the initial value of the discriminants are M 1 = 4 and for N 1 = 2. The above algorithm is used to draw the spatial straight lines, as shown in Figure 6.
In this case study, the end point coordinate for the x-axis is eight, which required eight steps forward. Thus, the x-axis progressed one unit at a time, and the actual x-axis value coincided with the theoretical value. The end points for the y and z-axis are six and five, respectively. Therefore, there are two steps without progression along the y-axis, and there are three along the z-axis. In Figure 6a, δ i is the error of each step, and n steps needed totally for the straight-line, then: Energies 2020, 13, 5002 8 of 16 and three numbers of them are a group of coordinates as the end point of a straight line; There are totally 100 groups, and one group of them is taken as an example, such as (8, 6, 5); therefore, Δ = 8, Δ = 6, and Δ = 5.
From Equation (10), the initial value of the discriminants are = 4 and for N = 2. The above algorithm is used to draw the spatial straight lines, as shown in Figure 6. In Figure 6b, the black dashed line is the actual generated spatial straight line, and the red dashed line is the theoretical Spatial straight line. The cylinder is the minimum inclusive region of the spatial straight-line straightness error [20], which is parallel to the theoretical straight line. All parts of the spatial straight line drawn by the algorithm are in the cylinder, whose diameter is the maximum error of the spatial straight line [21,22], and δ = max(δ i ), all the results are shown in Figure 7.  Figure 6a shows the motion process for each axis. The ordinate is the number of units, and the abscissa is the number of forward steps. The black, red, and blue lines represent the , , and -axis. The solid line is the theoretical value, while the dashed line is the actual value.
In this case study, the end point coordinate for the -axis is eight, which required eight steps forward. Thus, the -axis progressed one unit at a time, and the actual x-axis value coincided with the theoretical value. The end points for the and -axis are six and five, respectively. Therefore, there are two steps without progression along the -axis, and there are three along the -axis. In Figure 6a, δ is the error of each step, and n steps needed totally for the straight-line, then: In Figure 6b, the black dashed line is the actual generated spatial straight line, and the red dashed line is the theoretical Spatial straight line. The cylinder is the minimum inclusive region of the spatial straight-line straightness error [20], which is parallel to the theoretical straight line. All parts of the spatial straight line drawn by the algorithm are in the cylinder, whose diameter is the maximum error of the spatial straight line [21,22], and = ( ), all the results are shown in Figure 7.  Energies 2020, 13, 5002 9 of 16 Figure 7a-c, respectively, show the largest change of x-axis, y-axis, and z-axis in 100 groups of data and the local enlarged drawing, and B is the enlarged figure of A, where the black line is the x-axis, red line is the y-axis, and blue line is the z-axis.

Error Analysis
When the point p i+1 is at the center O of the right surface of the unit grid, the distance from p i+1 to any point of A, B, C, and D is the same (δ t ), which is called the maximum theoretical error of the spatial straight line, as shown in Figure 8.

Error Analysis
When the point is at the center O of the right surface of the unit grid, the distance from to any point of A, B, C, and D is the same ( ), which is called the maximum theoretical error of the spatial straight line, as shown in Figure 8. According to Figure 8, the maximum theoretical error = 0.7071 * . Where L is the side length of the unit grid, that is, the step length of each step of each axis-for example, in general industrial machine tools-L represents the moving distance of the actuator driven by a pulse of stepping motor. The step angle of the stepping motor is θ, subdivided is s; the pulse number of one turn of the stepping motor is ; and the screw pitch is p, then: The stepper motor receives one pulse, and the lead screw movement distance L is = (13) If = 1.8°, = 2, = 2 mm, obtain: L = 5 * 10 mm, and the maximum theoretical error = 3.54 * 10 mm. It can be seen that the value of L is related to the parameters of the stepping motor and the actuator, and the error distribution of each straight line is as shown in Figure 9. According to Figure 8, the maximum theoretical error δ t = 0.7071 * L. Where L is the side length of the unit grid, that is, the step length of each step of each axis-for example, in general industrial machine tools-L represents the moving distance of the actuator driven by a pulse of stepping motor. The step angle of the stepping motor is θ, subdivided is s; the pulse number of one turn of the stepping motor is p m ; and the screw pitch is p, then: The stepper motor receives one pulse, and the lead screw movement distance L is If θ = 1.8 • , s = 2, P = 2 mm, obtain: L = 5 * 10 −3 mm, and the maximum theoretical error δ t = 3.54 * 10 −3 mm. It can be seen that the value of L is related to the parameters of the stepping motor and the actuator, and the error distribution of each straight line is as shown in Figure 9.
If = 1.8°, = 2, = 2 mm, obtain: L = 5 * 10 mm, and the maximum theoretical error = 3.54 * 10 mm. It can be seen that the value of L is related to the parameters of the stepping motor and the actuator, and the error distribution of each straight line is as shown in Figure 9. From the above results, all errors are less than or equal to the maximum theoretical error of 0.7071. In addition, according to the algorithm provided by Liu [1], a random function in MATLAB to set several sets of samples including origin and target points is used. Then, Liu's algorithm and our algorithm are all programmed in MATLAB to generate a straight line with the above-mentioned randomly generated origin and end points. In this way, the ideal line is drawn, and the actual line generated by these two different algorithms are obtained, respectively. Finally, the ideal curve and the actual curve generated by the two algorithms are drawn in one graph, as shown in Figure 10 (green and blue lines represent the results of retaining four and one decimal places, respectively, and the detailed explanation of Figure 10a is in the sixth paragraph of the fourth section). randomly generated origin and end points. In this way, the ideal line is drawn, and the actual line generated by these two different algorithms are obtained, respectively. Finally, the ideal curve and the actual curve generated by the two algorithms are drawn in one graph, as shown in Figure 10 (green and blue lines represent the results of retaining four and one decimal places, respectively, and the detailed explanation of Figure 10a is in the sixth paragraph of the fourth section). A specific example is now given to explain the difference. As Liu's paper shows: given that the two end-points of a straight-line segment are specified at positions (0, 0, 0) and (10,7,6), it follows that kyx = 0.7, and kzx = 0.6, then From the above two equations, it is possible to calculate the generated pixels and the decision parameters at each inter x position, starting from 0, 0, 0, as listed in Table 1. The error listed in the last A specific example is now given to explain the difference. As Liu's paper shows: given that the two end-points of a straight-line segment are specified at positions (0, 0, 0) and (10,7,6), it follows that k yx = 0.7, and k zx = 0.6, then From the above two equations, it is possible to calculate the generated pixels and the decision parameters at each inter x position, starting from 0, 0, 0, as listed in Table 1. The error listed in the last column of the table is the distance between the generated pixel and the given line path at each inter x position.  Bringing this case into the algorithm in this article can obtain the data in Table 2. In addition, the difference between the seventh and ninth steps of the two methods can be clearly seen below in Tables 1 and 2, and Figure 11. When step 9 is performed, the error is different, which can be seen from Tables 1 and 2, respectively, and the error is sightly less than that in the literature. Bringing this case into the algorithm in this article can obtain the data in Table 2.  In addition, the difference between the seventh and ninth steps of the two methods can be clearly below in Table 1, Table 2, and Figure 11. When step 9 is performed, the error is different, which be seen from Table 1 and Table 2, respectively, and the error is sightly less than that in the ature.

Conversion of Unit Grid Number and Pulse Number
Step motor is an open-loop control motor which transforms electric pulse signal into ang displacement or linear displacement [23]. When a pulse is received, it will drive the step moto rotate a fixed angle (step angle θ) according to the set direction. The algorithm in this paper ca used for controlling three stepping motors cooperatively. In the research of Dulf [24,25] et al., a method for designing a fractional-order controller and a method for designing a DC motor sp control fractional-order PI controller are proposed, and the method is proved through an exam analysis. The feasibility and superiority of the fractional-order controller can greatly reduce overshoot and make its performance better than the traditional Kessler controller. Through spe experiments, its performance is evaluated and compared to other types of implementa possibilities. Three stepper motors control the -axis, -axis, and -axis, respectively; the th dimensional space described in the algorithm is the working space of three stepping motors; and unit is a pulse. Δx, Δy, and Δz are the number of pulses required to reach the target point for t motor, motor, and motor, respectively. The number of forward steps mentioned in this pap the number of pulses required for the axis with the largest moving distance.
In industrial machine tools, the three coordinate axes are all driven by lead screw, and the screw pitch is mm. Three axes are set to move mm, mm, mm, respectively; then, the motor turns a circle while lead screw moves mm(one pitch), and three motors rotate circ circle, and circle, respectively, to reach the target point. The step angle of all three stepper mo is 1.8°, and the subdivision is 8. According to Equation (12), 1600 pulses are needed for one tur the stepper motor. The number of pulses of the three stepper motors for reaching the target poin

Conversion of Unit Grid Number and Pulse Number
Step motor is an open-loop control motor which transforms electric pulse signal into angular displacement or linear displacement [23]. When a pulse is received, it will drive the step motor to rotate a fixed angle (step angle θ) according to the set direction. The algorithm in this paper can be used for controlling three stepping motors cooperatively. In the research of Dulf [24,25] et al., a new method for designing a fractional-order controller and a method for designing a DC motor speed control fractional-order PI controller are proposed, and the method is proved through an example analysis. The feasibility and superiority of the fractional-order controller can greatly reduce the overshoot and make its performance better than the traditional Kessler controller. Through specific experiments, its performance is evaluated and compared to other types of implementation possibilities. Three stepper motors control the x-axis, y-axis, and z-axis, respectively; the three-dimensional space described in the algorithm is the working space of three stepping motors; and the unit is a pulse. ∆x, ∆y, and ∆z are the number of pulses required to reach the target point for the x motor, y motor, and z motor, respectively. The number of forward steps mentioned in this paper is the number of pulses required for the axis with the largest moving distance. In industrial machine tools, the three coordinate axes are all driven by lead screw, and the lead screw pitch is P mm. Three axes are set to move x mm, y mm, z mm, respectively; then, the step motor turns a circle while lead screw moves P mm(one pitch), and three motors rotate x P circle, y P circle, and z P circle, respectively, to reach the target point. The step angle θ of all three stepper motors is 1.8 • , and the subdivision s is 8. According to Equation (12), 1600 pulses are needed for one turn of the stepper motor. The number of pulses of the three stepper motors for reaching the target point are (1600 × x P ), (1600 × y P ), (1600 × z P ), respectively.

Algorithm Extension
The algorithm in this paper can be extended to five dimensions; assuming that the other two axes are A and B, respectively, the corresponding discriminant is H and K, respectively. According to Equation (8), the H and K are obtained: Considering Equation (10), the initial value of the discriminant H and K are obtained as: According to the above rules, when H i+1 > 0, A i+1 = A i + 1, and when K i+1 > 0, B i+1 = B i + 1. Therefore, the algorithm in this paper can be extended to five or more dimensions, which means that more motors can be controlled cooperatively by this algorithm in this paper.

Matlab Simulation Discussion
The type 1 is discussed as one example of the algorithm in this paper; that is, the end point of the straight line is on the right surface of the cube, and algorithm 1 is designed. The x axis is taken as the active direction, and progresses one unit at a time; y and z are taken as the passive direction; by judging the sign of discriminant M i and N i , which regions of the right surface of the unit grid the point is located in will be determined, and then whether or not to progress one unit will be determined. There are seven types of spatial line distribution; for the other six types, the end position of the straight line is different, and the variables (∆x, ∆y, and ∆z) are different, but the algorithm structure is the same: only the corresponding variables need to be exchanged. In addition, in this paper, the ∆x, ∆y, and ∆z in the discriminant of the algorithm possess a proportion relation. For example, if ∆x = 8000, ∆y = 6000, and ∆z = 5000, the corresponding step size of 8000, and there is the greatest common factor (C f ), that is 1000, then ∆x * = ∆x C f = 8, ∆y * = ∆y C f = 6, and ∆z * = ∆z C f = 5; the ∆x * , ∆y * , and ∆z * are taken as variables of discriminants; moreover, the discriminants are all integers. Therefore, the proposed algorithm could be simplified to calculate for drawing spatial straight lines. The 100 groups of data are randomly generated by MATLAB, and the algorithm is verified in this paper. It is proved that the algorithm is suitable for straight lines in any direction.
According to the algorithm verification results in Section 3, several sets of data generated by MATLAB are brought into the three-dimensional algorithm of Liu [1], and the results are shown in Figure 12.
groups of data are randomly generated by MATLAB, and the algorithm is verified in this paper. It is proved that the algorithm is suitable for straight lines in any direction.
According to the algorithm verification results in Section 3, several sets of data generated by MATLAB are brought into the three-dimensional algorithm of Liu [1], and the results are shown in Figure 12. It can be seen from the results of the comparison algorithm that this algorithm produced the same results as the algorithm in this paper; meanwhile, the same case is brought into Dai [2], in which also the same results occurred. It is noted that the selection points for the y and z-axis in the comparison algorithm are judged separately in the XY and XZ planes. In addition, the discriminant contains decimals in the reference algorithm; however, there are not the above two phenomena in the algorithm of this paper.
Because of the retention number of significant digits and the gradual accumulation of the discriminant the positive and negative signs of the discriminant may be changed, the selective point also may be altered. Furthermore, there is a greater deviation of the drawn straight line from the theoretical straight line, which increases the straightness error. In order to verify the possibility of the above problems, the discriminant of different decimal places (four, three, two, and one decimals) is calculated by the comparison algorithm, after testing; when the discriminant retains one decimal, the straight line will deviate from its ideal straight line, as shown in Figure 10a.
In the Figure 10a, B is enlarged pictures of A; the black and red lines represent the x and y-axis, respectively; green and blue lines represent the results of retaining four and one decimal places, respectively. It can be seen in the figure that the z-axis deviates from the theoretical straight line with the reserved one decimal place: at this time, the straightness error δ is greater than the maximum theoretical error of 0.7071. The z-axis oscillates on the theoretical straight line with the reserved four decimal places.
Additionally, the following conclusions have been reached through multiple verifications; the Liu [1] algorithm will not deviate from the theoretical line when more than two decimals are reserved, and may deviate from the theoretical line when one decimal is reserved.
In this paper, according to a given rule (such as a pixel or a step angle), three-dimensional space is divided into innumerable three-dimensional meshes, namely unit grids. The right surface of each unit grid is divided into four regions, and two discriminants are determined at the same time to determine the selection point. One point is selected each time: this point would be the origin of the coordinate system of the next unit grid, and also the starting point of the straight line in this unit grid. The discriminants of the algorithm in this paper are all integers; that the problem of deviation from the theoretical straight line caused by the retention of decimals of significant digits can be avoided. Some other literatures also proposed some new algorithms or related error analysis: they verify the effectiveness and advantages of the algorithm through comparison and analysis with other related literatures [26,27]. In this article, the effectiveness and advantages of our algorithm are shown through MATLAB simulation, comparison, and analysis with other related literature. There are still some shortcomings in this algorithm. A large number of samples are needed for comparative analysis to verify whether the computational efficiency of this algorithm is improved; at present, this algorithm is only suitable for the space straight line, and not for the space curve.

Conclusions
First, the Bresenham's algorithm is extended to three-dimensional space in this paper. Bresenham algorithm is two-dimensional. To draw three-dimensional space straight lines, a novelty method of discriminate regions is proposed in this paper. Based on the discriminant, the selection points for each step will be provided. Only the coordinates of the starting and ending points of the spatial straight line are needed to be input in this algorithm, and the discriminants of the region can be quickly determined. All the discriminants are integers, making the calculations simple to quickly draw the spatial straight line; and the problem of deviation from the theoretical straight line caused by the retention of decimals of significant digits can be avoided. By analyzing the error of the straight line, the result shows that the error of the algorithm is related to the step length L. The maximum theoretical error is √ 2