More work on rotate method.

这个提交包含在:
craig-warren
2020-05-25 11:14:28 +01:00
父节点 c253cd080a
当前提交 4f040a1cc3
共有 9 个文件被更改,包括 70 次插入38 次删除

查看文件

@@ -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:

查看文件

@@ -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:

查看文件

@@ -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:

查看文件

@@ -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:

查看文件

@@ -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

查看文件

@@ -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:

查看文件

@@ -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']

查看文件

@@ -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']

查看文件

@@ -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: