|
3 | 3 | from compas.geometry import Point |
4 | 4 | from compas.geometry import Vector |
5 | 5 | from compas.geometry import Line |
| 6 | +from compas.geometry import Frame |
6 | 7 |
|
| 8 | +from OCC.Core.gp import gp_Ax3 |
7 | 9 | from OCC.Core.gp import gp_Pnt |
8 | 10 | from OCC.Core.gp import gp_Vec |
9 | 11 | from OCC.Core.gp import gp_Dir |
@@ -35,6 +37,20 @@ def compas_vector_to_occ_direction(self: Vector) -> gp_Dir: |
35 | 37 | return gp_Dir(* self) |
36 | 38 |
|
37 | 39 |
|
| 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 | + |
38 | 45 | def compas_line_to_occ_line(self: Line) -> gp_Lin: |
39 | 46 | """Convert a COMPAS line to an OCC line.""" |
40 | 47 | 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