Skip to content

compas_occ.conversions ¤

Functions¤

aabb_to_compas ¤

aabb_to_compas(aabb: Bnd_Box) -> Box

Convert an OCC oriented bounding box to a COMPAS box.

array1_from_floats1 ¤

array1_from_floats1(numbers: list[float]) -> TColStd_Array1OfReal

Construct a one-dimensional float array from a list of floats.

See Also

Examples:

>>> from compas_occ.conversions import array1_from_floats1
>>> floats1 = [0.0, 1.0, 2.0]
>>> array1 = array1_from_floats1(floats1)
>>> array1
<OCC.Core.TColStd.TColStd_Array1OfReal; ... >

array1_from_integers1 ¤

array1_from_integers1(numbers: list[int]) -> TColStd_Array1OfInteger

Construct a one-dimensional integer array from a list of integers.

See Also

Examples:

>>> from compas_occ.conversions import array1_from_integers1
>>> integers1 = [0, 1, 2]
>>> array1 = array1_from_integers1(integers1)
>>> array1
<OCC.Core.TColStd.TColStd_Array1OfInteger; ... >

array1_from_points1 ¤

array1_from_points1(points: list[Point]) -> TColgp_Array1OfPnt

Construct a one-dimensional point array from a list of points.

See Also

Examples:

>>> from compas.geometry import Point
>>> from compas_occ.conversions import array1_from_points1
>>> points1 = [Point(0, 0, 0), Point(1, 0, 0), Point(2, 0, 0)]
>>> array1 = array1_from_points1(points1)
>>> array1
<OCC.Core.TColgp.TColgp_Array1OfPnt; ... >
>>> for item in array1:
...     print(item)
<class 'gp_Pnt'>
<class 'gp_Pnt'>
<class 'gp_Pnt'>
>>> for item in array1:
...     print(item.X(), item.Y(), item.Z())
0.0 0.0 0.0
1.0 0.0 0.0
2.0 0.0 0.0

array2_from_floats2 ¤

array2_from_floats2(numbers: list[list[float]]) -> TColStd_Array2OfReal

Construct a two-dimensional real array from a list of lists of floats.

See Also

Examples:

>>> from compas_occ.conversions import array2_from_floats2
>>> floats2 = [
...     [0.0, 0.0, 0.0],
...     [1.0, 0.0, 0.0],
...     [2.0, 0.0, 0.0],
... ]
>>> array2 = array2_from_floats2(floats2)
>>> array2
<OCC.Core.TColStd.TColStd_Array2OfReal; ... >

array2_from_points2 ¤

array2_from_points2(points: list[list[Point]]) -> TColgp_Array2OfPnt

Construct a two-dimensional point array from a list of lists of points.

See Also

Examples:

>>> from itertools import product
>>> from compas.geometry import Point
>>> from compas_occ.conversions import array2_from_points2
>>> points2 = [
...     [Point(0, 0, 0), Point(1, 0, 0), Point(2, 0, 0)],
...     [Point(0, 1, 0), Point(1, 1, 0), Point(2, 1, 0)],
... ]
>>> array2 = array2_from_points2(points2)
>>> array2
<OCC.Core.TColgp.TColgp_Array2OfPnt; ... >
>>> rows = range(array2.LowerRow(), array2.UpperRow() + 1)
>>> cols = range(array2.LowerCol(), array2.UpperCol() + 1)
>>> for i, j in product(rows, cols):
...     value = array2.Value(i, j)
...     x = value.X()
...     y = value.Y()
...     z = value.Z()
...     print(x, y, z)
0.0 0.0 0.0
0.0 1.0 0.0
1.0 0.0 0.0
1.0 1.0 0.0
2.0 0.0 0.0
2.0 1.0 0.0

ax22d_to_compas ¤

ax22d_to_compas(position: gp_Ax22d, cls: Type[Frame] | None = None) -> Frame

Construct a COMPAS frame from a 2D OCC position.

See Also

Examples:

>>> from OCC.Core.gp import gp_Pnt2d, gp_Dir2d, gp_Ax22d
>>> from compas_occ.conversions import ax22d_to_compas
>>> ax2 = gp_Ax22d(gp_Pnt2d(0, 0), gp_Dir2d(0, 1), gp_Dir2d(1, 0))
>>> ax22d_to_compas(ax2)
Frame(point=Point(x=0.0, y=0.0, z=0.0), xaxis=Vector(x=0.0, y=1.0, z=0.0), yaxis=Vector(x=1.0, y=0.0, z=0.0))

