From ec9d028c60f4f1940d6ee5b3626dd510b0a2f4c3 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Thu, 8 Jun 2023 16:38:34 +0300 Subject: [PATCH] ellipsoid --- libsrc/occ/python_occ_basic.cpp | 8 ++++++++ libsrc/occ/python_occ_shapes.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/libsrc/occ/python_occ_basic.cpp b/libsrc/occ/python_occ_basic.cpp index 9768a22d..56322b39 100644 --- a/libsrc/occ/python_occ_basic.cpp +++ b/libsrc/occ/python_occ_basic.cpp @@ -151,6 +151,11 @@ DLL_HEADER void ExportNgOCCBasic(py::module &m) .def(py::init([](gp_Pnt p, gp_Dir N, gp_Dir Vx) { return gp_Ax3(p,N, Vx); }), py::arg("p")=gp_Pnt(0,0,0), py::arg("n")=gp_Vec(0,0,1), py::arg("h")=gp_Vec(1,0,0)) + .def(py::init([](gp_Ax1 ax1) { + gp_Ax3 ax; + ax.SetAxis(ax1); + return ax; + }), py::arg("axis")) .def(py::init()) .def_property("p", [](gp_Ax3 & ax) { return ax.Location(); }, [](gp_Ax3&ax, gp_Pnt p) { ax.SetLocation(p); }) ; @@ -363,6 +368,9 @@ DLL_HEADER void ExportNgOCCBasic(py::module &m) py::implicitly_convertible(); py::implicitly_convertible(); py::implicitly_convertible(); + + py::implicitly_convertible(); + py::implicitly_convertible(); py::implicitly_convertible(); diff --git a/libsrc/occ/python_occ_shapes.cpp b/libsrc/occ/python_occ_shapes.cpp index 29c3320c..9bd1aa8d 100644 --- a/libsrc/occ/python_occ_shapes.cpp +++ b/libsrc/occ/python_occ_shapes.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -1815,9 +1816,32 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m) BRepPrimAPI_MakeHalfSpace builder(face, refpnt); return builder.Shape(); }, py::arg("p"), py::arg("n"), "Create a half space threw point p normal to n"); + m.def("Sphere", [] (gp_Pnt cc, double r) { return BRepPrimAPI_MakeSphere (cc, r).Solid(); }, py::arg("c"), py::arg("r"), "create sphere with center 'c' and radius 'r'"); + + m.def("Ellipsoid", [] (gp_Ax3 ax, double r1, double r2, optional hr3) { + auto sp = BRepPrimAPI_MakeSphere (gp_Pnt(0,0,0), 1).Solid(); + + gp_GTrsf gtrafo; + double r3 = hr3.value_or(r2); + gtrafo.SetVectorialPart({ r2, 0, 0, 0, r3, 0, 0, 0, r1 }); + gtrafo.SetTranslationPart( { 0.0, 0.0, 0.0 } ); + + BRepBuilderAPI_GTransform gbuilder(sp, gtrafo, true); + PropagateProperties(gbuilder, sp, occ2ng(gtrafo)); + + auto gsp = gbuilder.Shape(); + + gp_Trsf trafo; + trafo.SetTransformation(ax, gp_Ax3()); + BRepBuilderAPI_Transform builder(gsp, trafo, true); + PropagateProperties(builder, gsp, occ2ng(trafo)); + return builder.Shape(); + }, py::arg("axes"), py::arg("r1"), py::arg("r2"), py::arg("r3")=std::nullopt, + "create ellipsoid with local coordinates given by axes, radi 'r1', 'r2', 'r3'"); + m.def("Cylinder", [] (gp_Pnt cpnt, gp_Dir cdir, double r, double h, optional bot, optional top, optional mantle) {