Skip to content
DeepForgeby svx
All problems
HardTime Seriests-176

Spline Interpolation One Segment

Problem

Evaluate a Catmull-Rom cubic at the midpoint of one segment between y1 and y2, given the neighboring points y0 and y3: (-y0 + 9 * y1 + 9 * y2 - y3) / 16.

Return the interpolated value.

Hint

Catmull-Rom passes through the middle points and uses the outer ones for slope.

Test cases

case 1
in: [0,1,2,3]
expected: 1.5
case 2
in: [1,1,1,1]
expected: 1
case 3
in: [0,0,1,1]
expected: 0.5
case 4
in: [1,2,4,8]
expected: 2.8125
Starter codePython
def spline_interpolation_segment(y0, y1, y2, y3):
    # Your code here
    pass

4 test cases · run your code against them in the editor