latentspace.

Subdivision curve

Subdivision curves

Subdivision methods progressively refine a discrete curve so that it converges to a smooth curve. This makes it possible to interpolate or approximate a given coarse dataset.
Subdivision iterative step
Subdivision iterative step

A subdivision curve is created from a set of base vertices (or a base curve). Given the base vertices, the points at n% and 100-n% along the vector between the i-th point and the (i+1)-th point are computed. The code is as follows.

    class SubdivisionCurve:
        QUARTER = 0.25
        QUARTERDIFF = 1 - QUARTER
        
        def __init__(self, points, count, is_closed=False):
            self.points = points
            self.count = count
            self.is_closed = is_closed
            
            self.subdivided_points = points[:]
            
        def get_subdivided_curve(self):
            self._subdivide()
            return self.subdivided_points
            
        def _subdivide(self):
            for _ in range(self.count):
                each_subdivided_points = []
            
                for curr_index in range(len(self.subdivided_points)):
                    next_index = (curr_index + 1) % len(self.subdivided_points)
                    if next_index == 0 and not self.is_closed:
                        continue
                
                    curr_point = self.subdivided_points[curr_index]
                    next_point = self.subdivided_points[next_index]
                    
                    pt_1 = (next_point - curr_point) * self.QUARTER + curr_point
                    pt_2 = (next_point - curr_point) * self.QUARTERDIFF + curr_point

                    each_subdivided_points.append(pt_1)
                    each_subdivided_points.append(pt_2)
                    
                self.subdivided_points = each_subdivided_points

Increasing the iterative count produces a smoother curve, as illustrated in the image below.
Shape of subdivision curve by iterative count From the left, Subdivided vertices · Subdivided curve
Shape of subdivision curve by iterative count
From the left, Subdivided vertices · Subdivided curve