Skip to content

Adding rotate for Shape #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/formo/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ Point rotate(const Point & point, const Axis1 & axis, double angle);
/// @return Resulting vector
Vector rotate(const Vector & vector, const Axis1 & axis, double angle);

/// Rotate a shape about an axis
///
/// @param shape Shape to rotate
/// @param axis Axis to rotate about
/// @param angle Rotation angle (in radians)
/// @return Resulting `Shape`
Shape rotate(const Shape & point, const Axis1 & axis, double angle);

/// Compute section between a shape and a plane
///
/// @param shape Shape
Expand Down
2 changes: 2 additions & 0 deletions python/src/formo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ PYBIND11_MODULE(formo, m)
py::arg("point"), py::arg("axis"), py::arg("angle"));
m.def("rotate", py::overload_cast<const Vector &, const Axis1 &, double>(&rotate),
py::arg("point"), py::arg("axis1"), py::arg("angle"));
m.def("rotate", py::overload_cast<const Shape &, const Axis1 &, double>(&rotate),
py::arg("shape"), py::arg("axis1"), py::arg("angle"));

m.def("section", py::overload_cast<const Shape &, const Plane &>(&section),
py::arg("shape"), py::arg("plane"));
Expand Down
6 changes: 6 additions & 0 deletions python/tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ def test_sweep():
profile = formo.Face(formo.Wire([ circ ]));

shape = formo.sweep(profile, path);


def test_rotate_shape():
box = formo.Box(formo.Point(0, 0, 0), formo.Point(1, 1, 1))
ax1 = formo.Axis1(formo.Point(0, 0, 0), formo.Direction(0, 0, 1))
box = formo.rotate(box, ax1, 45)
9 changes: 9 additions & 0 deletions src/operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ rotate(const Vector & vector, const Axis1 & axis, double angle)
return Vector(res.X(), res.Y(), res.Z());
}

Shape
rotate(const Shape & shape, const Axis1 & axis, double angle)
{
gp_Trsf trsf;
trsf.SetRotation(axis, angle);
BRepBuilderAPI_Transform brep_trsf(shape, trsf);
return Shape(brep_trsf.Shape());
}

Wire
section(const Shape & shape, const Plane & plane)
{
Expand Down
6 changes: 6 additions & 0 deletions test/src/Operations_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ TEST(OperationsTest, rotate_pnt)
EXPECT_DOUBLE_EQ(b.z(), 0.);
}

TEST(OperationsTest, rotate_shape)
{
Box a(Point(2, 0, 0), Point(3, 2, 3));
auto b = rotate(a, Axis1(Point(0, 0, 0), Direction(0, 0, 1)), radians(45));
}

TEST(OperationsTest, section)
{
Box box1(Point(0, 0, 0), Point(1, 2, 3));
Expand Down