Interpolate a spline through the provided points. :param listOfVector: a list of Vectors that represent the points :param tangents: tuple of Vectors specifying start and finish tangent :param periodic: creation of periodic curves :param parameters: the value
(
cls,
listOfVector: list[Vector],
tangents: Sequence[Vector] | None = None,
periodic: bool = False,
parameters: Sequence[float] | None = None,
scale: bool = True,
tol: float = 1e-6,
)
| 2696 | |
| 2697 | @classmethod |
| 2698 | def makeSpline( |
| 2699 | cls, |
| 2700 | listOfVector: list[Vector], |
| 2701 | tangents: Sequence[Vector] | None = None, |
| 2702 | periodic: bool = False, |
| 2703 | parameters: Sequence[float] | None = None, |
| 2704 | scale: bool = True, |
| 2705 | tol: float = 1e-6, |
| 2706 | ) -> Edge: |
| 2707 | """ |
| 2708 | Interpolate a spline through the provided points. |
| 2709 | |
| 2710 | :param listOfVector: a list of Vectors that represent the points |
| 2711 | :param tangents: tuple of Vectors specifying start and finish tangent |
| 2712 | :param periodic: creation of periodic curves |
| 2713 | :param parameters: the value of the parameter at each interpolation point. (The interpolated |
| 2714 | curve is represented as a vector-valued function of a scalar parameter.) If periodic == |
| 2715 | True, then len(parameters) must be len(intepolation points) + 1, otherwise len(parameters) |
| 2716 | must be equal to len(interpolation points). |
| 2717 | :param scale: whether to scale the specified tangent vectors before interpolating. Each |
| 2718 | tangent is scaled, so it's length is equal to the derivative of the Lagrange interpolated |
| 2719 | curve. I.e., set this to True, if you want to use only the direction of the tangent |
| 2720 | vectors specified by ``tangents``, but not their magnitude. |
| 2721 | :param tol: tolerance of the algorithm (consult OCC documentation). Used to check that the |
| 2722 | specified points are not too close to each other, and that tangent vectors are not too |
| 2723 | short. (In either case interpolation may fail.) |
| 2724 | :return: an Edge |
| 2725 | """ |
| 2726 | pnts = TColgp_HArray1OfPnt(1, len(listOfVector)) |
| 2727 | for ix, v in enumerate(listOfVector): |
| 2728 | pnts.SetValue(ix + 1, v.toPnt()) |
| 2729 | |
| 2730 | if parameters is None: |
| 2731 | spline_builder = GeomAPI_Interpolate(pnts, periodic, tol) |
| 2732 | else: |
| 2733 | if len(parameters) != (len(listOfVector) + periodic): |
| 2734 | raise ValueError( |
| 2735 | "There must be one parameter for each interpolation point " |
| 2736 | "(plus one if periodic), or none specified. Parameter count: " |
| 2737 | f"{len(parameters)}, point count: {len(listOfVector)}" |
| 2738 | ) |
| 2739 | parameters_array = TColStd_HArray1OfReal(1, len(parameters)) |
| 2740 | for p_index, p_value in enumerate(parameters): |
| 2741 | parameters_array.SetValue(p_index + 1, p_value) |
| 2742 | |
| 2743 | spline_builder = GeomAPI_Interpolate(pnts, parameters_array, periodic, tol) |
| 2744 | |
| 2745 | if tangents: |
| 2746 | if len(tangents) == 2 and len(listOfVector) != 2: |
| 2747 | # Specify only initial and final tangent: |
| 2748 | t1, t2 = tangents |
| 2749 | spline_builder.Load(t1.wrapped, t2.wrapped, scale) |
| 2750 | else: |
| 2751 | if len(tangents) != len(listOfVector): |
| 2752 | raise ValueError( |
| 2753 | f"There must be one tangent for each interpolation point, " |
| 2754 | f"or just two end point tangents. Tangent count: " |
| 2755 | f"{len(tangents)}, point count: {len(listOfVector)}" |