Commit d8985cf9 authored by pacome's avatar pacome
Browse files

Replace the internal rotate etc functions in Inhull by the external ones + fix...

Replace the internal rotate etc functions in Inhull by the external ones + fix the RegularPolygon class
parent 9a687f26
......@@ -730,20 +730,9 @@ class InHull(Shape):
'''
if self.points_coordinates is None:
self.points_coordinates = self.generate_points()
vect_parent = vect
def fun():
vect = np.asarray(vect_parent)
if len(self.points_coordinates.shape) < 2:
# translate a point
return self.points_coordinates + np.asarray(vect)
elif len(self.points_coordinates.shape) == 2:
return (np.repeat([vect], len(self.points_coordinates), axis=0)
+ self.points_coordinates)
self.points_coordinates = fun()
self.points_operations.append(fun)
self.points_coordinates = translate(self.points_coordinates, vect)
self.points_operations.append(lambda : translate(self.points_coordinates, vect))
def rotate(self, angle, axis=None, center='self'):
'''Rotate a point or a list of points in 2 or 3d around a center
......@@ -775,49 +764,26 @@ class InHull(Shape):
if self.points_coordinates is None:
self.points_coordinates = self.generate_points()
if not isinstance(angle, (list, tuple)):
angle = (angle,)
angle = np.asarray(angle)
center_parent = center
def fun():
if len(self.points_coordinates.shape) == 2:
npt, ndim = self.points_coordinates.shape
else: raise ValueError
if ndim is 2:
rot_mat = np.array([[np.cos(angle[0]), -np.sin(angle[0])],
[np.sin(angle[0]), np.cos(angle[0])]])
elif ndim is 3:
rot_mat = _rotation_matrix(angle, axis)
else: raise ValueError
if center_parent is None:
center = np.zeros(ndim)
elif center_parent is 'self':
center = np.mean(self.points_coordinates, axis=0)
elif isinstance(center_parent, (tuple, list, np.ndarray)):
center = np.asarray(center_parent)
else: raise ValueError
center_mat = np.repeat([center],
len(self.points_coordinates), axis=0)
ret = (np.einsum(
'kij, kj -> ki',
np.repeat([rot_mat], len(self.points_coordinates), axis=0),
self.points_coordinates - center_mat)
+ center_mat)
if npt is 1:
return ret[0]
else:
return ret
self.points_coordinates = rotate(self.points_coordinates, angle,
axis=axis, center=center)
self.points_operations.append(lambda : rotate(self.points_coordinates, angle,
axis=axis, center=center))
self.points_coordinates = fun()
self.points_operations.append(fun)
def reflect(self, axis):
'''returns reflections of point(s) x wrt to axis
Parameters:
-----------
axis: array like
2 (3) points that generate the line (plan)
wrt which to reflect in 2d (3d)
'''
if self.points_coordinates is None:
self.points_coordinates = self.generate_points()
self.points_coordinates = reflect(self.points_coordinates, axis)
self.points_operations.append(lambda : reflect(self.points_coordinates,
axis))
#####################
def box(length, corner=None, center=None):
......@@ -1069,7 +1035,7 @@ class RegularPolygon(InHull):
Parameters:
-----------
n: integer (opt, defaults to 3)
npoints: integer (opt, defaults to 3)
the number of sides (points) of the regular polygon
center: 2d tuple (opt, defaults to [0, 0])
the center of the regular polygon
......@@ -1081,20 +1047,17 @@ class RegularPolygon(InHull):
flat: bool (opt, defaults to True)
it True, the polygon is rotated to have his lowest
edge parallel to x axis
'''
super().__init__()
self.radius = radius
self.npoints = npoints
self.center = center
self.clockwise = clockwise
self.flat = flat
super().__init__()
def generate_points(self):
'''
Returns a numpy array containing the coordinates of the points
defining the shape.
'''
......@@ -1154,14 +1117,13 @@ class ExtrudedRegularPolygon(InHull):
'''
super().__init__()
self.radius = radius
self.npoints = npoints
self.center = center
self.clockwise = clockwise
self.flat = flat
self.Lz = Lz
super().__init__()
def generate_points(self):
'''
......@@ -1197,7 +1159,6 @@ class ExtrudedRegularPolygon(InHull):
##########################################################
# test plots
def __test_plot_ellipse():
ellipse = Ellipsoid(radius=2)
mm = continuous.grid._2d_mesh(*continuous.grid._points_from_2dbounding_box([-3, 3, -3, 3],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment