Introduction

In CNC surface machining, the sectioning method is widely adopted for generating machining trajectories by intersecting a series of planes with the target surface1. Rapid computation of intersection curves is critical for this process. While algebraic methods yield exact solutions for analytically defined surfaces, parametric surfaces such as NURBS (Non-Uniform Rational B-Splines) pose significant challenges due to their inherent complexity. Traditional approaches, including tracing methods, bounding box techniques, and triangular mesh approximations2,3,4,5,6,7,8,9, often require extensive computational resources or fail to provide explicit NURBS descriptions of the intersection curves. In recent years, new progress has been made in the research of intersection algorithms. Recent advancements in intersection algorithms include adaptive step-size tracing2, subdivision surface intersection3, and point-cloud-based methods4. Researchers also studied the intersection of surfaces with unique shapes. Liu Xiaoming used a method based on a toroidal surface approximation to study the toroidal intersection algorithm10. Qian Fu et al. studied the intersection of ball B-spline curves and proposed an intersection method for ball B-spline curves11.

However, these techniques either rely on dense sampling of surface points or approximate representations, limiting their practicality in NURBS-based CNC systems. This paper proposes a bisection-based algorithm combined with reverse engineering to derive NURBS intersection curves, enhancing both computational efficiency and compatibility with downstream NURBS interpolation processes.

Intersection of a plane and a NURBS curve

NURBS curves are expressed in the form of parameters, and it is very challenging to solve the intersection issue analytically. In practice, approximate numerical methods are usually deployed to address this issue. The most widely used methods include the bisection method, tracing method, bounding box technique, etc. Furthermore, other algorithms are used to solve the intersection issue. Rao Daojuan et al. introduced the particle swarm optimization algorithm into the intersection of NURBS curves and proposed a NURBS curve intersection algorithm based on Particle Swarm Optimization (PSO)12. Delint Ira Setyo Adi et al. studied the NURBS fitting by using the particle swarm optimization algorithm, which provided a basis for the NURBS curve intersection with the particle swarm optimization algorithm13. Jingjing Shen et al. used the matrix representation method to study the intersection of straight lines and cropped NURBS surfaces14.

The above research methods are highly versatile and robust but very computation-consuming. However, in the scenario of CNC surface machining, the two ends of the tool path are usually located on both sides of the plane, and there is usually only one intersection point between the tool path curve and the plane. In this case, the bisection method is highly efficient and converges at the rate of 1/2. After 20 iterations, an accuracy of 10− 6 can be achieved. Here, the bisection method is used to solve the intersection of a curve and a plane.

A NURBS curve is defined as15:

$$\:\varvec{P}\left(u\right)=\frac{\sum\:_{i=0}^{n}{N}_{i,p}\left(u\right){{\mathbf{V}}_{i}W}_{i}}{\sum\:_{i=0}^{n}{N}_{i,p}\left(u\right){W}_{i}}$$
(1)

where \(\:{N}_{i,p}\left(u\right)\) is the B-spline basis function, \(\:{\varvec{V}}_{i}\) are the control points, \(\:{W}_{i}\) are the weights, \(\:u\) is the parameter, which is generally in the range of [0,1].

Assuming one end of the curve is \(\:\varvec{P}\left(0\right)\) and the other is \(\:\varvec{P}\left(1\right)\), and the curve and plane have only one intersection point, the bisection method can be used to approximate the intersection point.

For a plane defined by NX + D = 0, where A is the plane normal vector, X (x, y, z) is the position, and D is the intercept. The bisection method is applied to locate the intersection point when the curve spans both sides of the plane. The algorithm proceeds as follows:

figure a

The bisection method allows us to quickly locate the intersection point of the NURBS curve and the plane. Figure 1 is a schematic diagram of the intersection of a NURBS curve and a plane using the bisection method. For cases when the curve doesn’t span both sides of the plane, the piecewise bisection method, tracking method, or box bonding method can be used to solve the problem. However, as mentioned above, in the surface machining scenario, the two ends of the curve are usually located on both sides of the plane with only one intersection point. In most situations, the bisection method can be applied to find the intersection point directly.

Fig. 1
figure 1

Intersection of a NURBS curve with a plane.

Intersection of a plane with multiple NURBS curves

A NURBS surface is expressed as15

$$\:\varvec{s}\left(u,v\right)=\frac{\sum\:_{i=0}^{n}\sum\:_{j=0}^{m}{N}_{i,p}\left(u\right){N}_{j,q}{\left(v\right)W}_{i,j}{\mathbf{P}}_{i,j}}{\sum\:_{i=0}^{n}\sum\:_{j=0}^{m}{N}_{i,p}\left(u\right){N}_{j,q}{\left(v\right)W}_{i,j}}$$
(2)

