def anim():
    views = Visual.gen_space_views(fig, solar_system)
    views['Solar System'].set_cs_visible(False)
    views['Sun'].set_cs_visible(False)
    views['Earth'].set_cs_visible(False)
    views['Sun'].set_color((1.0, 1.0, 0.2))
    views['Earth'].set_color((0.0, 0.0, 0.5))
    Visual.draw_space(views)
    #views['Lunohod'].set_wireframe(True)
    #views['Moon'].set_wireframe(True)
    #views['Moon'].set_cs_visible(True)
    while True:
        Visual.draw_space(views)
        earth.coordinate_system.rotate_axis_angle([1, 1, 1], np.deg2rad(1))
        #moon.coordinate_system.rotate_axis_angle([0, 0, 1], np.deg2rad(1))
        yield
from __future__ import division, print_function
import numpy as np
from mayavi import mlab

from Space.Coordinates import Cartesian
from Space.Curve.Parametric import Helix
from Space.Pathfinder import line_between_two_points, helix_between_two_points, arc_between_two_points
import Space_visualization as Visual

coordinate_system = Cartesian()
coordinate_system.rotate_axis_angle(np.ones(3), np.deg2rad(45))

fig = mlab.figure('CS demo', bgcolor=(0, 0, 0))
Visual.draw_coordinate_system_axes(fig, coordinate_system)

right_helix = Helix(name='Right Helix', coordinate_system=coordinate_system,
                    radius=2, pitch=0.5, start=0, stop=np.pi * 4, right=True)
left_helix = Helix(name='Left Helix', coordinate_system=coordinate_system,
                   radius=2, pitch=0.5, start=0, stop=np.pi * 2, right=False)

print('Helix length:', left_helix.length())

right_helix_view = Visual.CurveView(fig=fig, curve=right_helix)
right_helix_view.draw()

left_helix_view = Visual.CurveView(fig=fig, curve=left_helix)
left_helix_view.draw()

point1 = np.array([1, 1, 0])
point2 = np.array([2, 2, 0])
points = np.vstack((coordinate_system.to_parent(point1), coordinate_system.to_parent(point2)))
from Space.Coordinates import Cartesian
import Space_visualization as Visual

# Euler's angles are used in the proper notation Z (phi1) - X' (Phi) - Z" (phi2)
# phi1 and phi2 are defined to have modulo 2*pi radians [-pi; pi] or [0; 2*pi]
# Phi is defined to have modulo pi radians [-pi/2; pi/2] or [0; pi]

M = 10
N = 5

# Here we use degrees and numpy deg2rad for conversion

scale = min(360 / (2 * M), 180 / (2 * N)) # scale factor for mayavi scene

fig = mlab.figure('CS demo', bgcolor=(0, 0, 0))  # Create the mayavi figure

for phi1 in np.linspace(0, 360, M, endpoint=True):
    for Phi in np.linspace(0, 180, N, endpoint=True):
        for phi2 in np.linspace(0, 360, M, endpoint=True):
            euler_angles = np.deg2rad(np.array([phi1, Phi, phi2]))
            # Create cartesian coordinate system
            CS = Cartesian(origin=np.array([phi1, Phi, phi2]), labels=['i1', 'i2', 'i3'],)
                           #euler_angles_convention='Bunge')
            # Set CS orientation using Euler's angles
            CS.euler_angles = euler_angles
            # CS_box visualize CS as a cube colored according to Euler's angles
            Visual.draw_coordinate_system_box(fig, CS, scale=scale, draw_axes=False)
# mlab.outline(extent=[0, 360, 0, 180, 0, 360])  # uncomment to draw white outline

mlab.show()
def anim():
    direction = 1
    while True:
        CS_1.rotate_axis_angle(np.array([0, 1, 0]), np.deg2rad(step))  # this is inplace transform
        CS_2.rotate_axis_angle(np.array([1, 0, 0]), np.deg2rad(step))  # this is inplace transform
        CS_3.rotate_axis_angle(np.array([0, 0, 1]), np.deg2rad(step))  # this is inplace transform
        CS_4.euler_angles += np.array([0, 0, np.deg2rad(step)])
        CS_5.euler_angles += direction * np.array([0, np.deg2rad(step), 0])
        CS_6.euler_angles += np.array([np.deg2rad(step), 0, 0])
        if direction == 1 and abs(np.pi - CS_5.euler_angles[1]) < np.deg2rad(step):
            direction *= -1
        elif direction == -1 and abs(CS_5.euler_angles[1]) < np.deg2rad(step):
            direction *= -1
        Visual.update_coordinate_system_box(CS_1, cs_box_1, arrows_1, labels_1)
        Visual.update_coordinate_system_box(CS_2, cs_box_2, arrows_2, labels_2)
        Visual.update_coordinate_system_box(CS_3, cs_box_3, arrows_3, labels_3)
        Visual.update_coordinate_system_box(CS_4, cs_box_4, arrows_4, labels_4)
        Visual.update_coordinate_system_box(CS_5, cs_box_5, arrows_5, labels_5)
        Visual.update_coordinate_system_box(CS_6, cs_box_6, arrows_6, labels_6)
        yield
