MCPcopy Create free account
hub / github.com/NanoComp/meep / interpolate

Function interpolate

python/simulation.py:6161–6180  ·  view source on GitHub ↗

Given a list of numbers or `Vector3`s as `nums`, linearly interpolates between them to add `n` new evenly-spaced values between each pair of consecutive values in the original list.

(n, nums)

Source from the content-addressed store, hash-verified

6159
6160
6161def interpolate(n, nums):
6162 """
6163 Given a list of numbers or `Vector3`s as `nums`, linearly interpolates between them to
6164 add `n` new evenly-spaced values between each pair of consecutive values in the
6165 original list.
6166 """
6167 res = []
6168 if isinstance(nums[0], mp.Vector3):
6169 for low, high in zip(nums, nums[1:]):
6170 x = np.linspace(low.x, high.x, n + 1, endpoint=False).tolist()
6171 y = np.linspace(low.y, high.y, n + 1, endpoint=False).tolist()
6172 z = np.linspace(low.z, high.z, n + 1, endpoint=False).tolist()
6173
6174 for i in range(len(x)):
6175 res.append(mp.Vector3(x[i], y[i], z[i]))
6176 else:
6177 for low, high in zip(nums, nums[1:]):
6178 res.extend(np.linspace(low, high, n + 1, endpoint=False).tolist())
6179
6180 return res + [nums[-1]]
6181
6182
6183# extract center and size of a meep::volume

Callers 1

interpolateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected