Skip to content

Commit

Permalink
New release & centroid frames prop and classmethod in ClayBullet
Browse files Browse the repository at this point in the history
Closes #28
  • Loading branch information
tetov committed Feb 14, 2020
1 parent 3f0940c commit b5fc0ea
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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\]

Expand Down
71 changes: 64 additions & 7 deletions src/compas_rcf/fabrication/clay_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
):
Expand Down Expand Up @@ -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."""
Expand All @@ -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):
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/compas_rcf/utils/util_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

0 comments on commit b5fc0ea

Please sign in to comment.