From b5fc0ea6e815fc8d038bf7c0d88e1a6f4aace6dd Mon Sep 17 00:00:00 2001 From: tetov Date: Fri, 14 Feb 2020 13:30:20 +0100 Subject: [PATCH] New release & centroid frames prop and classmethod in ClayBullet Closes #28 --- CHANGELOG.md | 5 ++ src/compas_rcf/fabrication/clay_obj.py | 71 +++++++++++++++++++++++--- src/compas_rcf/utils/util_funcs.py | 8 +-- 3 files changed, 73 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b398e74..b0c6d7ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## \[0.1.13\] \[2020-10-14\] +### Added +* Properties `centroid_frame`, `compressed_centroid_frame`, `centroid_plane` added `compressed_centroid_plane` to `compas_rcf.fabrication.clay_objs.ClayBullet`. +* Classmethod `from_compressed_centroid_frame_like` added to `ClayBullet`. + ### Changed - `compas_rcf.fabrication.abb_rcf_runner` renamed to `compas_rcf.fabrication.abb_runner`. - Typos in `abb_runner` fixed. - Trying to set up imports better between modules - Fixes for tkinter file dialog in `compas_rcf.utils.ui`. +* Property `post_planes` renamed to `trajectory_from` in `ClayBullet`. ## \[0.1.12\] \[2020-10-13\] diff --git a/src/compas_rcf/fabrication/clay_obj.py b/src/compas_rcf/fabrication/clay_obj.py index b03d85a4..8c36a947 100755 --- a/src/compas_rcf/fabrication/clay_obj.py +++ b/src/compas_rcf/fabrication/clay_obj.py @@ -15,6 +15,7 @@ from compas_rcf.utils import ensure_frame from compas_rcf.utils import list_elem_w_index_wrap +from compas_rcf.utils import get_offset_frame from compas_rcf.utils.compas_to_rhino import cgframe_to_rgplane if IPY: @@ -47,9 +48,9 @@ def __init__( trajectory_to=[], trajectory_from=[], id=None, - radius=40, - height=200, - compression_ratio=1, + radius=45, + height=100, + compression_ratio=.5, precision=5, tool=None, ): @@ -134,6 +135,16 @@ def trajectory_from(self, frame_list): frame = ensure_frame(frame_like) self._trajectory_from.append(frame) + @property + def centroid_frame(self): + """Get frame at middle of uncompressed bullet.""" + return get_offset_frame(self.location, self.height) + + @property + def compressed_centroid_frame(self): + """Get frame at middle of compressed bullet.""" + return get_offset_frame(self.location, self.compressed_height) + @property def plane(self): """For Compatibility with older scripts.""" @@ -160,24 +171,44 @@ def placement_plane(self): return cgframe_to_rgplane(self.placement_frame) @property - def pre_planes(self): + def trajectory_to_planes(self): """Rhino.Geometry.Plane representations of pre frames. Returns ------- - Rhino.Geometry.Plane + list of Rhino.Geometry.Plane """ return [cgframe_to_rgplane(frame) for frame in self.trajectory_to] @property - def post_planes(self): + def trajectory_from_planes(self): """Rhino.Geometry.Plane representation of pre frames. + Returns + ------- + list of Rhino.Geometry.Plane + """ + return [cgframe_to_rgplane(frame) for frame in self.trajectory_from] + + @property + def centroid_plane(self): + """Get plane at middle of uncompressed bullet. + Returns ------- Rhino.Geometry.Plane """ - return [cgframe_to_rgplane(frame) for frame in self.post_planes] + return cgframe_to_rgplane(self.centroid_frame) + + @property + def compressed_centroid_plane(self): + """Get plane at middle of compressed bullet. + + Returns + ------- + Rhino.Geometry.Plane + """ + return cgframe_to_rgplane(self.centroid_frame) @property def volume(self): @@ -280,6 +311,32 @@ def from_data(cls, data): **kwargs, ) + @classmethod + def from_compressed_centroid_frame_like(cls, centroid_frame_like, compression_ratio=.5, height=100, kwargs={}): + """Construct a :class:`ClayBullet` instance from centroid plane. + + Parameters + ---------- + centroid_frame_like : compas.geometry.Frame or Rhino.Geometry.Plane + frame between bottom of clay bullet and compressed top + compression_ratio : float + The compressed height as a percentage of the original height + height : float + The height of the bullet before compression + kwargs + Other attributes + + Returns + ------- + :class:`ClayBullet` + The constructed ClayBullet instance + """ + centroid_frame = ensure_frame(centroid_frame_like) + compressed_height = height * compression_ratio + location = get_offset_frame(centroid_frame, -compressed_height / 2) + + return cls(location, compression_ratio=compression_ratio, height=height, **kwargs) + def generate_mesh(self, face_count=18): """Generate mesh representation of bullet with custom resolution. diff --git a/src/compas_rcf/utils/util_funcs.py b/src/compas_rcf/utils/util_funcs.py index 50cb2c33..6195107c 100644 --- a/src/compas_rcf/utils/util_funcs.py +++ b/src/compas_rcf/utils/util_funcs.py @@ -163,12 +163,12 @@ def ensure_frame(frame_like): ) -def get_offset_frame(origin_frame, distance): +def get_offset_frame(frame, distance): """Offset a frame in its Z axis direction. Parameters ---------- - origin_frame : `class`:compas.geometry.Frame + frame : `class`:compas.geometry.Frame Frame to offset distance : float Translation distance in mm @@ -177,7 +177,7 @@ def get_offset_frame(origin_frame, distance): ------- `class`:compas.geometry.Frame """ - offset_vector = origin_frame.zaxis * distance * -1 + offset_vector = frame.zaxis * distance * -1 T = cg.Translation(offset_vector) - return origin_frame.transformed(T) + return frame.transformed(T)