diff --git a/gprMax/cmds_geometry/add_grass.py b/gprMax/cmds_geometry/add_grass.py index 850be20c..b159e078 100644 --- a/gprMax/cmds_geometry/add_grass.py +++ b/gprMax/cmds_geometry/add_grass.py @@ -50,6 +50,13 @@ class AddGrass(UserObjectGeometry): super().__init__(**kwargs) self.hash = '#add_grass' + def rotate(self, axis, angle, origin=None): + pts = np.array([self.kwargs['p1'], self.kwargs['p2']]) + rotation = UserObjectGeometry.rotate_2point_object + rot_pts = rotation(self, pts, axis, angle, origin) + self.kwargs['p1'] = tuple(rot_pts[0, :]) + self.kwargs['p2'] = tuple(rot_pts[1, :]) + def create(self, grid, uip): """Add Grass to fractal box.""" try: diff --git a/gprMax/cmds_geometry/add_surface_roughness.py b/gprMax/cmds_geometry/add_surface_roughness.py index 09042f1d..4cf1fc2b 100644 --- a/gprMax/cmds_geometry/add_surface_roughness.py +++ b/gprMax/cmds_geometry/add_surface_roughness.py @@ -50,6 +50,13 @@ class AddSurfaceRoughness(UserObjectGeometry): super().__init__(**kwargs) self.hash = '#add_surface_roughness' + def rotate(self, axis, angle, origin=None): + pts = np.array([self.kwargs['p1'], self.kwargs['p2']]) + rotation = UserObjectGeometry.rotate_2point_object + rot_pts = rotation(self, pts, axis, angle, origin) + self.kwargs['p1'] = tuple(rot_pts[0, :]) + self.kwargs['p2'] = tuple(rot_pts[1, :]) + def create(self, grid, uip): try: diff --git a/gprMax/cmds_geometry/add_surface_water.py b/gprMax/cmds_geometry/add_surface_water.py index e9285155..4d4e0d80 100644 --- a/gprMax/cmds_geometry/add_surface_water.py +++ b/gprMax/cmds_geometry/add_surface_water.py @@ -19,6 +19,7 @@ import logging import gprMax.config as config +import numpy as np from ..materials import DispersiveMaterial from ..utilities import round_value @@ -44,6 +45,13 @@ class AddSurfaceWater(UserObjectGeometry): super().__init__(**kwargs) self.hash = '#add_surface_water' + def rotate(self, axis, angle, origin=None): + pts = np.array([self.kwargs['p1'], self.kwargs['p2']]) + rotation = UserObjectGeometry.rotate_2point_object + rot_pts = rotation(self, pts, axis, angle, origin) + self.kwargs['p1'] = tuple(rot_pts[0, :]) + self.kwargs['p2'] = tuple(rot_pts[1, :]) + def create(self, grid, uip): """"Create surface water on fractal box.""" try: diff --git a/gprMax/cmds_geometry/box.py b/gprMax/cmds_geometry/box.py index 11654f26..136303cd 100644 --- a/gprMax/cmds_geometry/box.py +++ b/gprMax/cmds_geometry/box.py @@ -46,12 +46,12 @@ class Box(UserObjectGeometry): super().__init__(**kwargs) self.hash = '#box' - def rotate(self, pts, axis, angle, origin=None): - pts = np.array([[self.kwargs['p1']], [self.kwargs['p1']]]) + def rotate(self, axis, angle, origin=None): + pts = np.array([self.kwargs['p1'], self.kwargs['p2']]) rotation = UserObjectGeometry.rotate_2point_object rot_pts = rotation(self, pts, axis, angle, origin) self.kwargs['p1'] = tuple(rot_pts[0, :]) - self.kwargs['p1'] = tuple(rot_pts[1, :]) + self.kwargs['p2'] = tuple(rot_pts[1, :]) def create(self, grid, uip): try: diff --git a/gprMax/cmds_geometry/cmds_geometry.py b/gprMax/cmds_geometry/cmds_geometry.py index 2c9d17f6..d14f5555 100644 --- a/gprMax/cmds_geometry/cmds_geometry.py +++ b/gprMax/cmds_geometry/cmds_geometry.py @@ -47,6 +47,10 @@ class UserObjectGeometry: """Create the object and add it to the grid.""" pass + def rotate(self, axis, angle, origin=None): + """Rotate object - specialised for each object.""" + pass + def rotate_point(self, p, axis, angle, origin=(0, 0, 0)): """Rotate a point. @@ -60,7 +64,7 @@ class UserObjectGeometry: p (array): coordinates of rotated point (x, y, z) """ - origin = np.array([origin]) + origin = np.array(origin) # Move point to axis of rotation p -= origin diff --git a/gprMax/cmds_geometry/edge.py b/gprMax/cmds_geometry/edge.py index e803a2ec..b8d735e6 100644 --- a/gprMax/cmds_geometry/edge.py +++ b/gprMax/cmds_geometry/edge.py @@ -18,6 +18,8 @@ import logging +import numpy as np + from ..cython.geometry_primitives import (build_edge_x, build_edge_y, build_edge_z) from .cmds_geometry import UserObjectGeometry @@ -40,6 +42,13 @@ class Edge(UserObjectGeometry): super().__init__(**kwargs) self.hash = '#edge' + def rotate(self, axis, angle, origin=None): + pts = np.array([self.kwargs['p1'], self.kwargs['p2']]) + rotation = UserObjectGeometry.rotate_2point_object + rot_pts = rotation(self, pts, axis, angle, origin) + self.kwargs['p1'] = tuple(rot_pts[0, :]) + self.kwargs['p2'] = tuple(rot_pts[1, :]) + def create(self, grid, uip): """Create edge and add it to the grid.""" try: diff --git a/gprMax/cmds_geometry/fractal_box.py b/gprMax/cmds_geometry/fractal_box.py index 23b2593a..d2439d3a 100644 --- a/gprMax/cmds_geometry/fractal_box.py +++ b/gprMax/cmds_geometry/fractal_box.py @@ -53,6 +53,13 @@ class FractalBox(UserObjectGeometry): super().__init__(**kwargs) self.hash = '#fractal_box' + def rotate(self, axis, angle, origin=None): + pts = np.array([self.kwargs['p1'], self.kwargs['p2']]) + rotation = UserObjectGeometry.rotate_2point_object + rot_pts = rotation(self, pts, axis, angle, origin) + self.kwargs['p1'] = tuple(rot_pts[0, :]) + self.kwargs['p2'] = tuple(rot_pts[1, :]) + def create(self, grid, uip): try: p1 = self.kwargs['p1'] diff --git a/gprMax/cmds_geometry/plate.py b/gprMax/cmds_geometry/plate.py index 5cd38bd8..f4c71045 100644 --- a/gprMax/cmds_geometry/plate.py +++ b/gprMax/cmds_geometry/plate.py @@ -18,6 +18,8 @@ import logging +import numpy as np + from ..cython.geometry_primitives import (build_face_xy, build_face_xz, build_face_yz) from .cmds_geometry import UserObjectGeometry @@ -42,6 +44,13 @@ class Plate(UserObjectGeometry): super().__init__(**kwargs) self.hash = '#plate' + def rotate(self, axis, angle, origin=None): + pts = np.array([self.kwargs['p1'], self.kwargs['p2']]) + rotation = UserObjectGeometry.rotate_2point_object + rot_pts = rotation(self, pts, axis, angle, origin) + self.kwargs['p1'] = tuple(rot_pts[0, :]) + self.kwargs['p2'] = tuple(rot_pts[1, :]) + def create(self, grid, uip): try: p1 = self.kwargs['p1'] diff --git a/gprMax/cmds_multiuse.py b/gprMax/cmds_multiuse.py index f70597a5..fa8d3011 100644 --- a/gprMax/cmds_multiuse.py +++ b/gprMax/cmds_multiuse.py @@ -141,42 +141,25 @@ class VoltageSource(UserObjectMulti): self.order = 2 self.hash = '#voltage_source' - def rotate(self, axis, angle, origin=(0, 0, 0)): - """Rotate geometry object. - - Args: - axis (str): axis about which to perform rotation (x, y, or z) - angle (int): angle of rotation (degrees) - origin (tuple): point about which to perform rotation (x, y, z) - """ + def rotate(self, axis, angle, origin=None): + pts = np.array([self.kwargs['p1'], self.kwargs['p2']]) + dxdydz = (0.001, 0.001, 0.001) + if self.kwargs['polarisation'].lower() == 'x': + new_pt = (self.kwargs['p1'][0] + dxdydz[0], + self.kwargs['p1'][1], + self.kwargs['p1'][2]) + if axis == 'y' and angle == 90 or angle == 270: + self.kwargs['polarisation'] = 'z' + if axis == 'z' and angle == 90 or angle == 270: + self.kwargs['polarisation'] = 'y' - # Check angle value is suitable - angle = int(angle) - if angle < 0 or angle > 360: - logger.exception( - self.__str__() + ' angle of rotation must be between 0-360 degrees') - raise ValueError - if angle % 90 != 0: - logger.exception( - self.__str__() + ' angle of rotation must be a multiple of 90 degrees') - raise ValueError + pts = np.array([self.kwargs['p1'], new_pt]) - # Check axis is valid - if axis != 'x' and axis != 'y' and axis != 'z': - logger.exception(self.__str__() + - ' axis of rotation must be x, y, or z') - raise ValueError + rotation = UserObjectGeometry.rotate_2point_object + rot_pts = rotation(self, pts, axis, angle, origin) + self.kwargs['p1'] = tuple(rot_pts[0, :]) - # Save original point - origp = self.kwargs['p1'] - - # Rotate point - p = self.rotate_point(self, origp, axis, angle, origin) - p = np.array([p]) - # Reset coordinates of invariant direction - # - only needed for 2D models, has no effect on 3D models. - # Set polarisation depending on rotation angle if axis == 'x': p[0] = origp[0] if self.kwargs['polarisation'].lower() == 'y': @@ -202,8 +185,6 @@ class VoltageSource(UserObjectMulti): if angle == 90 or angle == 270: self.kwargs['polarisation'] = 'x' - # Write point back to original tuple - self.kwargs['p1'] = tuple(p) def create(self, grid, uip): try: