Skip to content

Commit

Permalink
Support 2 points for cubic spline.
Browse files Browse the repository at this point in the history
  • Loading branch information
portnov committed Dec 19, 2022
1 parent 8192dcd commit d247404
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion tests/nurbs_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

from sverchok.utils.testing import SverchokTestCase, requires
from sverchok.utils.geom import circle_by_three_points
from sverchok.utils.nurbs_common import SvNurbsMaths, elevate_bezier_degree, from_homogenous
from sverchok.utils.curve import knotvector as sv_knotvector
from sverchok.utils.curve.primitives import SvCircle
from sverchok.utils.curve.nurbs import SvGeomdlCurve, SvNativeNurbsCurve, SvNurbsBasisFunctions, SvNurbsCurve
from sverchok.utils.nurbs_common import SvNurbsMaths, elevate_bezier_degree, from_homogenous
from sverchok.utils.curve.nurbs_solver_applications import knotvector_with_tangents_from_tknots
from sverchok.utils.surface.nurbs import SvGeomdlSurface, SvNativeNurbsSurface
from sverchok.utils.surface.algorithms import SvCurveLerpSurface
from sverchok.dependencies import geomdl
Expand Down Expand Up @@ -909,6 +910,12 @@ def test_interpolate_4d(self):
expected_weights = np.array([1, 3, 1])
self.assert_numpy_arrays_equal(weights, expected_weights, precision=6)

def test_knotvector_with_tangents_1(self):
u = np.array([0.0, 1.0])
kv = knotvector_with_tangents_from_tknots(3, u)
expected = np.array([0,0,0,0, 1,1,1,1])
self.assert_numpy_arrays_equal(kv, expected, precision=4)

class TaylorTests(SverchokTestCase):
def test_bezier_to_taylor_1(self):
cpts = np.array([[0,0,0], [1,0,0], [1,1,0], [2,1,0]], dtype=np.float64)
Expand Down
8 changes: 7 additions & 1 deletion utils/curve/nurbs_solver_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ def knotvector_with_tangents_from_tknots(degree, u):
kv.extend([u[-1], u[-1]])
return np.array(kv)
elif degree == 3:
if len(u) == 2:
return np.array([u[0], u[0], u[0], u[0],
u[1], u[1], u[1], u[1]])
kv = [u[0], u[0], u[0],u[0]]
kv.append(u[1]/2.0)
for i in range(1, n-2):
Expand All @@ -193,11 +196,14 @@ def interpolate_nurbs_curve_with_tangents(degree, points, tangents,
tangents = np.asarray(tangents)
if len(points) != len(tangents):
raise Exception(f"Number of points ({len(points)}) must be equal to number of tangent vectors ({len(tangents)})")
ndim = points.shape[-1]
if ndim not in {3,4}:
raise Exception(f"Points must be 3 or 4 dimensional, not {ndim}")

if tknots is None:
tknots = Spline.create_knots(points, metric=metric)

solver = SvNurbsCurveSolver(degree=degree, ndim=4)
solver = SvNurbsCurveSolver(degree=degree, ndim=ndim)
solver.add_goal(SvNurbsCurvePoints(tknots, points, relative=False))
solver.add_goal(SvNurbsCurveTangents(tknots, tangents, relative=False))
knotvector = knotvector_with_tangents_from_tknots(degree, tknots)
Expand Down

0 comments on commit d247404

Please sign in to comment.