# Interpolate Points

I’ve been given a set of points derived from real-world measurements, but it is apparent that some points are missing. How can I interpolate the points I do have to estimate the points that are missing? I am going to be using this data in Grasshopper and want to fix this via ghpython. The missing points show up as null in the grasshopper list, so I know where in the sequence they are. One thing I could do is interpolate curve and get the points in the gap. But then I saw that Rhinocommon has a interpolate section (Rhino.Geometry.Interpolator). Can I use those tools to estimate the missing points?

I’ve attached a simplified example of my data points.

160718 Interpolate Point.gh (7.6 KB)
160718 Interpolate Points.3dm (64.8 KB)

Hi Lawrence,

Whithout testing you code or the file, I would try what creating a interpolated curve through the points can bring you:
Rhino.Geometry.Curve.CreateInterpolatedCurve(points, degree, knotstyle, start_tangent, end_tangent)

What you could do is:

1: Create the interpolated curve through the points you have
2: Split the curve at the points that form the start and end of a gap in your data
3: Divide the splitresult into the amount of sections you are missing and evaluate the division points to fill the missing data points.

HTH
-Willem

Yes, that was my initial thought but I was hoping someone would know if interpolator was applicable in this situation. If I could learn to use it here it may come in handy later for when my data points are less linear/sequential.

I did a quick setup to test the interpolator
here it is fwiw:

``````import rhinoscriptsyntax as rs
import Rhino

def InterpolateCosineMissingXYZ(start_index,missing_steps,x_interpolator,y_interpolator,z_interpolator):
for T in xrange(1,missing_steps):
x = x_interpolator.InterpolateCosine(start_index + (T/missing_steps) )
y = y_interpolator.InterpolateCosine(start_index+ (T/missing_steps) )
z = z_interpolator.InterpolateCosine(start_index+ (T/missing_steps) )

def InterpolateCatmullRomMissingXYZ(start_index,missing_steps,x_interpolator,y_interpolator,z_interpolator):
for T in xrange(1,missing_steps):
x = x_interpolator.InterpolateCatmullRom(start_index + (T/missing_steps) )
y = y_interpolator.InterpolateCatmullRom(start_index+ (T/missing_steps) )
z = z_interpolator.InterpolateCatmullRom(start_index+ (T/missing_steps) )

def InterpolateCubicMissingXYZ(start_index,missing_steps,x_interpolator,y_interpolator,z_interpolator):
for T in xrange(1,missing_steps):
x = x_interpolator.InterpolateCubic(start_index + (T/missing_steps) )
y = y_interpolator.InterpolateCubic(start_index+ (T/missing_steps) )
z = z_interpolator.InterpolateCubic(start_index+ (T/missing_steps) )

def Main():

pt_objs = rs.GetObjects('select points',filter = 1)
pts = [rs.PointCoordinates(obj) for obj in pt_objs]
#sort the points along the x axis to sanitize input for testing
pts.sort(key = lambda pt : pt.X)

x_interpolator = Rhino.Geometry.Interpolator([pt.X for pt in pts])
y_interpolator = Rhino.Geometry.Interpolator([pt.Y for pt in pts])
z_interpolator = Rhino.Geometry.Interpolator([pt.Z for pt in pts])

startA,stepsA = 7,3
startB,stepsB = 22,4
startC,stepsC = 36,5

if True:
InterpolateCosineMissingXYZ(startA,stepsA,x_interpolator,y_interpolator,z_interpolator)
InterpolateCosineMissingXYZ(startB,stepsB,x_interpolator,y_interpolator,z_interpolator)
InterpolateCosineMissingXYZ(startC,stepsC,x_interpolator,y_interpolator,z_interpolator)

if True:
InterpolateCatmullRomMissingXYZ(startA,stepsA,x_interpolator,y_interpolator,z_interpolator)
InterpolateCatmullRomMissingXYZ(startB,stepsB,x_interpolator,y_interpolator,z_interpolator)
InterpolateCatmullRomMissingXYZ(startC,stepsC,x_interpolator,y_interpolator,z_interpolator)

if True:
InterpolateCubicMissingXYZ(startA,stepsA,x_interpolator,y_interpolator,z_interpolator)
InterpolateCubicMissingXYZ(startB,stepsB,x_interpolator,y_interpolator,z_interpolator)
InterpolateCubicMissingXYZ(startC,stepsC,x_interpolator,y_interpolator,z_interpolator)

Main()
``````

result with lines for clarity:

I think there is more to it than my setup so maybe it’s worth digging deeper, let me know what you find

-Willem

1 Like

Thanks for the example. From looking at your results, it seems that the interpolator produces flatter curves.

I tried doing Rhino.Geometry.Curve.CreateInterpolatedCurve(), but the resultant curve does not look right (see image below). The blue curve was drawn with the interpcrv command (which looks good) and the green one was drawn with the Rhinocommon command (I only provided the points and set the degree to 3)- both use the same points (6 before and 6 after gap).

correction: After setting the curveknotstyle to chord, the Rhinocommon curve now looks like the manually drawn one.

1 Like

You might consider creating interpolated curves in pieces, then blending between the pieces (`Rhino.Geometry.Curve.CreateBlendCurve`).

I guess if you use the version without need for a knot style, `Uniform` knot spacing is used. `Chord` is the best choice in your case.

c.

1 Like