where \(\:{N}_{i,p}\left(u\right)\) and \(\:{N}_{j,q}\left(v\right)\) are the B-spline basis functions of the surface parameters \(\:u\) and \(\:v\) respectively, \(\:{\varvec{P}}_{i,j}\) are the control points, \(\:{W}_{i,j}\) are the weights. The two knot vectors of the two parameters are

$$\varvec{U} = \left[ {\underbrace {{{\text{0,0}},{\text{0,0}}}}_{{p + 1}},u_{0} , \cdots \:,u_{{n - p - 1}} ,\underbrace {{{\text{1,1}},{\text{1,1}}}}_{{p + 1}}} \right]$$
$$\varvec{V} = \left[ {\underbrace {{{\text{0,0}},{\text{0,0}}}}_{{q + 1}},v_{0} , \cdots \:,v_{{m - q - 1}} ,\underbrace {{{\text{1,1}},{\text{1,1}}}}_{{q + 1}}} \right]$$

.

NURBS surfaces can be rewritten as

$$\:\varvec{s}\left(u,v\right)=\frac{\sum\:_{i=0}^{n}{N}_{i,p}\left(u\right)\sum\:_{j=0}^{m}{N}_{j,q}{\left(v\right)W}_{i,j}{\varvec{P}}_{i,j}}{\sum\:_{i=0}^{n}{N}_{i,p}\left(u\right)\sum\:_{j=0}^{m}{N}_{j,q}{\left(v\right)W}_{i,j}}$$
(3)

By fixing one parameter (e.g. \(\:v={v}_{k}\)), Eq. (3) can be rewritten as Eq. (4), which represents a NURBS curve.

$$\:\varvec{s}\left(u,{v}_{k}\right)=\frac{\sum\:_{i=0}^{n}{N}_{i,p}\left(u\right){\varvec{P}}_{{v}_{k}}}{\sum\:_{i=0}^{n}{N}_{i,p}\left(u\right){W}_{{v}_{k}}}$$
(4)

where

$$\:{\varvec{P}}_{{v}_{k}}=\sum\:_{j=0}^{m}{N}_{j,q}{\left({v}_{k}\right)W}_{i,j}{\varvec{P}}_{i,j}$$
$$\:{W}_{{v}_{k}}=\sum\:_{j=0}^{m}{N}_{j,q}{\left({v}_{k}\right)W}_{i,j}$$

.

By fixing the parameter \(\:v\) with a series of fixed values (here \(\:v={[0,v}_{0},\cdots\:,{v}_{m-q-1},1]\) as it is in the knot vector), a family of NURBS curves in the \(\:u\)-direction is generated. The bisection method is used to compute the intersection points of the plane and this family of curves, just as discussed in “Intersection of a plane and a NURBS curve”. Thus, \(\:m-q+2\) NURBS curves are intersecting with the plane, and \(\:m-q+2\) intersection points will be found. Figure 2 demonstrates the intersection of multiple curves with the plane.

Fig. 2
figure 2

Intersection of multiple curves with the plane.

Find the intersection curve reversely

Based on the reverse engineering and NURBS theory, the control points of a NURBS curve going through all the \(\:m-q+2\) intersection points will be computed reversely. According to the NURBS curve expression, without considering the weights, there is

$$\:\sum\:_{j=0}^{m}{N}_{j,q}\left(v\right){\varvec{V}}_{j}={\varvec{P}}_{\varvec{j}}$$
(5)

where \(\:{\varvec{P}}_{\varvec{j}}\) are the data points through which we want the generated curve goes. In this case, \(\:{\varvec{P}}_{\varvec{j}}\) include the intersection points and the complementary points which are determined by the boundary conditions. \(\:{\varvec{V}}_{j}\) are the required control points that will generate the NURBS curve.

Due to the rational properties and non-uniformity of NURBS, NURBS interpolation is extremely difficult even impossible, and here it is first simplified as a B-spline interpolation problem. The error caused by this simplification can be solved later through additional interpolation as discussed in the “Algorithm verification”. According to16, Eq. (5) can be rewritten in matrix form as follows