# Create cartesian coordinate system

# if you don't pass arguments the basis coincide with 'Absolute' (mayavi) coordinate system
CS_1 = Cartesian(origin=np.array([0, 0, 0]), euler_angles_convention='bunge')
CS_2 = Cartesian(origin=np.array([3, 0, 0]), euler_angles_convention='bunge')
CS_3 = Cartesian(origin=np.array([6, 0, 0]), euler_angles_convention='bunge')
CS_4 = Cartesian(origin=np.array([0, 3, 0]), euler_angles_convention='bunge')
CS_5 = Cartesian(origin=np.array([3, 3, 0]), euler_angles_convention='bunge')
CS_6 = Cartesian(origin=np.array([6, 3, 0]), euler_angles_convention='bunge')
step = 1.0  # in degrees
# to visualise the coordinate system basis the module Visual is used

fig = mlab.figure('CS demo', bgcolor=(0.5, 0.5, 0.5))  # Create the mayavi figure

cs_box_1, arrows_1, labels_1 = Visual.draw_coordinate_system_box(fig, CS_1)
cs_box_2, arrows_2, labels_2 = Visual.draw_coordinate_system_box(fig, CS_2)
cs_box_3, arrows_3, labels_3 = Visual.draw_coordinate_system_box(fig, CS_3)
cs_box_4, arrows_4, labels_4 = Visual.draw_coordinate_system_box(fig, CS_4)
cs_box_5, arrows_5, labels_5 = Visual.draw_coordinate_system_box(fig, CS_5)
cs_box_6, arrows_6, labels_6 = Visual.draw_coordinate_system_box(fig, CS_6)
direction = 1

@mlab.show
@mlab.animate(delay=10)
def anim():
    direction = 1
    while True:
        CS_1.rotate_axis_angle(np.array([0, 1, 0]), np.deg2rad(step))  # this is inplace transform
        CS_2.rotate_axis_angle(np.array([1, 0, 0]), np.deg2rad(step))  # this is inplace transform
        CS_3.rotate_axis_angle(np.array([0, 0, 1]), np.deg2rad(step))  # this is inplace transform
def anim():
    while 1:
        delta_eulers = np.array([direction_prec * np.deg2rad(step_prec), 0, direction_rot * np.deg2rad(step_rot)])
        CS_1.euler_angles += delta_eulers
        Visual.update_coordinate_system_box(CS_1, cs_box_1, arrows_1, labels_1)
        yield
import Space_visualization as Visual

# Create cartesian coordinate system

# if you don't pass arguments the basis coincide with 'Absolute' (mayavi) coordinate system
CS_1 = Cartesian(origin=np.array([0, 0, 0]), euler_angles_convention='Bunge')
CS_2 = Cartesian(origin=np.array([0, 0, 0]), euler_angles_convention='Bunge')
step_prec = 1.0  # in degrees
step_rot = 1.0  # in degrees
direction_prec = 1
direction_rot = 1
Phi = 30  # tilt in degrees
CS_1.euler_angles += np.array([0, np.deg2rad(Phi), 0])  # tilt the CS
# to visualise the coordinate system basis the module Visual is used

fig = mlab.figure('CS demo', bgcolor=(0, 0, 0))  # Create the mayavi figure

cs_box_1, arrows_1, labels_1 = Visual.draw_coordinate_system_box(fig, CS_1, draw_labels=True)
arrows_2, labels_2 = Visual.draw_coordinate_system_axes(fig, CS_2, scale=2, draw_labels=True)

@mlab.show
@mlab.animate(delay=10)
def anim():
    while 1:
        delta_eulers = np.array([direction_prec * np.deg2rad(step_prec), 0, direction_rot * np.deg2rad(step_rot)])
        CS_1.euler_angles += delta_eulers
        Visual.update_coordinate_system_box(CS_1, cs_box_1, arrows_1, labels_1)
        yield

anim()