def updatePositions(self, observe=None, subpoint=None, altaz=None): """ updatePositions is triggered once a second and update the satellite position in each view. :return: success """ if observe is None: return False if subpoint is None: return False if altaz is None: return False if self.satellite is None: return False if self.plotSatPosEarth is None: return False if self.plotSatPosHorizon is None: return False if self.plotSatPosSphere1 is None: return False if self.plotSatPosSphere2 is None: return False # sphere1 x, y, z = observe.position.km self.plotSatPosSphere1.set_data_3d((x, y, z)) # sphere2 lat = subpoint.latitude.radians lon = subpoint.longitude.radians elev = subpoint.elevation.m / 1000 + self.EARTH_RADIUS x, y, z = transform.sphericalToCartesian(azimuth=lon, altitude=lat, radius=elev) self.plotSatPosSphere2.set_data_3d((x, y, z)) # earth lat = subpoint.latitude.degrees lon = subpoint.longitude.degrees self.plotSatPosEarth.set_data((lon, lat)) # horizon alt, az, _ = altaz alt = alt.degrees az = az.degrees self.plotSatPosHorizon.set_data((az, alt)) # update the plot and redraw self.satSphereMat1.figure.canvas.draw() self.satEarthMat.figure.canvas.draw() self.satHorizonMat.figure.canvas.draw() return True
def drawSphere2(self, observe=None, subpoint=None): """ draw sphere and put face color als image overlay: https://stackoverflow.com/questions/53074908/ map-an-image-onto-a-sphere-and-plot-3d-trajectories but performance problems see also: https://space.stackexchange.com/questions/25958/ how-can-i-plot-a-satellites-orbit-in-3d-from-a-tle-using-python-and-skyfield :param observe: :param subpoint: :return: success """ figure = self.satSphereMat2.figure figure.clf() figure.subplots_adjust(left=-0.1, right=1.1, bottom=-0.3, top=1.2) axe = figure.add_subplot(111, projection='3d') # switching all visual grids and planes off axe.set_facecolor((0, 0, 0, 0)) axe.tick_params(colors=self.M_GREY, labelsize=12) axe.set_axis_off() axe.w_xaxis.set_pane_color((0.0, 0.0, 0.0, 0.0)) axe.w_yaxis.set_pane_color((0.0, 0.0, 0.0, 0.0)) axe.w_zaxis.set_pane_color((0.0, 0.0, 0.0, 0.0)) # calculating sphere theta = np.linspace(0, 2 * np.pi, 51) cth, sth, zth = [f(theta) for f in [np.cos, np.sin, np.zeros_like]] lon0 = self.EARTH_RADIUS * np.vstack((cth, zth, sth)) longitudes = [] lonBase = np.arange(-180, 180, 15) for phi in np.radians(lonBase): cph, sph = [f(phi) for f in [np.cos, np.sin]] lon = np.vstack((lon0[0] * cph - lon0[1] * sph, lon0[1] * cph + lon0[0] * sph, lon0[2])) longitudes.append(lon) lats = [] latBase = np.arange(-75, 90, 15) for phi in np.radians(latBase): cph, sph = [f(phi) for f in [np.cos, np.sin]] lat = self.EARTH_RADIUS * np.vstack((cth * cph, sth * cph, zth + sph)) lats.append(lat) # plotting sphere and labels for i, longitude in enumerate(longitudes): x, y, z = longitude axe.plot(x, y, z, '-k', lw=1, color=self.M_GREY) for i, lat in enumerate(lats): x, y, z = lat axe.plot(x, y, z, '-k', lw=1, color=self.M_GREY) axe.plot([0, 0], [0, 0], [- self.EARTH_RADIUS * 1.1, self.EARTH_RADIUS * 1.1], lw=3, color=self.M_BLUE) axe.text(0, 0, self.EARTH_RADIUS * 1.2, 'N', fontsize=14, color=self.M_BLUE) axe.text(0, 0, - self.EARTH_RADIUS * 1.2 - 200, 'S', fontsize=14, color=self.M_BLUE) # plot world for key in self.world.keys(): shape = self.world[key] x, y, z = transform.sphericalToCartesian(azimuth=shape['xRad'], altitude=shape['yRad'], radius=self.EARTH_RADIUS) verts = [list(zip(x, y, z))] collect = Poly3DCollection(verts, facecolors=self.M_BLUE, alpha=0.5) axe.add_collection3d(collect) # drawing home position location on earth lat = self.app.mount.obsSite.location.latitude.radians lon = self.app.mount.obsSite.location.longitude.radians x, y, z = transform.sphericalToCartesian(altitude=lat, azimuth=lon, radius=self.EARTH_RADIUS) axe.plot([x], [y], [z], marker='.', markersize=12, color=self.M_RED, ) # empty chart if no satellite is chosen if observe is None: axe.figure.canvas.draw() return False # drawing satellite subpoint path lat = subpoint.latitude.radians lon = subpoint.longitude.radians elev = subpoint.elevation.m / 1000 + self.EARTH_RADIUS x, y, z = transform.sphericalToCartesian(azimuth=lon, altitude=lat, radius=elev) axe.plot(x, y, z, color=self.M_YELLOW) # draw satellite position self.plotSatPosSphere2, = axe.plot([x[0]], [y[0]], [z[0]], marker=self.markerSatellite(), markersize=16, linewidth=2, fillstyle='none', color=self.M_PINK) # finalizing self.makeCubeLimits(axe) axe.figure.canvas.draw() return True
def test_sphericalToCartesian_3(): x, y, z = transform.sphericalToCartesian(0, np.radians(90), 1) assert round(x, 6) == 0 assert round(y, 6) == 1 assert round(z, 6) == 0
def test_sphericalToCartesian_4(): x, y, z = transform.sphericalToCartesian(0, np.radians(45), 1) assert round(x, 6) == 0.707107 assert round(y, 6) == 0.707107 assert round(z, 6) == 0
def test_sphericalToCartesian_2(): x, y, z = transform.sphericalToCartesian(0, 0, 1) assert round(x, 6) == 1 assert round(y, 6) == 0 assert round(z, 6) == 0