$$\:\left[\begin{array}{cccccccc}{b}_{0}&\:{c}_{0}&\:&\:&\:&\:&\:&\:\\\:\raisebox{1ex}{$1$}\!\left/\:\!\raisebox{-1ex}{$4$}\right.&\:\raisebox{1ex}{$7$}\!\left/\:\!\raisebox{-1ex}{$12$}\right.&\:\raisebox{1ex}{$1$}\!\left/\:\!\raisebox{-1ex}{$6$}\right.&\:&\:&\:&\:&\:\\\:&\:\raisebox{1ex}{$1$}\!\left/\:\!\raisebox{-1ex}{$6$}\right.&\:\raisebox{1ex}{$2$}\!\left/\:\!\raisebox{-1ex}{$3$}\right.&\:\raisebox{1ex}{$1$}\!\left/\:\!\raisebox{-1ex}{$6$}\right.&\:&\:&\:&\:\\\:&\:&\:...&\:...&\:...&\:&\:&\:\\\:&\:&\:&\:...&\:...&\:...&\:&\:\\\:&\:&\:&\:&\:\raisebox{1ex}{$1$}\!\left/\:\!\raisebox{-1ex}{$6$}\right.&\:\raisebox{1ex}{$2$}\!\left/\:\!\raisebox{-1ex}{$3$}\right.&\:\raisebox{1ex}{$1$}\!\left/\:\!\raisebox{-1ex}{$6$}\right.&\:\\\:&\:&\:&\:&\:&\:\raisebox{1ex}{$1$}\!\left/\:\!\raisebox{-1ex}{$6$}\right.&\:\raisebox{1ex}{$7$}\!\left/\:\!\raisebox{-1ex}{$12$}\right.&\:\raisebox{1ex}{$1$}\!\left/\:\!\raisebox{-1ex}{$4$}\right.\\\:&\:&\:&\:&\:&\:&\:{a}_{m}&\:{b}_{m}\end{array}\right]\left[\begin{array}{c}{V}_{0}\\\:{V}_{1}\\\:{V}_{2}\\\:...\\\:{V}_{m-2}\\\:{V}_{m-1}\\\:{V}_{m}\end{array}\right]=\left[\begin{array}{c}{d}_{0}\\\:{P}_{0}\\\:{P}_{1}\\\:...\\\:{P}_{m-3}\\\:{P}_{m-2}\\\:{d}_{m-1}\end{array}\right]$$
(6)

For cubic NURBS curves, the following boundary conditions are added to Eq. (6).

$$\:{b}_{0}=9\:{c}_{0}=-3\:{d}_{0}=6{P}_{0}$$
$$\:{a}_{m}=-3\:{b}_{m}=9\:{d}_{m-1}=6{P}_{m-2}$$

In Eq. (6), the matrix is a tridiagonal matrix that can be solved using the pursuit method. Therefore, control points are computed by Eq. (6) reversely. The NURBS curve generated by these control points will go through the intersection points. Figure 3 illustrates the generated NURBS curve. The generated curve is used to approximate the actual intersection curve of the NURBS surface and the plane. Figure 4 demonstrates that the generated curve fits the actual intersection curve nearly perfectly. In the CNC surface machining process, this generated curve can be used as the tool path.

Fig. 3
figure 3

Intersection curve generated by the control points.

Fig. 4
figure 4

The generated curve can fit the actual intersection curve well.

To strengthen the effectiveness of the algorithm, we have tested more NURBS surfaces with the proposed algorithm. Two of these surface are Figs. 5 and 6.

Fig. 5
figure 5

NURBS surface and plane intersection test 1.

Fig. 6
figure 6

NURBS surface and plane intersection test 2.

Algorithm verification

Since the intersection curve is a curve coming from the NURBS surface intersecting with the plane, the curve must be a planar curve, and it must be on the plane. That is, the intersection points and the control points obtained reversely must be on the plane, too. To verify the correctness and accuracy of the proposed algorithm, first, we should verify if the intersection points and the control points obtained reversely satisfy the plane expression. In one of the experiments, the cubic NURBS surface has 9 × 9 = 81 control points. Each of the two parameters \(\:u\) and \(\:v\) has 9 − 3 = 6 segments. The expression of the plane intersecting with the NURBS surface is \(\:0.01\text{x}+12\text{y}-\text{z}-1800=0\). Usually, the projection of the control points of the NURBS surface onto one coordinate plane, i.e., the x-y plane of the coordinate system, is in a rectangular area. The reason that \(\:0.01\text{x}+12\text{y}-\text{z}-1800=0\) is chosen as the expression of the plane is that we want to ensure that the plane is as parallel as possible to two opposite edges of the projection rectangle and perpendicular to the other two opposite edges (For the sake of simplicity, we will refer to it as ideal intersection later). In this situation, the generated curve used to approximate the intersection curve is closest to the intersection curve. Otherwise, if the plane is far from parallel and perpendicular to the edges of the rectangle, the approximation is not satisfying, and other improvement measurements should be taken, as discussed later. By fixing the parameter \(\:v\) as it is in its knot vector, seven \(\:u\)-direction NURBS curves are formed, which are used to intersect with the plane to get seven intersection points. Then, nine control points are computed reversely.

Tables 1 and 2 show that the intersection points and the control points are on the plane, and the errors meet the error control requirement (error requirement being 10− 4).

Table 1 Intersection points verification.
Table 2 Control points verification.

