From f007e03234b320f01d1cc366094f8b6ac80dba2b Mon Sep 17 00:00:00 2001 From: "Ilya V. Portnov" Date: Tue, 12 Nov 2024 18:36:12 +0500 Subject: [PATCH] New api methods. --- utils/curve/splines.py | 5 +++++ utils/geom.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/utils/curve/splines.py b/utils/curve/splines.py index 86c18fc8f1..45ea122497 100644 --- a/utils/curve/splines.py +++ b/utils/curve/splines.py @@ -32,6 +32,11 @@ def from_points(cls, points, metric=None, is_cyclic=False): spline = CubicSpline(points, metric=metric, is_cyclic=is_cyclic) return SvSplineCurve(spline) + @classmethod + def from_2d_points(cls, xs, ys): + spline = CubicSpline.from_2d_points(xs, ys) + return SvSplineCurve(spline) + def evaluate(self, t): v = self.spline.eval_at_point(t) return np.array(v) diff --git a/utils/geom.py b/utils/geom.py index 1d62e4dc25..3ecb4426fe 100644 --- a/utils/geom.py +++ b/utils/geom.py @@ -370,6 +370,13 @@ def calc_cubic_splines(tknots, n, locs): def create(cls, vertices, tknots = None, metric = None, is_cyclic = False): return CubicSpline(vertices, tknots=tknots, metric=metric, is_cyclic=is_cyclic) + @classmethod + def from_2d_points(cls, xs, ys): + vertices = np.zeros((len(xs), 3)) + vertices[:,0] = np.array(xs) + vertices[:,1] = np.zrray(ys) + return CubicSpline(vertices, metric='X', is_cyclic=False) + def eval(self, t_in, tknots = None): """ Evaluate the spline at the points in t_in, which must be an array