def _check_intersection(self, ray0, ray1, tri0, tri1, tri2): from pascal3d.utils.geometry import intersect3d_ray_triangle n_rays = len(ray0) assert len(ray1) == n_rays assert len(tri0) == n_rays assert len(tri1) == n_rays assert len(tri2) == n_rays l1 = sympy.Line3D(sympy.Point3D(*ray0.tolist()), sympy.Point3D(*ray1.tolist())) p1 = sympy.Plane(sympy.Point3D(*tri0.tolist()), sympy.Point3D(*tri1.tolist()), sympy.Point3D(*tri2.tolist())) t1 = sympy.Triangle(sympy.Point3D(*tri0.tolist()), sympy.Point3D(*tri1.tolist()), sympy.Point3D(*tri2.tolist())) i1 = p1.intersection(l1) if len(i1) == 0: ret1 = False else: ret1 = t1.encloses(i1[0]) ret2, i2 = intersect3d_ray_triangle(ray0, ray1, tri0, tri1, tri2) nose.tools.assert_equal(ret2.shape, (1, )) nose.tools.assert_equal(ret2[0] == 1, ret1) nose.tools.assert_equal(i2.shape, (1, 3)) if ret1: np.testing.assert_allclose(i2[0], map(float, [i1[0].x, i1[0].y, i1[0].z]))
def doppler_equation(freq=143050000, delta=True): M1_x = sp.Symbol('M1_x') M1_y = sp.Symbol('M1_y') M1_z = sp.Symbol('M1_z') M2_x = sp.Symbol('M2_x') M2_y = sp.Symbol('M2_y') M2_z = sp.Symbol('M2_z') VEL = sp.Symbol('Velocity') TX_x = sp.Symbol('TX_x') TX_y = sp.Symbol('TX_y') TX_z = sp.Symbol('TX_z') RX_x = sp.Symbol('RX_x') RX_y = sp.Symbol('RX_y') RX_z = sp.Symbol('RX_z') t = sp.Symbol('time') TX = sp.Matrix([TX_x, TX_y, TX_z]) # poloha vysilace RX = sp.Matrix([RX_x, RX_y, RX_z]) # poloha stanice M1 = sp.Matrix([M1_x, M1_y, M1_z]) # prvni souradnice trajektorie M2 = sp.Matrix([M2_x, M2_y, M2_z]) # druha souradnice trajektorie MV = (M2 - M1).normalized() # normalizovany vektor trajoktie # poloha meteoru v case 'time' MT = M1 + MV * VEL * t #B_pn = (RX-TX).cross((RX-MT)) # bistatic plane normal Vmt = (TX - MT).normalized() Vmr = (RX - MT).normalized() Vba = Vmt + Vmr l1, l2 = sp.Line3D(MT, TX), sp.Line3D(MT, RX) bistatic_angle = l1.angle_between(l2) #l1, l2 = sp.Line3D(MT, MT+Vba), sp.Line3D(MT, MT+MV) l1, l2 = sp.Line3D(MT, RX), sp.Line3D(MT, MT + MV) angle = l1.angle_between(l2) #doppler = (int(not delta)+(sp.acos(angle)*VEL)/(constants.c))*freq doppler = freq * (sp.cos(angle - bistatic_angle / 2) * VEL) / constants.c return doppler
def offset_face(self, fid): connected_edges = [ self.get_connected_edge(self.faces[fid][i], fid) for i in range(4) ] plane = self.face2plane(fid) origin = self.face_centre(fid) norm = sp.Point3D(plane.normal_vector) offset_vector = (sp.Point3D(self.center) - origin) offset_vector /= sp.Segment3D(sp.Point3D(0, 0, 0), offset_vector).length origin += offset_vector * random.uniform(-self.max_offset, self.max_offset) plane = sp.Plane(origin, normal_vector=norm) # find new points for face new_face_points = [] for ce in connected_edges: line = sp.Line3D(sp.Point3D(self.points[ce[0]]), sp.Point3D(self.points[ce[1]])) intersections = plane.intersection(line) if len(intersections) == 0: print("skip face offsetting - hex will not be valid") return new_point = intersections[0] new_point = [ new_point.x.evalf(), new_point.y.evalf(), new_point.z.evalf() ] new_face_points.append(new_point) if not self.is_b_not_far_than_a(self.points[ce[0]], self.points[ce[1]], new_point): print("skip face offsetting - hex will not be valid") return # replace old points with new for i in range(4): pid = self.faces[fid][i] self.points[pid] = new_face_points[i]
def rotate_face(self, fid): connected_edges = [ self.get_connected_edge(self.faces[fid][i], fid) for i in range(4) ] # rotate face plane around random axis with origin at face centre plane = self.face2plane(fid) origin = self.face_centre(fid) axis = plane.random_point() - plane.random_point() transform_matrix = Quaternion.from_axis_angle((axis[0], axis[1], axis[2]), random.uniform(-self.max_angle_offset, self.max_angle_offset) )\ .to_rotation_matrix((origin[0], origin[1], origin[2])) norm = sp.Point3D(plane.normal_vector) plane = sp.Plane(origin, normal_vector=norm.transform(transform_matrix)) # find new points for face new_face_points = [] for ce in connected_edges: line = sp.Line3D(sp.Point3D(self.points[ce[0]]), sp.Point3D(self.points[ce[1]])) new_point = plane.intersection(line)[0] new_point = [ new_point.x.evalf(), new_point.y.evalf(), new_point.z.evalf() ] new_face_points.append(new_point) if not self.is_b_not_far_than_a(self.points[ce[0]], self.points[ce[1]], new_point): print("skip face rotating - hex will not be valid") return # replace old points with new for i in range(4): pid = self.faces[fid][i] self.points[pid] = new_face_points[i]
import platform platform.platform() platform.python_version() import numpy as np import numpy.linalg as LA import math import sympy from sympy import var pravac = sympy.Line3D(sympy.Point3D(66.5, -33.93, -93.39), (41.22, 24.1, 69.82)) tocka = sympy.Point3D(19.43, -25.51, 32.48) print(round(pravac.distance(tocka), 5))
import platform platform.platform() platform.python_version() import numpy as np import numpy.linalg as LA import math import sympy from sympy import var H = sympy.Point3D(18, -95, 56) pravac1 = sympy.Line3D(sympy.Point3D(10, -27, 24), sympy.Point3D(-17, -65, 63)) pravac2 = sympy.Line3D(sympy.Point3D(41, 54, 86), sympy.Point3D(43, 129, 32)) s1 = sympy.Matrix(pravac1.direction_ratio) s2 = sympy.Matrix(pravac2.direction_ratio) nor = s1.cross(s2) nor_pi1 = s1.cross(nor) pi1 = sympy.Plane(sympy.Point3D(10, -27, 24), nor_pi1) nor_pi2 = s2.cross(nor) pi2 = sympy.Plane(sympy.Point3D(41, 54, 86), nor_pi2) normala = pi1.intersection(pi2)[0] N1 = normala.intersection(pravac1)[0] N2 = normala.intersection(pravac2)[0]