ax2_to_compas ¤

ax2_to_compas(position: gp_Ax2, cls: Type[Frame] | None = None) -> Frame

Construct a COMPAS frame from an OCC position.

See Also

Examples:

>>> from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Ax2
>>> from compas_occ.conversions import ax2_to_compas
>>> ax2 = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
>>> ax2_to_compas(ax2)
Frame(point=Point(x=0.0, y=0.0, z=0.0), xaxis=Vector(x=1.0, y=0.0, z=0.0), yaxis=Vector(x=0.0, y=1.0, z=0.0))

ax3_to_compas ¤

ax3_to_compas(position: gp_Ax3, cls: Type[Frame] | None = None) -> Frame

Construct a COMPAS frame from an OCC position.

See Also

Examples:

>>> from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Ax3
>>> from compas_occ.conversions import ax3_to_compas
>>> ax3 = gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
>>> ax3_to_compas(ax3)
Frame(point=Point(x=0.0, y=0.0, z=0.0), xaxis=Vector(x=1.0, y=0.0, z=0.0), yaxis=Vector(x=0.0, y=1.0, z=0.0))

axis2d_to_compas ¤

axis2d_to_compas(axis: gp_Ax2d) -> tuple[Point, Vector]

Convert a 2D OCC axis to a tuple of COMPAS point and vector.

See Also

Examples:

>>> from OCC.Core.gp import gp_Pnt2d, gp_Dir2d, gp_Ax2d
>>> from compas_occ.conversions import axis2d_to_compas
>>> axis = gp_Ax2d(gp_Pnt2d(0, 0), gp_Dir2d(1, 0))
>>> axis2d_to_compas(axis)
(Point(x=0.0, y=0.0, z=0.0), Vector(x=1.0, y=0.0, z=0.0))

axis2d_to_compas_vector ¤

axis2d_to_compas_vector(axis: gp_Ax2d, cls: Type[Vector] | None = None) -> Vector

Convert a 2D OCC axis to a COMPAS vector.

See Also

Examples:

>>> from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Ax1
>>> from compas_occ.conversions import axis_to_compas_vector
>>> axis = gp_Ax2d(gp_Pnt2d(0, 0), gp_Dir2d(1, 0))
>>> axis2d_to_compas_vector(axis)
Vector(x=1.0, y=0.0, z=0.0)

axis_to_compas ¤

axis_to_compas(axis: gp_Ax1) -> tuple[Point, Vector]

Convert an OCC axis to a tuple of COMPAS point and vector.

See Also

Examples:

>>> from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Ax1
>>> from compas_occ.conversions import axis_to_compas
>>> axis = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0))
>>> axis_to_compas(axis)
(Point(x=0.0, y=0.0, z=0.0), Vector(x=1.0, y=0.0, z=0.0))

axis_to_compas_vector ¤

axis_to_compas_vector(axis: gp_Ax1, cls: Type[Vector] | None = None) -> Vector

Convert an OCC axis to a COMPAS vector.

See Also

Examples:

>>> from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Ax1
>>> from compas_occ.conversions import axis_to_compas_vector
>>> axis = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0))
>>> axis_to_compas_vector(axis)
Vector(x=1.0, y=0.0, z=0.0)

axis_to_occ ¤

axis_to_occ(axis: tuple[Point, Vector]) -> gp_Ax1

Convert a COMPAS point and vector to an OCC axis.

See Also

Examples:

>>> from compas.geometry import Point, Vector
>>> from compas_occ.conversions import axis_to_occ
>>> point = Point(0, 0, 0)
>>> vector = Vector(1, 0, 0)
>>> axis_to_occ((point, vector))
<class 'gp_Ax1'>

bezier_to_compas ¤

bezier_to_compas(bezier: Geom_BezierCurve) -> Bezier

Construct a COMPAS Bezier curve from an OCC Bezier curve.

Examples:

>>> from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Ax2, gp_Parab
>>> from compas_occ.conversions import bezier_to_compas
>>> from OCC.Core.Geom import Geom_BezierCurve
>>> from OCC.Core.TColgp import TColgp_Array1OfPnt
>>> from OCC.Core.gp import gp_Pnt
>>> array = TColgp_Array1OfPnt(1, 4)
>>> array.SetValue(1, gp_Pnt(0, 0, 0))
>>> array.SetValue(2, gp_Pnt(1, 0, 0))
>>> array.SetValue(3, gp_Pnt(1, 1, 0))
>>> array.SetValue(4, gp_Pnt(0, 1, 0))
>>> bezier = Geom_BezierCurve(array)
>>> bezier_to_compas(bezier)
Bezier(points=[...])

