#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
sphere.py für Blatt 7, Aufgabe 28
'''

import numpy as np
import matplotlib.pyplot as plt


phi1D = np.linspace(np.pi/4, 3*np.pi/4, 10)[1:-1]
theta1D = np.linspace(-3*np.pi/4, 3*np.pi/4, 22)[:-1]
phi, theta = np.meshgrid(phi1D, theta1D)

x0 = (np.sin(phi)*np.cos(theta)).flatten()
x1 = (np.sin(phi)*np.sin(theta)).flatten()
x2 = np.cos(phi).flatten()

xYin = np.vstack([x0, x1, x2])
xYang = np.vstack([-x0, x2, x1])
x = np.hstack((xYin, xYang))

fig = plt.figure(figsize=(5, 5))
ax = fig.add_subplot(projection='3d')

m1 = np.min(x)
m2 = np.max(x)
ax.set_xlim3d(m1, m2)
ax.set_xlabel('$x_0$')
ax.set_ylim3d(m1, m2)
ax.set_ylabel('$x_1$')
ax.set_zlim3d(m1, m2)
ax.set_zlabel('$x_2$')

for k in range(x.shape[1]):
    col = plt.cm.rainbow(k/x.shape[1])
    ax.quiver(0, 0, 0, x[0, k], x[1, k], x[2, k], colors=col)
