Skip to content
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

Frame inversion #1415

Merged
merged 7 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

* Added implementation of `RhinoBrep.fillet()` and `RhinoBrep.filleted()` to `compas_rhino`.
* Added `Frame.invert` and `Frame.inverted`.

### Changed

Expand Down
12 changes: 12 additions & 0 deletions src/compas/geometry/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,18 @@ def to_transformation(self):
# Methods
# ==========================================================================

def invert(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure but should this be maybe called flip?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in Vector it is also invert, but we can add an alias in both perhaps

"""Invert the frame while keeping the X axis fixed."""
self._yaxis = self.yaxis * -1
self._zaxis = None

def inverted(self):
"""Return an inverted copy of the frame."""
frame = self.copy() # type: Frame
frame.invert()
print(frame.xaxis, frame.yaxis, frame.zaxis)
tomvanmele marked this conversation as resolved.
Show resolved Hide resolved
return frame

def interpolate_frame(self, other, t):
"""Interpolates between two frames at a given parameter t in the range [0, 1]

Expand Down
32 changes: 32 additions & 0 deletions tests/compas/geometry/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,35 @@ def test_interpolate_frame_start_end():

three_quarter_frame = frame1.interpolate_frame(frame2, 0.75)
assert TOL.is_allclose([math.degrees(three_quarter_frame.axis_angle_vector.y)], [-67.5], atol=TOL.angular)


def test_frame_invert():
frame = Frame([0, 0, 0])

assert TOL.is_close(frame.xaxis.dot([1, 0, 0]), 1.0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just out of curiosity what's the advantage of this over TOL.is_allclose(frame.xaxis, [1, 0, 0])

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no advantage. am just used to expressing this using dot

assert TOL.is_close(frame.yaxis.dot([0, 1, 0]), 1.0)
assert TOL.is_close(frame.zaxis.dot([0, 0, 1]), 1.0)

frame.invert()

assert TOL.is_close(frame.xaxis.dot([1, 0, 0]), 1.0)
assert TOL.is_close(frame.yaxis.dot([0, -1, 0]), 1.0)
assert TOL.is_close(frame.zaxis.dot([0, 0, -1]), 1.0)


def test_frame_inverted():
frame = Frame([0, 0, 0])

assert TOL.is_close(frame.xaxis.dot([1, 0, 0]), 1.0)
assert TOL.is_close(frame.yaxis.dot([0, 1, 0]), 1.0)
assert TOL.is_close(frame.zaxis.dot([0, 0, 1]), 1.0)

other = frame.inverted()

assert TOL.is_close(frame.xaxis.dot([1, 0, 0]), 1.0)
assert TOL.is_close(frame.yaxis.dot([0, 1, 0]), 1.0)
assert TOL.is_close(frame.zaxis.dot([0, 0, 1]), 1.0)

assert TOL.is_close(other.xaxis.dot([1, 0, 0]), 1.0)
assert TOL.is_close(other.yaxis.dot([0, -1, 0]), 1.0)
assert TOL.is_close(other.zaxis.dot([0, 0, -1]), 1.0)
Loading