bspline_to_compas ¤

bspline_to_compas(bspline: Geom_BSplineCurve) -> NurbsCurve

Construct a COMPAS NURBS curve from an OCC B-spline curve.

circle2d_to_compas ¤

circle2d_to_compas(circ: gp_Circ2d, cls: Type[Circle] | None = None) -> Circle

Construct a COMPAS circle from a 2D OCC circle.

See Also

Examples:

>>> from OCC.Core.gp import gp_Pnt2d, gp_Dir2d, gp_Ax22d, gp_Circ2d
>>> from compas_occ.conversions import circle2d_to_compas
>>> ax2 = gp_Ax22d(gp_Pnt2d(0, 0), gp_Dir2d(0, 1), gp_Dir2d(1, 0))
>>> circ = gp_Circ2d(ax2, 1)
>>> circle2d_to_compas(circ)
Circle(radius=1.0, frame=Frame(...)

circle_to_compas ¤

circle_to_compas(circ: gp_Circ, cls: Type[Circle] | None = None) -> Circle

Construct a COMPAS circle from an OCC circle.

See Also

Examples:

>>> from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Ax2, gp_Circ
>>> from compas_occ.conversions import circle_to_compas
>>> ax2 = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
>>> circ = gp_Circ(ax2, 1)
>>> circle_to_compas(circ)
Circle(radius=1.0, frame=Frame(...)

circle_to_occ ¤

circle_to_occ(circle: Circle) -> gp_Circ

Construct an OCC circle from a COMPAS circle.

See Also

Examples:

>>> from compas.geometry import Circle
>>> from compas_occ.conversions import circle_to_occ
>>> circle = Circle(1)
>>> circle_to_occ(circle)
<class 'gp_Circ'>

circle_to_occ2d ¤

circle_to_occ2d(circle: Circle) -> gp_Circ2d

Convert a COMPAS circle to a 2D OCC circle.

See Also

Examples:

>>> from compas.geometry import Circle
>>> from compas_occ.conversions import circle_to_occ2d
>>> circle = Circle(1)
>>> circle_to_occ2d(circle)
<class 'gp_Circ2d'>

compas_mesh_to_occ_shell ¤

compas_mesh_to_occ_shell(mesh: Mesh) -> TopoDS_Shell

Convert a general COMPAS mesh to an OCC shell.

See Also

compas_quadmesh_to_occ_shell ¤

compas_quadmesh_to_occ_shell(mesh: Mesh) -> TopoDS_Shell

Convert a COMPAS quad mesh to an OCC shell.

Raises:

  • ValueError

    If the input mesh is not a quad mesh.

See Also

compas_transformation_to_trsf ¤

compas_transformation_to_trsf(matrix: Transformation) -> gp_Trsf

Convert a COMPAS transformation to a OCC transformation.

Parameters:

Returns:

  • gp_Trsf

    An OCC transformation.

Examples:

>>> from compas.geometry import Translation
>>> from compas_occ.conversions import compas_transformation_to_trsf
>>> transformation = Translation.from_vector([1, 2, 3])
>>> compas_transformation_to_trsf(transformation)
<class 'gp_Trsf'>

compas_trimesh_to_occ_shell ¤

compas_trimesh_to_occ_shell(mesh: Mesh) -> TopoDS_Shell

Convert a COMPAS triangle mesh to an OCC shell.

Raises:

  • ValueError

    If the mesh is not a triangle mesh.

See Also

cone_to_occ ¤

cone_to_occ(cone: Cone) -> gp_Cone

Convert a COMPAS cone to an OCC cone.

See Also

Examples:

>>> from compas.geometry import Cone
>>> from compas_occ.conversions import cone_to_occ
>>> cone = Cone(1, 1)
>>> cone_to_occ(cone)
<class 'gp_Cone'>

cylinder_to_compas ¤

cylinder_to_compas(
    cylinder: gp_Cylinder, cls: Type[Cylinder] | None = None
) -> Cylinder

Convert an OCC cylinder to a COMPAS cylinder.

See Also
  • [compas_sphere_from_occ_sphere][]

Examples:

>>> from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Ax3, gp_Cylinder
>>> from compas_occ.conversions import cylinder_to_compas
>>> ax3 = gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
>>> cylinder = gp_Cylinder(ax3, 1)
>>> cylinder_to_compas(cylinder)
Cylinder(radius=1.0, height=1.0, frame=Frame(...))

cylinder_to_occ ¤

cylinder_to_occ(cylinder: Cylinder) -> gp_Cylinder

Convert a COMPAS cylinder to an OCC cylinder.

See Also

Examples:

>>> from compas.geometry import Cylinder
>>> from compas_occ.conversions import cylinder_to_occ
>>> cylinder = Cylinder(1, 1)
>>> cylinder_to_occ(cylinder)
<class 'gp_Cylinder'>

direction2d_to_compas ¤

direction2d_to_compas(direction: gp_Dir2d, cls: Type[Vector] | None = None) -> Vector

Construct a COMPAS vector from a 2D OCC direction.

See Also

Examples:

>>> from OCC.Core.gp import gp_Dir2d
>>> from compas_occ.conversions import direction2d_to_compas
>>> vector = gp_Dir2d(1, 0)
>>> direction2d_to_compas(vector)
Vector(x=1.0, y=0.0, z=0.0)

direction_to_compas ¤

direction_to_compas(vector: gp_Dir, cls: Type[Vector] | None = None) -> Vector

Construct a COMPAS vector from an OCC direction.

See Also

Examples:

>>> from OCC.Core.gp import gp_Dir
>>> from compas_occ.conversions import direction_to_compas
>>> vector = gp_Dir(1, 0, 0)
>>> direction_to_compas(vector)
Vector(x=1.0, y=0.0, z=0.0)

direction_to_occ ¤

direction_to_occ(vector: Vector) -> gp_Dir

Convert a COMPAS vector to an OCC direction.

See Also

Examples:

>>> from compas.geometry import Vector
>>> from compas_occ.conversions import direction_to_occ
>>> vector = Vector(1, 0, 0)
>>> direction_to_occ(vector)
<class 'gp_Dir'>

direction_to_occ2d ¤

direction_to_occ2d(vector: Vector) -> gp_Dir2d

Convert a COMPAS vector to a 2D OCC direction.

See Also

Examples:

>>> from compas.geometry import Vector
>>> from compas_occ.conversions import direction_to_occ2d
>>> vector = Vector(1, 0, 0)
>>> direction_to_occ2d(vector)
<class 'gp_Dir2d'>

ellipse2d_to_compas ¤

ellipse2d_to_compas(elips: gp_Elips2d, cls: Type[Ellipse] | None = None) -> Ellipse

Construc a COMPAS ellipse from a 2D OCC ellipse.

See Also

Examples:

>>> from OCC.Core.gp import gp_Pnt2d, gp_Dir2d, gp_Ax22d, gp_Elips2d
>>> from compas_occ.conversions import ellipse_to_compas
>>> ax2 = gp_Ax22d(gp_Pnt2d(0, 0), gp_Dir2d(0, 1), gp_Dir2d(1, 0))
>>> elips = gp_Elips2d(ax2, 1, 0.5)
>>> ellipse2d_to_compas(elips)
Ellipse(major=1.0, minor=0.5, frame=Frame(...))

ellipse_to_compas ¤

ellipse_to_compas(elips: gp_Elips, cls: Type[Ellipse] | None = None) -> Ellipse

Construc a COMPAS ellipse from an OCC ellipse.

See Also

Examples:

>>> from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Ax2, gp_Elips
>>> from compas_occ.conversions import ellipse_to_compas
>>> ax2 = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
>>> elips = gp_Elips(ax2, 1, 0.5)
>>> ellipse_to_compas(elips)
Ellipse(major=1.0, minor=0.5, frame=Frame(...))

ellipse_to_occ ¤

ellipse_to_occ(ellipse: Ellipse) -> gp_Elips

Construct an OCC ellipse from a COMPAS ellipse.

See Also

Examples:

>>> from compas.geometry import Ellipse
>>> from compas_occ.conversions import ellipse_to_occ
>>> ellipse = Ellipse(1, 0.5)
>>> ellipse_to_occ(ellipse)
<class 'gp_Elips'>

ellipse_to_occ2d ¤

ellipse_to_occ2d(ellipse: Ellipse) -> gp_Elips2d

Convert a COMPAS ellipse to a 2D OCC ellipse.

See Also

Examples:

>>> from compas.geometry import Ellipse
>>> from compas_occ.conversions import ellipse_to_occ2d
>>> ellipse = Ellipse(1, 0.5)
>>> ellipse_to_occ2d(ellipse)
<class 'gp_Elips2d'>

floats2_from_array2 ¤

floats2_from_array2(array: TColStd_Array2OfReal) -> list[Sequence[float]]

Construct a list of lists of floats from a two-dimensional array of real numbers.

See Also

Examples:

>>> from itertools import product
>>> from OCC.Core.TColStd import TColStd_Array2OfReal
>>> array2 = TColStd_Array2OfReal(1, 2, 1, 3)
>>> array2.SetValue(1, 1, 0.0)
>>> array2.SetValue(1, 2, 1.0)
>>> array2.SetValue(1, 3, 2.0)
>>> array2.SetValue(2, 1, 0.0)
>>> array2.SetValue(2, 2, 1.0)
>>> array2.SetValue(2, 3, 2.0)
>>> floats2 = floats2_from_array2(array2)
>>> floats2
[(0.0, 0.0), (1.0, 1.0), (2.0, 2.0)]

frame_to_occ_ax2 ¤

frame_to_occ_ax2(frame: Frame) -> gp_Ax2

Convert a COMPAS frame to a right-handed OCC coordinate system.

See Also

Examples:

>>> from compas.geometry import Frame
>>> from compas_occ.conversions import frame_to_occ_ax2
>>> frame = Frame.worldXY()
>>> frame_to_occ_ax2(frame)
<class 'gp_Ax2'>

frame_to_occ_ax22d ¤

frame_to_occ_ax22d(frame: Frame) -> gp_Ax22d

Convert a COMPAS frame to a 2D right-handed OCC coordinate system.

Examples:

>>> from compas.geometry import Frame
>>> from compas_occ.conversions import frame_to_occ_ax22d
>>> frame = Frame.worldXY()
>>> frame_to_occ_ax22d(frame)
<class 'gp_Ax22d'>

frame_to_occ_ax3 ¤

frame_to_occ_ax3(frame: Frame) -> gp_Ax3

Convert a COMPAS frame to a right-handed OCC coordinate system.

See Also

Examples:

>>> from compas.geometry import Frame
>>> from compas_occ.conversions import frame_to_occ_ax3
>>> frame = Frame.worldXY()
>>> frame_to_occ_ax3(frame)
<class 'gp_Ax3'>

harray1_from_points1 ¤

harray1_from_points1(points: list[Point]) -> TColgp_HArray1OfPnt

Construct a horizontal one-dimensional point array from a list of points.

See Also

Examples:

>>> from compas.geometry import Point
>>> from compas_occ.conversions import harray1_from_points1
>>> points1 = [Point(0, 0, 0), Point(1, 0, 0), Point(2, 0, 0)]
>>> harray1 = harray1_from_points1(points1)
>>> harray1
<OCC.Core.TColgp.TColgp_HArray1OfPnt; ... >
>>> for item in harray1:
...     print(item)
<class 'gp_Pnt'>
<class 'gp_Pnt'>
<class 'gp_Pnt'>
>>> for item in harray1:
...     print(item.X(), item.Y(), item.Z())
0.0 0.0 0.0
1.0 0.0 0.0
2.0 0.0 0.0

hyperbola2d_to_compas ¤

hyperbola2d_to_compas(hypr: gp_Hypr2d) -> Hyperbola

Construct a COMPAS hyperbola from a 2D OCC hyperbola.

Examples:

>>> from OCC.Core.gp import gp_Pnt2d, gp_Dir2d, gp_Ax22d, gp_Hypr2d
>>> from compas_occ.conversions import hyperbola_to_compas
>>> ax2 = gp_Ax22d(gp_Pnt2d(0, 0), gp_Dir2d(0, 1), gp_Dir2d(1, 0))
>>> hypr = gp_Hypr2d(ax2, 1, 0.5)
>>> hyperbola2d_to_compas(hypr)
Hyperbola(major=1.0, minor=0.5, frame=Frame(...))

hyperbola_to_compas ¤

hyperbola_to_compas(hypr: gp_Hypr) -> Hyperbola

Construct a COMPAS hyperbola from an OCC hyperbola.

Examples:

>>> from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Ax2, gp_Hypr
>>> from compas_occ.conversions import hyperbola_to_compas
>>> ax2 = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
>>> hypr = gp_Hypr(ax2, 1, 0.5)
>>> hyperbola_to_compas(hypr)
Hyperbola(major=1.0, minor=0.5, frame=Frame(...))

line2d_to_compas ¤

line2d_to_compas(lin: gp_Lin2d, cls: Type[Line] | None = None) -> Line

Convert a 2D OCC line to a COMPAS line.

See Also

line_to_occ2d

Examples:

>>> from OCC.Core.gp import gp_Pnt2d, gp_Dir2d, gp_Lin2d
>>> from compas_occ.conversions import line2d_to_compas
>>> line = gp_Lin2d(gp_Pnt2d(0, 0), gp_Dir2d(1, 0))
>>> line2d_to_compas(line)
Line(Point(x=0.0, y=0.0, z=0.0), Point(x=1.0, y=0.0, z=0.0))

line_to_compas ¤

line_to_compas(lin: gp_Lin, cls: Type[Line] | None = None) -> Line

Convert an OCC line to a COMPAS line.

See Also

Examples:

>>> from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Lin
>>> from compas_occ.conversions import line_to_compas
>>> line = gp_Lin(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0))
>>> line_to_compas(line)
Line(Point(x=0.0, y=0.0, z=0.0), Point(x=1.0, y=0.0, z=0.0))

line_to_occ ¤

line_to_occ(line: Line) -> gp_Lin

Convert a COMPAS line to an OCC line.

See Also

Examples:

>>> from compas.geometry import Line
>>> from compas_occ.conversions import line_to_occ
>>> line = Line([0, 0, 0], [1, 0, 0])
>>> line_to_occ(line)
<class 'gp_Lin'>

line_to_occ2d ¤

line_to_occ2d(line: Line) -> gp_Lin2d

Convert a COMPAS line to a 2D OCC line.

See Also
  • [axis_to_occ2d][]

Examples:

>>> from compas.geometry import Line
>>> from compas_occ.conversions import line_to_occ2d
>>> line = Line([0, 0, 0], [1, 0, 0])
>>> line_to_occ2d(line)
<class 'gp_Lin2d'>

location_to_compas ¤

location_to_compas(location: TopLoc_Location) -> Frame

Construct a COMPAS frame from an OCC location.

Examples:

>>> from OCC.Core.TopLoc import TopLoc_Location
>>> from compas_occ.conversions import location_to_compas
>>> location = TopLoc_Location()
>>> location_to_compas(location)
Frame(point=Point(x=0.0, y=0.0, z=0.0), xaxis=Vector(x=1.0, y=0.0, z=0.0), yaxis=Vector(x=0.0, y=1.0, z=0.0))

ngon_to_face ¤

ngon_to_face(ngon: NGon) -> TopoDS_Face

Convert a Ngon to a BRep face with an underlying best-fit surface.

See Also

obb_to_compas ¤

obb_to_compas(obb: Bnd_OBB) -> Box

Convert an OCC oriented bounding box to a COMPAS box.

parabola2d_to_compas ¤

parabola2d_to_compas(parab: gp_Parab2d) -> Parabola

Construct a COMPAS parabola from a 2D OCC parabola.

Examples:

>>> from OCC.Core.gp import gp_Pnt2d, gp_Dir2d, gp_Ax22d, gp_Parab2d
>>> from compas_occ.conversions import parabola_to_compas
>>> ax2 = gp_Ax22d(gp_Pnt2d(0, 0), gp_Dir2d(0, 1), gp_Dir2d(1, 0))
>>> parab = gp_Parab2d(ax2, 1)
>>> parabola2d_to_compas(parab)
Parabola(focal=2.0, frame=Frame(...))

parabola_to_compas ¤

parabola_to_compas(parab: gp_Parab) -> Parabola

Construct a COMPAS parabola from an OCC parabola.

Examples:

>>> from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Ax2, gp_Parab
>>> from compas_occ.conversions import parabola_to_compas
>>> ax2 = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
>>> parab = gp_Parab(ax2, 1)
>>> parabola_to_compas(parab)
Parabola(focal=2.0, frame=Frame(...))

plane_to_compas ¤

plane_to_compas(pln: gp_Pln, cls: Type[Plane] | None = None) -> Plane

Convert an OCC plane to a COMPAS plane.

See Also

Examples:

>>> from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Pln
>>> from compas_occ.conversions import plane_to_compas
>>> plane = gp_Pln(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
>>> plane_to_compas(plane)
Plane(point=Point(x=0.0, y=0.0, z=0.0), normal=Vector(x=0.0, y=0.0, z=1.0))

plane_to_occ ¤

plane_to_occ(plane: Plane) -> gp_Pln

Convert a COMPAS plane to an OCC plane.

See Also

Examples:

>>> from compas.geometry import Plane
>>> from compas_occ.conversions import plane_to_occ
>>> plane = Plane([0, 0, 0], [0, 0, 1])
>>> plane_to_occ(plane)
<class 'gp_Pln'>

plane_to_occ_ax2 ¤

plane_to_occ_ax2(plane: Plane) -> gp_Ax2

Convert a COMPAS plane to a right-handed OCC coordinate system.

See Also

Examples:

>>> from compas.geometry import Plane
>>> from compas_occ.conversions import plane_to_occ_ax2
>>> plane = Plane([0, 0, 0], [0, 0, 1])
>>> plane_to_occ_ax2(plane)
<class 'gp_Ax2'>

plane_to_occ_ax3 ¤

plane_to_occ_ax3(plane: Plane) -> gp_Ax3

Convert a COMPAS plane to a right-handed OCC coordinate system.

See Also

Examples:

>>> from compas.geometry import Plane
>>> from compas_occ.conversions import plane_to_occ_ax3
>>> plane = Plane([0, 0, 0], [0, 0, 1])
>>> plane_to_occ_ax3(plane)
<class 'gp_Ax3'>

point2d_to_compas ¤

point2d_to_compas(point: gp_Pnt2d, cls: Type[Point] | None = None) -> Point

Construct a COMPAS point from an OCC 2D point.

See Also

Examples:

>>> from OCC.Core.gp import gp_Pnt2d
>>> from compas_occ.conversions import point2d_to_compas
>>> point = gp_Pnt2d(0, 0)
>>> point2d_to_compas(point)
Point(x=0.0, y=0.0, z=0.0)

point_to_compas ¤

point_to_compas(point: gp_Pnt, cls: Type[Point] | None = None) -> Point

Construct a COMPAS point from an OCC point.

See Also

Examples:

>>> from OCC.Core.gp import gp_Pnt
>>> from compas_occ.conversions import point_to_compas
>>> point = gp_Pnt(0, 0, 0)
>>> point_to_compas(point)
Point(x=0.0, y=0.0, z=0.0)

point_to_occ ¤

point_to_occ(point: Point) -> gp_Pnt

Convert a COMPAS point to an OCC point.

Examples:

>>> from compas.geometry import Point
>>> from compas_occ.conversions import point_to_occ
>>> point = Point(0, 0, 0)
>>> point_to_occ(point)
<class 'gp_Pnt'>

point_to_occ2d ¤

point_to_occ2d(point: Point) -> gp_Pnt2d

Convert a COMPAS point to a 2D OCC point.

Examples:

>>> from compas.geometry import Point
>>> from compas_occ.conversions import point_to_occ2d
>>> point = Point(0, 0, 0)
>>> point_to_occ2d(point)
<class 'gp_Pnt2d'>

points1_from_array1 ¤

points1_from_array1(array: TColgp_Array1OfPnt) -> list[Point]

Construct a list of points from a one-dimensional point array.

See Also

Examples:

>>> from compas_occ.conversions import points1_from_array1
>>> from OCC.Core.TColgp import TColgp_Array1OfPnt
>>> from OCC.Core.gp import gp_Pnt
>>> array1 = TColgp_Array1OfPnt(1, 3)
>>> array1.SetValue(1, gp_Pnt(0, 0, 0))
>>> array1.SetValue(2, gp_Pnt(1, 0, 0))
>>> array1.SetValue(3, gp_Pnt(2, 0, 0))
>>> points1 = points1_from_array1(array1)
>>> for point in points1:
...     print(point)
Point(x=0.0, y=0.0, z=0.0)
Point(x=1.0, y=0.0, z=0.0)
Point(x=2.0, y=0.0, z=0.0)

points2_from_array2 ¤

points2_from_array2(array: TColgp_Array2OfPnt) -> list[list[Point]]

Construct a list of lists of points from two-dimensional point array.

See Also

Examples:

>>> from itertools import product
>>> from OCC.Core.TColgp import TColgp_Array2OfPnt
>>> from OCC.Core.gp import gp_Pnt
>>> array2 = TColgp_Array2OfPnt(1, 2, 1, 3)
>>> array2.SetValue(1, 1, gp_Pnt(0, 0, 0))
>>> array2.SetValue(1, 2, gp_Pnt(1, 0, 0))
>>> array2.SetValue(1, 3, gp_Pnt(2, 0, 0))
>>> array2.SetValue(2, 1, gp_Pnt(0, 1, 0))
>>> array2.SetValue(2, 2, gp_Pnt(1, 1, 0))
>>> array2.SetValue(2, 3, gp_Pnt(2, 1, 0))
>>> points2 = points2_from_array2(array2)
>>> rows = len(points2)
>>> cols = len(points2[0])
>>> for i, j in product(range(rows), range(cols)):
...     print(points2[i][j])
Point(x=0.0, y=0.0, z=0.0)
Point(x=0.0, y=1.0, z=0.0)
Point(x=1.0, y=0.0, z=0.0)
Point(x=1.0, y=1.0, z=0.0)
Point(x=2.0, y=0.0, z=0.0)
Point(x=2.0, y=1.0, z=0.0)

quad_to_face ¤

quad_to_face(quad: Quad) -> TopoDS_Face

Convert a quad to a BRep face with an underlying ruled surface.

Raises:

  • ValueError

    If the number of points is not 4.

See Also

Examples:

>>> quad = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]]
>>> quad_to_face(quad)
<class 'TopoDS_Face'>

