Python: outline dots and circles on a sphere

In the section of the project I'm working on at the university, I'm trying to recreate the Earth using Python and use it to build specific places on the surface and build circles in different directions so that they match satellite data. give an idea of ​​the location of the aircraft at a given time from a dataset.

I started with a simple wireframe construction and drew the points on the wireframe that I need (all on the scale of the Earth and their geographical locale).

The problem I am facing is when I draw points on a spherical object with an image of the Earth superimposed on top of the points that disappear when the sphere rotates past a certain point. So, the initial question: how can I stop their disappearance?

Secondly; I can't seem to find a way to draw circles centered on a sphere - for example, a circle around the equator, and then manipulate the same idea to draw circles on the surface of the sphere to get an image as shown below:

Circles on Earth

I know this is from Google maps, but I'm curious if this can be done in Python (I suppose so).

My current code is:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from itertools import product, combinations
import PIL

#Plot the Earth
f = plt.figure(1, figsize=(13,13))
ax = f.add_subplot(111, projection='3d')
u, v = np.mgrid[0:2*np.pi:30j, 0:np.pi:20j]
x=6371*np.cos(u)*np.sin(v)
y=6371*np.sin(u)*np.sin(v)
z=6371*np.cos(v)
ax.plot_wireframe(x, y, z, color="b")

#GES ground station @ Perth & AES @ KLIA

ax.scatter([-2368.8],[4881.1],[-3342.0],color="r",s=100)
ax.scatter([-1293.0],[6238.3],[303.5],color="k",s=100)

#Load earthmap with PIL
bm = PIL.Image.open('earthmap.jpg')
#It big, so I'll rescale it, convert to array, and divide by 256 to get RGB values that matplotlib accept 
bm = np.array(bm.resize([d/3 for d in bm.size]))/256.

#d/1 is normal size, anything else is smaller - faster loading time on Uni HPC

#Coordinates of the image - don't know if this is entirely accurate, but probably close
lons = np.linspace(-180, 180, bm.shape[1]) * np.pi/180 
lats = np.linspace(-90, 90, bm.shape[0])[::-1] * np.pi/180 

#Repeat code specifying face colours 

x = np.outer(6371*np.cos(lons), np.cos(lats)).T
y = np.outer(6371*np.sin(lons), np.cos(lats)).T
z = np.outer(6371*np.ones(np.size(lons)), np.sin(lats)).T
ax.plot_surface(x, y, z, rstride=4, cstride=4, facecolors = bm)

plt.show()

If there is any way, I can get it so that the dots stop fading and even capture a circle at the equator, which would be wonderful!

Thanks!

+6
source share

Source: https://habr.com/ru/post/1014731/


All Articles