Skip to content

Commit

Permalink
cylinder from_line_radius
Browse files Browse the repository at this point in the history
  • Loading branch information
yck011522 committed Sep 29, 2023
1 parent 1fc963e commit cf356c7
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/compas/geometry/shapes/cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from compas.geometry import Circle
from compas.geometry import Frame
from compas.geometry import Plane
from compas.geometry import Vector

from ._shape import Shape

Expand Down Expand Up @@ -207,6 +208,36 @@ def __iter__(self):
# constructors
# ==========================================================================

@classmethod
def from_line_radius(cls, line, radius):
"""Construct a box from its width, height and depth.
Note that width is along the X-axis, height along Z-axis, and depth along the Y-axis.
Parameters
----------
line : :class:`compas.geometry.Line`
Center line of the cylinder.
radius : float
Diameter of the cylinder.
Returns
-------
Cylinder
The constructed cylinder.
Notes
-----
`cylinder.circle` is located at the mid point of the cylinder.
"""
radius = float(radius)
normal = Vector.from_start_end(line.start, line.end)
circle = Circle(Plane(line.point(0.5), normal), radius)

return cls(circle, line.length)


# ==========================================================================
# methods
# ==========================================================================
Expand Down

0 comments on commit cf356c7

Please sign in to comment.