Skip to main content
. 2025 Jan 23;18(3):505. doi: 10.3390/ma18030505
Algorithm 1 Find point Poptimal on the target part to serve as the end of an ingate.
Input: STL_model: List of triangular faces {Facei:(PointAi, PointBi,PointCi)}
P: The endpoint of the streamline in an ingate of the source part’s process
T: The threshold of distance
Nsource: The normal vector at point P.
Hsource: The mean curvature at point P.
Ksource: The Gaussian curvature at point P.
1: Initialize List Centers=[]
2: Initialize Dictionary Face_Map={}
3: For Facei in STL_model do
4:  Calculate the center point Ci of Facei
5:  Centers.append(Ci)
6:  Face_Map[Ci]=Facei
7: End For
8: Build K-D Tree kdTree using Centers
9: The cluster of center points closest to P Ccandidate=kdTree.rangeQuery(P,T)
10: Initialize List Candidate_Point_Info=[]
11: For Ci in Ccandidate do
12:  Facei=Face_Map[Ci]
13: Calculate the projection point Pi of P on the Facei plane
14: If Pi is outside of Facei then
15: Choose the vertex of Facei that is closet to P as the new Pi
16: End If
17:  Candidate_Point_Info.append(Pi,Facei)
18: End For
19: Initialize min_total_error=
20: Initialize Poptimal=None
21: For (Pi,Facei) in Candidate_P do
22: Approximate the normal vector Ni of Pi by the normal vector of Facei
23: Compute the mean curvature Hi and Gaussian curvature Ki at P using barycentric coordinate interpolation
24: Substitute Nsource, Hsource, Ksource, Ni, Hi, Ki to calculate the total error Erri using Equation (1)
25: If (Erri<min_total_error) then
26:  min_total_error=Erri
27:  Poptimal=Pi
28: End If
29: End For
Output: The position of the optimal point Poptimal on the STL surface of the target part.