sphere_to_compas ¤

sphere_to_compas(sphere: gp_Sphere, cls: Type[Sphere] | None = None) -> Sphere

Convert an OCC sphere to a COMPAS sphere.

See Also

Examples:

>>> from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Ax3, gp_Sphere
>>> from compas_occ.conversions import sphere_to_compas
>>> ax3 = gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
>>> sphere = gp_Sphere(ax3, 1)
>>> sphere_to_compas(sphere)
Sphere(radius=1.0, frame=Frame(...))

sphere_to_occ ¤

sphere_to_occ(sphere: Sphere) -> gp_Sphere

Convert a COMPAS sphere to an OCC sphere.

See Also

Examples:

>>> from compas.geometry import Sphere
>>> from compas_occ.conversions import sphere_to_occ
>>> sphere = Sphere(1)
>>> sphere_to_occ(sphere)
<class 'gp_Sphere'>

torus_to_occ ¤

torus_to_occ(torus: Torus) -> gp_Torus

Convert a COMPAS torus to an OCC torus.

See Also

Examples:

>>> from compas.geometry import Torus
>>> from compas_occ.conversions import torus_to_occ
>>> torus = Torus(1, 0.5)
>>> torus_to_occ(torus)
<class 'gp_Torus'>

triangle_to_face ¤

