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

Method sample

cadquery/occ_impl/shapes.py:2385–2412  ·  view source on GitHub ↗

Sample a curve based on a number of points or deflection. :param n: Number of positions or deflection :return: A list of Vectors and a list of parameters.

(
        self: Mixin1DProtocol, n: int | float
    )

Source from the content-addressed store, hash-verified

2383 return [self.positionAt(d, mode) for d in ds]
2384
2385 def sample(
2386 self: Mixin1DProtocol, n: int | float
2387 ) -> tuple[list[Vector], list[float]]:
2388 """
2389 Sample a curve based on a number of points or deflection.
2390
2391 :param n: Number of positions or deflection
2392 :return: A list of Vectors and a list of parameters.
2393 """
2394
2395 gcpnts: GCPnts_QuasiUniformAbscissa | GCPnts_QuasiUniformDeflection
2396
2397 if isinstance(n, int):
2398 crv = self._geomAdaptor()
2399 gcpnts = GCPnts_QuasiUniformAbscissa(crv, n + 1 if crv.IsClosed() else n)
2400 else:
2401 crv = self._geomAdaptor()
2402 gcpnts = GCPnts_QuasiUniformDeflection(crv, n)
2403
2404 N_pts = gcpnts.NbPoints()
2405
2406 params = [
2407 gcpnts.Parameter(i)
2408 for i in range(1, N_pts if crv.IsClosed() else N_pts + 1)
2409 ]
2410 pnts = [Vector(crv.Value(p)) for p in params]
2411
2412 return pnts, params
2413
2414 def locationAt(
2415 self: Mixin1DProtocol,

Callers 8

edgeOnFunction · 0.80
rotated_circlesFunction · 0.80
test_approximateFunction · 0.80
test_nurbs.pyFile · 0.80
test_styleFunction · 0.80
test_edge_paramsFunction · 0.80
test_sampleFunction · 0.80

Calls 3

VectorClass · 0.85
IsClosedMethod · 0.80
_geomAdaptorMethod · 0.45

Tested by 6

rotated_circlesFunction · 0.64
test_approximateFunction · 0.64
test_styleFunction · 0.64
test_edge_paramsFunction · 0.64
test_sampleFunction · 0.64