Skip to content

Commit 7707329

Browse files
committed
add join and joined with example
1 parent 0287177 commit 7707329

File tree

6 files changed

+88
-0
lines changed

6 files changed

+88
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## Unreleased
99

1010
### Added
11+
* Added `compas_occ.geometry.NurbsCurve.join`.
12+
* Added `compas_occ.geometry.NurbsCurve.joined`.
1113

1214
### Changed
1315

375 KB
Loading
373 KB
Loading

docs/examples/curve_joining.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from compas.geometry import Point
2+
from compas.geometry import Polyline
3+
from compas_occ.geometry import OCCNurbsCurve
4+
from compas_view2.app import App
5+
6+
points1 = [Point(0, 0, 0), Point(1, 1, 0), Point(3, 0, 0)]
7+
points2 = [Point(3, 0, 0), Point(4, -2, 0), Point(5, 0, 0)]
8+
9+
curve1 = OCCNurbsCurve.from_interpolation(points1)
10+
curve2 = OCCNurbsCurve.from_interpolation(points2)
11+
12+
joined = curve1.joined(curve2)
13+
curve1.join(curve2)
14+
15+
# ==============================================================================
16+
# Visualisation
17+
# ==============================================================================
18+
19+
view = App()
20+
21+
view.add(Polyline(curve1.locus()), linewidth=3, linecolor=(1, 0, 0))
22+
view.add(Polyline(curve2.locus()), linewidth=3, linecolor=(0, 1, 0))
23+
view.add(Polyline(joined.locus()), linewidth=3, linecolor=(0, 0, 1))
24+
25+
view.run()

docs/examples/curve_joining.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
********************************************************************************
2+
Curve Joining
3+
********************************************************************************
4+
5+
.. figure:: /_images/example_curve_joining_separate.png
6+
:figclass: figure
7+
:class: figure-img img-fluid
8+
9+
.. figure:: /_images/example_curve_joining_joined.png
10+
:figclass: figure
11+
:class: figure-img img-fluid
12+
13+
.. literalinclude:: curve_joined.py
14+
:language: python

src/compas_occ/geometry/curves/nurbs.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from OCC.Core.Geom import Geom_BSplineCurve
2121
from OCC.Core.GeomAPI import GeomAPI_Interpolate
22+
from OCC.Core.GeomConvert import GeomConvert_CompCurveToBSplineCurve
2223

2324
from .curve import OCCCurve
2425

@@ -493,3 +494,49 @@ def segmented(self, u, v, precision=1e-3):
493494
copy = self.copy()
494495
copy.segment(u, v, precision)
495496
return copy
497+
498+
def join(self, curve, precision=1e-4):
499+
"""Modifies this curve by joining it with another curve.
500+
501+
Parameters
502+
----------
503+
curve : :class:`OCCNurbsCurve`
504+
The curve to join.
505+
506+
precision : float, optional
507+
Tolerance for continuity and multiplicity.
508+
509+
Returns
510+
-------
511+
None
512+
513+
"""
514+
converter = GeomConvert_CompCurveToBSplineCurve(self.occ_curve)
515+
success = converter.Add(curve.occ_curve, precision)
516+
if success:
517+
self.occ_curve = converter.BSplineCurve()
518+
519+
def joined(self, curve, precision=1e-4):
520+
"""Returns a copy of joining this curve with another curve.
521+
522+
Parameters
523+
----------
524+
curve : :class:`OCCNurbsCurve`
525+
The curve to join.
526+
527+
precision : float, optional
528+
Tolerance for continuity and multiplicity.
529+
530+
Returns
531+
-------
532+
:class:`OCCNurbsCurve`
533+
534+
"""
535+
copy = self.copy()
536+
converter = GeomConvert_CompCurveToBSplineCurve(self.occ_curve)
537+
success = converter.Add(curve.occ_curve, precision)
538+
if success:
539+
copy.occ_curve = converter.BSplineCurve()
540+
return copy
541+
else:
542+
return None

0 commit comments

Comments
 (0)