-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #249 from ajhynes7/add_cylinder_class
Add Cylinder class
- Loading branch information
Showing
23 changed files
with
706 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
skspatial.objects.Cylinder | ||
========================== | ||
|
||
.. autoclass:: skspatial.objects.Cylinder | ||
|
||
|
||
Methods | ||
------- | ||
.. autosummary:: | ||
:toctree: Cylinder/methods | ||
|
||
~skspatial.objects.Cylinder.from_points | ||
~skspatial.objects.Cylinder.is_point_within | ||
~skspatial.objects.Cylinder.length | ||
~skspatial.objects.Cylinder.plot_3d | ||
~skspatial.objects.Cylinder.to_mesh | ||
~skspatial.objects.Cylinder.volume |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Cylinder | ||
-------- | ||
|
||
A :class:`~skspatial.objects.Cylinder` object is defined by a point, a vector, and a radius. | ||
|
||
The point is the centre of the cylinder base. The vector is normal to the base, and the length of the cylinder is the length of this vector. | ||
The point and vector must be 3D. | ||
|
||
>>> from skspatial.objects import Cylinder | ||
|
||
>>> cylinder = Cylinder(point=[0, 0, 0], vector=[0, 0, 5], radius=1) | ||
|
||
>>> cylinder | ||
Cylinder(point=Point([0, 0, 0]), vector=Vector([0, 0, 5]), radius=1) | ||
|
||
>>> cylinder.length() | ||
5.0 | ||
|
||
>>> cylinder.volume().round(3) | ||
15.708 | ||
|
||
You can check if a point is inside (or on the surface of) the cylinder. | ||
|
||
>>> cylinder.is_point_within([0, 0, 0]) | ||
True | ||
>>> cylinder.is_point_within([0, 0, 5]) | ||
True | ||
>>> cylinder.is_point_within([1, 0, 3]) | ||
True | ||
>>> cylinder.is_point_within([2, 0, 3]) | ||
False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Mixin classes.""" | ||
|
||
from typing import Callable, Tuple | ||
|
||
import numpy as np | ||
|
||
from skspatial._functions import _mesh_to_points | ||
from skspatial.objects.points import Points | ||
|
||
|
||
class _ToPointsMixin: | ||
|
||
to_mesh: Callable[..., Tuple[np.ndarray, np.ndarray, np.ndarray]] | ||
|
||
def to_points(self, **kwargs) -> Points: | ||
""" | ||
Return points on the surface of the object. | ||
Parameters | ||
---------- | ||
kwargs: dict, optional | ||
Additional keywords passed to the `to_mesh` method of the class. | ||
Returns | ||
------- | ||
Points | ||
Points on the surface of the object. | ||
Examples | ||
-------- | ||
>>> from skspatial.objects import Sphere | ||
>>> sphere = Sphere([0, 0, 0], 1) | ||
>>> sphere.to_points(n_angles=3).round().unique() | ||
Points([[ 0., -1., 0.], | ||
[ 0., 0., -1.], | ||
[ 0., 0., 1.], | ||
[ 0., 1., 0.]]) | ||
>>> sphere.to_points(n_angles=4).round(3).unique() | ||
Points([[-0.75 , -0.433, -0.5 ], | ||
[-0.75 , -0.433, 0.5 ], | ||
[ 0. , 0. , -1. ], | ||
[ 0. , 0. , 1. ], | ||
[ 0. , 0.866, -0.5 ], | ||
[ 0. , 0.866, 0.5 ], | ||
[ 0.75 , -0.433, -0.5 ], | ||
[ 0.75 , -0.433, 0.5 ]]) | ||
""" | ||
X, Y, Z = self.to_mesh(**kwargs) | ||
points = _mesh_to_points(X, Y, Z) | ||
|
||
return Points(points) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.