To further verify the proposed algorithm, the actual intersection curve is compared with the generated curve, as shown in Fig. 5. In the test, the actual intersection curve is obtained via dense sampling. As can be seen from Fig. 7, the two curves have a high degree of agreement. The RMSE (Root Mean Square Error) between the two curves is only about 1.87.

Fig. 7
figure 7

Comparison of the actual intersection curve and the generated curve.

The above results show that the algorithm is effective and has high accuracy when the plane is nearly parallel to the two opposite edges of the projection rectangle and perpendicular to the other two opposite edges (ideal intersection). If this is not the case, there will be obvious errors between the generated and actual curves, as shown in Fig. 8. The RMSE is 9.23, and it is obviously larger than that of the ideal intersection in which the RMSE is 1.87. This obvious error is mainly because the original knot vector of the NURBS surface is used as the knot vector of the generated curve in the proposed algorithm. This is a little unreasonable, but the purpose of doing so is to significantly reduce the complexity of the calculations. When a plane ideally intersects with a NURBS surface, the proposed algorithm brings about an ideal effect. However, when the plane doesn’t intersect with the surface ideally, the proposed algorithm will cause large errors. To address this problem is quite complex, and some studies have used complex algorithms such as particle swarm optimization (PSO) to solve this problem. However, the CNC system has real-time requirements, and complex algorithms cannot meet this requirement. At the same time, the increase in accuracy brought about by these complex algorithms is not always satisfactory. According to reference12 and our estimation, it takes about 20 ms to find just one intersection point of a NURBS curve when PSO algorithm is used. This is unacceptable for a CNC system. In the proposed algorithm, a NURBS calculation takes only several nanoseconds, and the total cost of finding the intersection curve is about several microseconds. Furthermore, for the PSO algorithm, the computational cost will increase exponentially if high accuracy is required. On the other hand, the computational cost of the proposed algorithm will only increase at a square root rate.

To improve the accuracy with the least increase in computational complexity, a strategy adopted here is to interpolate the generated curve so as to improve the intersection effect. By interpolating the generated curve, the shape of the curve can be controlled more flexibly, and the generated curve can fit the actual intersection curve better. In general, large errors are prone to occur at the place where the curvature of the intersection curve is large and at both ends of the intersection curve, so it is important to interpolate at these places. With curve interpolation, the accuracy of the approximation is significantly improved, and the RMSE reduces from 9.23 to 2.23. Figure 9 shows a comparison of the improved intersection curve after interpolation and the actual intersection curve, and it can be seen that the two curves have a high degree of agreement. Comparing Figs. 8 and 10, one can see that the accuracy has improved significantly.

Fig. 8
figure 8

Obvious error occurs in non-ideal intersection.

Fig. 9
figure 9

The improved intersection curve after interpolation fits the actual intersection curve well.

Fig. 10
figure 10

The improved intersection curve after interpolation is fairly accurate.

Conclusion

The proposed algorithm can find the intersection curve of a plane and a NURBS surface rapidly and give the NURBS description of the intersection curve, which can be used as a tool path in the CNC surface machining process. The NURBS description is convenient for storing and transmitting the tool path in the subsequent machining process in which the NURBS curve interpolation algorithm is usually needed. The explicit NURBS description benefits a lot to the NURBS interpolation algorithm. The proposed algorithm only needs to solve the intersection points of several NURBS curves with the plane. In the abovementioned experiment, 7 NURBS curves with 9 control points in each curve are first obtained, and only 63 NURBS calculations are required. When the control accuracy is 10− 6, it takes about 140 NURBS calculations to find the intersection points of the 7 curves and the plane with the bisection method. Equation (6) can be solved using the Thomas algorithm. The computational cost of the reverse engineering is about \(\:5*n\) floating-point operations, where \(\:n\) is the order of the matrix in Eq. (6). Its computational cost is relatively small compared to that of the NURBS, and so the computational cost of the reverse engineering can be neglected. Without considering the computation of the reverse engineering, the total computation is just a little more than 200 NURBS calculations. On the contrary, the traditional triangular patch approximation algorithm that uses a large number of small triangular patches to fit the original surface may require thousands or even hundreds of thousands of NURBS calculations to form triangular patches. Also, the traditional triangular patch approximation algorithm needs to judge whether each of these massive patches intersects with the plane, which is very computation-consuming. Therefore, the proposed algorithm has high efficiency. This is of great significance for CNC systems with high real-time requirements. The shortcoming of the proposed algorithm is that it needs ideal intersection conditions, just as described previously. However, in the path planning process of surface machining, people have opportunities to set how the plane intersects with the NURBS surface. In some special situations where the ideal intersection condition is not satisfied, curve interpolation techniques can be adopted to reduce the approximation error.