Skip to content

Commit 79fd87d

Browse files
committed
frame from position
1 parent e62c5d6 commit 79fd87d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/compas_occ/interop/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
compas_vector_to_occ_direction
3535
compas_vector_from_occ_vector
3636
compas_line_to_occ_line
37+
compas_frame_from_occ_position
3738
3839
Meshes
3940
======
@@ -66,6 +67,7 @@
6667
from .primitives import compas_vector_to_occ_direction # noqa: F401
6768
from .primitives import compas_vector_from_occ_vector # noqa: F401
6869
from .primitives import compas_line_to_occ_line # noqa: F401
70+
from .primitives import compas_frame_from_occ_position # noqa: F401
6971

7072
from .meshes import triangle_to_face # noqa: F401
7173
from .meshes import quad_to_face # noqa: F401

src/compas_occ/interop/primitives.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from compas.geometry import Point
44
from compas.geometry import Vector
55
from compas.geometry import Line
6+
from compas.geometry import Frame
67

8+
from OCC.Core.gp import gp_Ax3
79
from OCC.Core.gp import gp_Pnt
810
from OCC.Core.gp import gp_Vec
911
from OCC.Core.gp import gp_Dir
@@ -35,6 +37,20 @@ def compas_vector_to_occ_direction(self: Vector) -> gp_Dir:
3537
return gp_Dir(* self)
3638

3739

40+
def compas_vector_from_occ_direction(cls: Vector, vector: gp_Dir) -> Vector:
41+
"""Construct a COMPAS vector from an OCC direction."""
42+
return cls(vector.X(), vector.Y(), vector.Z())
43+
44+
3845
def compas_line_to_occ_line(self: Line) -> gp_Lin:
3946
"""Convert a COMPAS line to an OCC line."""
4047
return gp_Lin(compas_point_to_occ_point(self.start), compas_vector_to_occ_direction(self.direction))
48+
49+
50+
def compas_frame_from_occ_position(cls: Frame, position: gp_Ax3) -> Frame:
51+
"""Construct a COMPAS frame from an OCC position."""
52+
return cls(
53+
compas_point_from_occ_point(Point, position.Location()),
54+
compas_vector_from_occ_direction(Vector, position.XDirection()),
55+
compas_vector_from_occ_direction(Vector, position.YDirection())
56+
)

0 commit comments

Comments
 (0)