MCPcopy
hub / github.com/CadQuery/cadquery / parametricCurve

Method parametricCurve

cadquery/cq.py:1939–1983  ·  view source on GitHub ↗

Create a spline curve approximating the provided function. :param func: function f(t) that will generate (x,y,z) pairs :type func: float --> (float,float,float) :param N: number of points for discretization :param start: starting value of the parameter t

(
        self: T,
        func: Callable[[float], VectorLike],
        N: int = 400,
        start: float = 0,
        stop: float = 1,
        tol: float = 1e-6,
        minDeg: int = 1,
        maxDeg: int = 6,
        smoothing: Optional[Tuple[float, float, float]] = (1, 1, 1),
        makeWire: bool = True,
    )

Source from the content-addressed store, hash-verified

1937 return self.newObject([rv_w if makeWire else e])
1938
1939 def parametricCurve(
1940 self: T,
1941 func: Callable[[float], VectorLike],
1942 N: int = 400,
1943 start: float = 0,
1944 stop: float = 1,
1945 tol: float = 1e-6,
1946 minDeg: int = 1,
1947 maxDeg: int = 6,
1948 smoothing: Optional[Tuple[float, float, float]] = (1, 1, 1),
1949 makeWire: bool = True,
1950 ) -> T:
1951 """
1952 Create a spline curve approximating the provided function.
1953
1954 :param func: function f(t) that will generate (x,y,z) pairs
1955 :type func: float --> (float,float,float)
1956 :param N: number of points for discretization
1957 :param start: starting value of the parameter t
1958 :param stop: final value of the parameter t
1959 :param tol: tolerance of the algorithm (default: 1e-6)
1960 :param minDeg: minimum spline degree (default: 1)
1961 :param maxDeg: maximum spline degree (default: 6)
1962 :param smoothing: optional parameters for the variational smoothing algorithm (default: (1,1,1))
1963 :param makeWire: convert the resulting spline edge to a wire
1964 :return: a Workplane object with the current point unchanged
1965
1966 """
1967
1968 diff = stop - start
1969 allPoints = self._toVectors(
1970 (func(start + diff * t / N) for t in range(N + 1)), False
1971 )
1972
1973 e = Edge.makeSplineApprox(
1974 allPoints, tol=tol, smoothing=smoothing, minDeg=minDeg, maxDeg=maxDeg
1975 )
1976
1977 if makeWire:
1978 rv_w = Wire.assembleEdges([e])
1979 self._addPendingWire(rv_w)
1980 else:
1981 self._addPendingEdge(e)
1982
1983 return self.newObject([rv_w if makeWire else e])
1984
1985 def parametricSurface(
1986 self: T,

Callers 1

testParametricCurveMethod · 0.80

Calls 6

_toVectorsMethod · 0.95
_addPendingWireMethod · 0.95
_addPendingEdgeMethod · 0.95
newObjectMethod · 0.95
assembleEdgesMethod · 0.80
makeSplineApproxMethod · 0.45

Tested by 1

testParametricCurveMethod · 0.64