Commit 8ef830a3 authored by pacome's avatar pacome
Browse files

Add translate, rotate, reflect in Shapes. visualy tested for few examples in 2D only

parent ebf7a3e5
......@@ -344,6 +344,30 @@ class Shape(ABC):
return General(func=new_func)
def translate(self, vect):
vect = np.asarray(vect)
func = self.geometry
def newfunc(x):
return func(translate(x, -vect))
self.geometry = newfunc
def rotate(self, angle, axis=None, center='self'):
'''3D not tested !!!'''
func = self.geometry
angle = -angle
except TypeError:
angle = -np.asarray(angle)
def newfunc(x):
return func(rotate(x, angle, axis=axis, center=center))
self.geometry = newfunc
def reflect(self, axis):
func = self.geometry
def newfunc(x):
return func(reflect(x, axis))
self.geometry = newfunc
class PiecewiseFunction(object):
......@@ -527,6 +551,7 @@ class Rectangle(General):
It returns True if the point is within the shape defined
by the function or False otherwise
x = np.asarray(x)
if len(x.shape) == 1:
ndim, npt = x.shape[0], -1
x = x[None, :]
......@@ -703,7 +728,7 @@ class InHull(Shape):
angle of rotation.
if 3d, tx is either the angle around the x axis or
the angle to rotate around the specified axis
ty: number
ty: numbernp.repeat([rot_mat], len(x), axis=0)
if axis is None, the angle of the rotation around y
will be ignored if axis is not None
tz: number (opt, defaults to None)
......@@ -877,6 +902,7 @@ def rotate(x, angle, axis=None, center='self'):
center_mat = np.repeat([center],
len(x), axis=0)
ret = (np.einsum(
'kij, kj -> ki',
np.repeat([rot_mat], len(x), axis=0), x - center_mat)
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