triangle_to_face(triangle: Triangle) -> TopoDS_Face

Convert a triangle to a BRep face.

Raises:

  • ValueError

    If the number of points is not 3.

See Also

Examples:

>>> triangle = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
>>> triangle_to_face(triangle)
<class 'TopoDS_Face'>

vector2d_to_compas ¤

vector2d_to_compas(vector: gp_Vec2d, cls: Type[Vector] | None = None) -> Vector

Construct a COMPAS vector from an OCC 2D vector.

See Also

Examples:

>>> from OCC.Core.gp import gp_Vec2d
>>> from compas_occ.conversions import vector2d_to_compas
>>> vector = gp_Vec2d(1, 0)
>>> vector2d_to_compas(vector)
Vector(x=1.0, y=0.0, z=0.0)

vector_to_compas ¤

vector_to_compas(vector: gp_Vec, cls: Type[Vector] | None = None) -> Vector

Construct a COMPAS vector from an OCC vector.

See Also

Examples:

>>> from OCC.Core.gp import gp_Vec
>>> from compas_occ.conversions import vector_to_compas
>>> vector = gp_Vec(1, 0, 0)
>>> vector_to_compas(vector)
Vector(x=1.0, y=0.0, z=0.0)

vector_to_occ ¤

vector_to_occ(vector: Vector) -> gp_Vec

Convert a COMPAS vector to an OCC vector.

See Also

Examples:

>>> from compas.geometry import Vector
>>> from compas_occ.conversions import vector_to_occ
>>> vector = Vector(1, 0, 0)
>>> vector_to_occ(vector)
<class 'gp_Vec'>

vector_to_occ2d ¤

vector_to_occ2d(vector: Vector) -> gp_Vec2d

Convert a COMPAS vector to a 2D OCC vector.

See Also

Examples:

>>> from compas.geometry import Vector
>>> from compas_occ.conversions import vector_to_occ2d
>>> vector = Vector(1, 0, 0)
>>> vector_to_occ2d(vector)
<class 'gp_Vec2d'>