def testSubtraction(self): actual = self.vectorQ1 - self.vectorQ2 expected = geometry.Vector3D(0, 6, 0) self.assertEqual(actual, expected) actual = self.vectorQ1 - 3 expected = geometry.Vector3D(-1, 0, 1) self.assertEqual(actual, expected)
def testAddition(self): actual = self.vectorQ1 + self.vectorQ2 expected = geometry.Vector3D(4, 0, 8) self.assertEqual(actual, expected) actual = self.vectorQ1 + 3 expected = geometry.Vector3D(5, 6, 7) self.assertEqual(actual, expected)
def tearDown(self): self.assertTrue(self.vectorQ1 == geometry.Vector3D(2, 3, 4)) self.assertTrue(self.vectorQ2 == geometry.Vector3D(2, -3, 4)) self.assertTrue(self.vectorQ3 == geometry.Vector3D(-2, -1, -1)) self.assertTrue(self.vectorQ4 == geometry.Vector3D(-4, 6, -8)) self.assertTrue(self.vectorQ1 == [2, 3, 4]) self.assertTrue(self.vectorQ2 == [2, -3, 4]) self.assertTrue(self.vectorQ3 == [-2, -1, -1]) self.assertTrue(self.vectorQ4 == [-4, 6, -8])
def testSubtractionToSelf(self): actual = geometry.Vector3D.zero() actual -= self.vectorQ1 expected = geometry.Vector3D(-2, -3, -4) self.assertEqual(actual, expected) actual = geometry.Vector3D(2, 3, 4) actual -= 3 expected = geometry.Vector3D(-1, 0, 1) self.assertEqual(actual, expected)
def testAdditionToSelf(self): actual = geometry.Vector3D.zero() actual += self.vectorQ1 expected = geometry.Vector3D(2, 3, 4) self.assertEqual(actual, expected) actual = geometry.Vector3D(2, 3, 4) actual += 3 expected = geometry.Vector3D(5, 6, 7) self.assertEqual(actual, expected)
def setUp(self): # Vectors in each quadrant # Q1 is top right: x>0, y>0, and goes counter clockwise self.vectorQ1 = geometry.Vector3D(2, 3, 4) self.vectorQ2 = geometry.Vector3D(2, -3, 4) self.vectorQ3 = geometry.Vector3D(-2, -1, -1) self.vectorQ4 = geometry.Vector3D(-4, 6, -8) self.vectors = [ self.vectorQ1, self.vectorQ2, self.vectorQ3, self.vectorQ4 ]
def testScalarMultiplication(self): actual = self.vectorQ1 * 2 expected = geometry.Vector3D(4, 6, 8) self.assertEqual(actual, expected) actual = 2 * self.vectorQ1 self.assertEqual(actual, expected)
def __init__(self, parent=None): super().__init__(parent) self.stars3d = parser.parse_stars3d("stars/") self.view_area = geometry.ViewArea(geometry.Vector3D(0, 0, 1), geometry.Vector3D(0, 1, 0), math.pi / 5) self.stars2d = None self.update_stars2d() self.constellations_list = list( set([star.constellation for star in self.stars3d])) self.constellations_centers, self.constellations_radii = \ geometry.calculate_constellations_properties(self.stars3d) self.mouse_press_coordinates = None self.selected_constellation = None layout = QtWidgets.QVBoxLayout(self) layout.setAlignment(QtCore.Qt.AlignTop) self.search_button = QtWidgets.QPushButton("Search", self) self.search_button.clicked.connect(self.show_search) layout.addWidget(self.search_button) self.search_text = "" self.help_button = QtWidgets.QPushButton("Help", self) self.help_button.clicked.connect(self.show_help) layout.addWidget(self.help_button) self.about_button = QtWidgets.QPushButton("About", self) self.about_button.clicked.connect(self.show_about) layout.addWidget(self.about_button) self.exit_button = QtWidgets.QPushButton("Exit", self) self.exit_button.clicked.connect(self.close) layout.addWidget(self.exit_button) self.info_popup = None self.setWindowState(QtCore.Qt.WindowMaximized) self.setWindowTitle("Sky full of stars") self.background = QtGui.QImage("bg.png")
def testCrossProduct(self): actual = geometry.Vector3D(1, 0, 0).cross(geometry.Vector3D(0, 1, 0)) expected = geometry.Vector3D(0, 0, 1) self.assertEqual(actual, expected) actual = geometry.Vector3D(0, 1, 0).cross(geometry.Vector3D(1, 0, 0)) expected = geometry.Vector3D(0, 0, -1) self.assertEqual(actual, expected) actual = self.vectorQ1.cross(self.vectorQ2) expected = geometry.Vector3D(24, 0, -12) self.assertEqual(actual, expected)
def testScalarDivision(self): actual = self.vectorQ1 / 2 expected = geometry.Vector3D(1, 1.5, 2) self.assertEqual(actual, expected)
def makeTracks(self): """Generate tracks based on the specified number of azimuthal angle, subdivisions, and track spacing. """ # Geometry preliminaries w = self.geometry.width # Width of 3D domain h = self.geometry.height # Height of 3D domain d = self.geometry.depth # Depth of 3D domain if self.boundary == 'reflective': # Azimuthal angle subdivision, e.g. div=2 is (0,pi) self.div = 2 elif self.boundary == 'periodic' or self.boundary == 'white': self.div = 4 nangle = self.nangle // self.div # Num of azimuthal angles followed self.npolar = 3 #Determine azimuthal angles intv = vectorize(int) p = 2 * pi / self.nangle * (0.5 + arange(nangle)) # Desired angles t = pi / 2.0 / self.npolar * (0.5 + arange(self.npolar) ) # Desired polar angles self.nx = intv(abs(w / self.delta * sin(p)) + 1) # Num of intersections along x-axis self.ny = intv(abs(h / self.delta * cos(p)) + 1) # Num of intersections along y-axis self.nz = intv(abs(d / self.delta * sin(t)) + 1) # Num of intersections along z-axis self.nt = self.nx + self.ny # Total num of tracks for each angle self.phi = arctan(h * self.nx / (w * self.ny)) # Actual angle # create polar angle spacing and correct angles for each azi angle self.theta = zeros((len(self.nx), len(self.nz))) for x in range(len(self.nx)): for z, nz in enumerate(self.nz): self.theta[x][z] = pi / 2.0 - arctan( d / (nz * sqrt((w / self.nx[x] / 2.0)**2 + (h / self.ny[x] / 2.0)**2))) print("nz = {0}".format(self.nz)) print("theta = {0}".format(self.theta)) for i, angle in enumerate(self.phi): if p[i] > pi / 2: self.phi[i] = pi - self.phi[i] # Fix angles in (pi/2, pi) # Determine track spacing xprime = w / self.nx # Spacing between points along x-axis yprime = h / self.ny # Spacing between points along y-axis zprime = d / self.nz # Spacing between points along y-axis self.dels = xprime * sin(self.phi) # Actual track spacing # Determine azimuthal weights temp1 = concatenate((self.phi, [2 * pi / self.div] + self.phi[0])) temp2 = concatenate((-self.phi[0:1], self.phi)) x1 = 0.5 * (temp1[1:] - temp1[:-1]) x2 = 0.5 * (temp2[1:] - temp2[:-1]) self.wgta = (x1 + x2) / (2 * pi) * self.dels * self.div print('phi: {0}'.format(self.phi)) # allocate track lists self.tracks = [] for p in range(2 * self.npolar): self.tracks.append([]) for i in range(nangle): self.tracks[p].append([]) # Make tracks on (0,y,z), (x,0,z), and (w,y,z) planes for i in range(nangle): xin = zeros(self.nt[i]) yin = zeros(self.nt[i]) phi = self.phi[i] xin[:self.nx[i]] = xprime[i] * (0.5 + arange(self.nx[i])) yin[:self.nx[i]] = 0 yin[self.nx[i]:] = yprime[i] * (0.5 + arange(self.ny[i])) if sin(phi) > 0 and cos(phi) > 0: xin[self.nx[i]:] = 0 elif sin(phi) > 0 and cos(phi) < 0: xin[self.nx[i]:] = w phi = self.phi[i] for x, y in zip(xin, yin): for p in range(len(self.nz)): zin = zprime[p] * (0.5 + arange(self.nz[p])) print('zin: {0}'.format(zin)) for z in zin: # track for theta > pi / 2 r_in = geom.Vector3D(x, y, z) r_out = self.geometry.endpoint3d( r_in, phi, self.theta[i][p]) newTrack = Track3D(r_in, r_out, phi, self.theta[i][p]) newTrack.weight = self.wgta[ i] # Could make index on track to get rid of this self.tracks[p][i].append(newTrack) # track for reflecting theta r_in = geom.Vector3D(x, y, z) r_out = self.geometry.endpoint3d( r_in, phi, pi - self.theta[i][p]) newTrack = Track3D(r_in, r_out, phi, pi - self.theta[i][p]) newTrack.weight = self.wgta[ i] # Could make index on track to get rid of this self.tracks[p][i].append(newTrack) # make tracks on (x, y, 0) plane for p in range(len(self.nz)): for i in range(nangle): dx = xprime[i] dy = yprime[i] dl = zprime[p] * tan(self.theta[i][p]) xin = zeros(self.nt[i]) yin = zeros(self.nt[i]) phi = self.phi[i] xin[:self.nx[i]] = xprime[i] * (0.5 + arange(self.nx[i])) yin[:self.nx[i]] = 0 yin[self.nx[i]:] = yprime[i] * (0.5 + arange(self.ny[i])) if sin(phi) > 0 and cos(phi) > 0: xin[self.nx[i]:] = 0 elif sin(phi) > 0 and cos(phi) < 0: xin[self.nx[i]:] = w phi = self.phi[i] # tracks for theta < pi / 2 for x, y in zip(xin, yin): x += cos(phi) * dl / 2.0 y += sin(phi) * dl / 2.0 while x < w and y < h and x > 0 and y > 0: r_in = geom.Vector3D(x, y, 0) r_out = self.geometry.endpoint3d( r_in, phi, self.theta[i][p]) newTrack = Track3D(r_in, r_out, phi, self.theta[i][p]) newTrack.weight = self.wgta[ i] # Could make index on track to get rid of this self.tracks[p][i].append(newTrack) x += cos(phi) * dl y += sin(phi) * dl # tracks for reflecting theta for x, y in zip(xin, yin): x += cos(phi) * dl / 2.0 y += sin(phi) * dl / 2.0 while x < w and y < h and x > 0 and y > 0: r_in = geom.Vector3D(x, y, d) r_out = self.geometry.endpoint3d( r_in, phi, pi - self.theta[i][p]) newTrack = Track3D(r_in, r_out, phi, pi - self.theta[i][p]) newTrack.weight = self.wgta[ i] # Could make index on track to get rid of this self.tracks[p][i].append(newTrack) x += cos(phi) * dl y += sin(phi) * dl