mirror of
https://github.com/gumyr/build123d.git
synced 2025-12-06 02:30:55 -08:00
commit
6eb11ad9f6
2 changed files with 36 additions and 2 deletions
|
|
@ -89,8 +89,12 @@ from OCP.BRepPrimAPI import BRepPrimAPI_MakeHalfSpace
|
||||||
from OCP.BRepProj import BRepProj_Projection
|
from OCP.BRepProj import BRepProj_Projection
|
||||||
from OCP.BRepTools import BRepTools, BRepTools_WireExplorer
|
from OCP.BRepTools import BRepTools, BRepTools_WireExplorer
|
||||||
from OCP.GC import GC_MakeArcOfCircle, GC_MakeArcOfEllipse
|
from OCP.GC import GC_MakeArcOfCircle, GC_MakeArcOfEllipse
|
||||||
from OCP.GccEnt import GccEnt_unqualified, GccEnt_Position
|
from OCP.GCPnts import (
|
||||||
from OCP.GCPnts import GCPnts_AbscissaPoint
|
GCPnts_AbscissaPoint,
|
||||||
|
GCPnts_QuasiUniformDeflection,
|
||||||
|
GCPnts_UniformDeflection,
|
||||||
|
)
|
||||||
|
from OCP.GProp import GProp_GProps
|
||||||
from OCP.Geom import (
|
from OCP.Geom import (
|
||||||
Geom_BezierCurve,
|
Geom_BezierCurve,
|
||||||
Geom_BSplineCurve,
|
Geom_BSplineCurve,
|
||||||
|
|
@ -541,6 +545,31 @@ class Mixin1D(Shape[TOPODS]):
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def discretize(self, deflection: float = 0.1, quasi=True) -> list[Vector]:
|
||||||
|
"""Discretize the shape into a list of points"""
|
||||||
|
if self.wrapped is None:
|
||||||
|
raise ValueError("Cannot discretize an empty shape")
|
||||||
|
curve = self.geom_adaptor()
|
||||||
|
if quasi:
|
||||||
|
discretizer = GCPnts_QuasiUniformDeflection()
|
||||||
|
else:
|
||||||
|
discretizer = GCPnts_UniformDeflection()
|
||||||
|
discretizer.Initialize(
|
||||||
|
curve,
|
||||||
|
deflection,
|
||||||
|
curve.FirstParameter(),
|
||||||
|
curve.LastParameter(),
|
||||||
|
)
|
||||||
|
|
||||||
|
assert discretizer.IsDone()
|
||||||
|
|
||||||
|
return [
|
||||||
|
Vector(v.X(), v.Y(), v.Z())
|
||||||
|
for v in (
|
||||||
|
curve.Value(discretizer.Parameter(i))
|
||||||
|
for i in range(1, discretizer.NbPoints() + 1)
|
||||||
|
)
|
||||||
|
]
|
||||||
def curvature_comb(
|
def curvature_comb(
|
||||||
self, count: int = 100, max_tooth_size: float | None = None
|
self, count: int = 100, max_tooth_size: float | None = None
|
||||||
) -> ShapeList[Edge]:
|
) -> ShapeList[Edge]:
|
||||||
|
|
|
||||||
|
|
@ -368,6 +368,11 @@ class TestMixin1D(unittest.TestCase):
|
||||||
self.assertAlmostEqual(common.z_dir.Y, 0, 5)
|
self.assertAlmostEqual(common.z_dir.Y, 0, 5)
|
||||||
self.assertAlmostEqual(common.z_dir.Z, 0, 5)
|
self.assertAlmostEqual(common.z_dir.Z, 0, 5)
|
||||||
|
|
||||||
|
def test_discretize(self):
|
||||||
|
edge = Edge.make_circle(2, start_angle=0, end_angle=180)
|
||||||
|
points = edge.discretize(0.1)
|
||||||
|
self.assertEqual(len(points), 6)
|
||||||
|
|
||||||
def test_edge_volume(self):
|
def test_edge_volume(self):
|
||||||
edge = Edge.make_line((0, 0), (1, 1))
|
edge = Edge.make_line((0, 0), (1, 1))
|
||||||
self.assertAlmostEqual(edge.volume, 0, 5)
|
self.assertAlmostEqual(edge.volume, 0, 5)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue