MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / BezierSegment

Class BezierSegment

lib/matplotlib/bezier.py:273–402  ·  view source on GitHub ↗

A d-dimensional Bézier segment. A BezierSegment can be called with an argument, either a scalar or an array-like object, to evaluate the curve at that/those location(s). Parameters ---------- control_points : (N, d) array Location of the *N* control points.

Source from the content-addressed store, hash-verified

271
272
273class BezierSegment:
274 """
275 A d-dimensional Bézier segment.
276
277 A BezierSegment can be called with an argument, either a scalar or an array-like
278 object, to evaluate the curve at that/those location(s).
279
280 Parameters
281 ----------
282 control_points : (N, d) array
283 Location of the *N* control points.
284 """
285
286 def __init__(self, control_points):
287 self._cpoints = np.asarray(control_points)
288 self._N, self._d = self._cpoints.shape
289 self._orders = np.arange(self._N)
290 coeff = [math.factorial(self._N - 1)
291 // (math.factorial(i) * math.factorial(self._N - 1 - i))
292 for i in range(self._N)]
293 self._px = (self._cpoints.T * coeff).T
294
295 def __call__(self, t):
296 """
297 Evaluate the Bézier curve at point(s) *t* in [0, 1].
298
299 Parameters
300 ----------
301 t : (k,) array-like
302 Points at which to evaluate the curve.
303
304 Returns
305 -------
306 (k, d) array
307 Value of the curve for each point in *t*.
308 """
309 t = np.asarray(t)
310 return (np.power.outer(1 - t, self._orders[::-1])
311 * np.power.outer(t, self._orders)) @ self._px
312
313 @_api.deprecated(
314 "3.11", alternative="Call the BezierSegment object with an argument.")
315 def point_at_t(self, t):
316 """
317 Evaluate the curve at a single point, returning a tuple of *d* floats.
318 """
319 return tuple(self(t))
320
321 @property
322 def control_points(self):
323 """The control points of the curve."""
324 return self._cpoints
325
326 @property
327 def dimension(self):
328 """The dimension of the curve."""
329 return self._d
330

Callers 2

iter_bezierMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…