# Path: ptsa/helper.py
# def pol2cart(theta,radius,z=None,radians=True):
#     """Converts corresponding angles (theta), radii, and (optional) height (z)
#     from polar (or, when height is given, cylindrical) coordinates
#     to Cartesian coordinates x, y, and z.
#     Theta is assumed to be in radians, but will be converted
#     from degrees if radians==False."""
#     if radians:
#         x = radius*np.cos(theta)
#         y = radius*np.sin(theta)
#     else:
#         x = radius*np.cos(deg2rad(theta))
#         y = radius*np.sin(deg2rad(theta))
#     if z is not None:
#         # make sure we have a copy
#         z=z.copy()
#         return x,y,z
#     else:
#         return x,y
# 
# def cart2pol(x,y,z=None,radians=True):
#     """Converts corresponding Cartesian coordinates x, y, and (optional) z
#     to polar (or, when z is given, cylindrical) coordinates
#     angle (theta), radius, and z.
#     By default theta is returned in radians, but will be converted
#     to degrees if radians==False."""    
#     if radians:
#         theta = np.arctan2(y,x)
#     else:
#         theta = rad2deg(np.arctan2(y,x))
#     radius = np.hypot(x,y)
#     if z is not None:
#         # make sure we have a copy
#         z=z.copy()
#         return theta,radius,z
#     else:
#         return theta,radius
# 
# def deg2rad(degrees):
#     """Convert degrees to radians."""
#     return degrees/180.*np.math.pi


import numpy as np
import matplotlib.pyplot as plt
from ptsa.helper import pol2cart, cart2pol, deg2rad
from scipy.interpolate import griddata
        nose_dist = np.cos(np.arcsin((nose_width/2.)/radius))*radius
        # Distance from the center of the head to the tip of the nose:
        nose_tip_dist = 1.15*radius
        # Convert to polar coordinates for rotating:
        nose_polar_angle, nose_polar_radius = cart2pol(
            np.array([-nose_width/2, 0, nose_width/2]),
            np.array([nose_dist, nose_tip_dist, nose_dist]))
        nose_polar_angle = nose_polar_angle + deg2rad(nose_dir)
        # And back to cartesian coordinates for plotting:
        nose_x, nose_y = pol2cart(nose_polar_angle, nose_polar_radius)
        # Move nose with head:
        nose_x = nose_x + center[0]
        nose_y = nose_y + center[1]
        nose = plt.Line2D(nose_x, nose_y,
                          solid_joinstyle='round', solid_capstyle='round',
                          color=hprops['head_linecolor'],
                          linewidth=hprops['nose_linewidth'],
                          axes=a)

        # Ears:
        q = .04 # ear lengthening
        ear_x = np.array(
            [.497-.005, .510,.518, .5299, .5419, .54, .547,
             .532, .510, .489-.005])*(radius/0.5)
        ear_y = np.array(
            [q+.0555, q+.0775, q+.0783, q+.0746, q+.0555,
             -.0055, -.0932, -.1313, -.1384, -.1199])*(radius/0.5)
        # Convert to polar coordinates for rotating:
        rightear_polar_angle, rightear_polar_radius = cart2pol(ear_x, ear_y)
        leftear_polar_angle, leftear_polar_radius = cart2pol(-ear_x, ear_y)

# Path: ptsa/helper.py
# def pol2cart(theta,radius,z=None,radians=True):
#     """Converts corresponding angles (theta), radii, and (optional) height (z)
#     from polar (or, when height is given, cylindrical) coordinates
#     to Cartesian coordinates x, y, and z.
#     Theta is assumed to be in radians, but will be converted
#     from degrees if radians==False."""
#     if radians:
#         x = radius*np.cos(theta)
#         y = radius*np.sin(theta)
#     else:
#         x = radius*np.cos(deg2rad(theta))
#         y = radius*np.sin(deg2rad(theta))
#     if z is not None:
#         # make sure we have a copy
#         z=z.copy()
#         return x,y,z
#     else:
#         return x,y
# 
# def cart2pol(x,y,z=None,radians=True):
#     """Converts corresponding Cartesian coordinates x, y, and (optional) z
#     to polar (or, when z is given, cylindrical) coordinates
#     angle (theta), radius, and z.
#     By default theta is returned in radians, but will be converted
#     to degrees if radians==False."""    
#     if radians:
#         theta = np.arctan2(y,x)
#     else:
#         theta = rad2deg(np.arctan2(y,x))
#     radius = np.hypot(x,y)
#     if z is not None:
#         # make sure we have a copy
#         z=z.copy()
#         return theta,radius,z
#     else:
#         return theta,radius
# 
# def deg2rad(degrees):
#     """Convert degrees to radians."""
#     return degrees/180.*np.math.pi


# Path: ptsa/plotting/topo.py
import numpy as np
import matplotlib.pyplot as plt
from ptsa.helper import pol2cart, cart2pol, deg2rad
from scipy.interpolate import griddata

        nose_dist = np.cos(np.arcsin((nose_width/2.)/radius))*radius
        # Distance from the center of the head to the tip of the nose:
        nose_tip_dist = 1.15*radius
        # Convert to polar coordinates for rotating:
        nose_polar_angle, nose_polar_radius = cart2pol(
            np.array([-nose_width/2, 0, nose_width/2]),
            np.array([nose_dist, nose_tip_dist, nose_dist]))
        nose_polar_angle = nose_polar_angle + deg2rad(nose_dir)
        # And back to cartesian coordinates for plotting:
        nose_x, nose_y = pol2cart(nose_polar_angle, nose_polar_radius)
        # Move nose with head:
        nose_x = nose_x + center[0]
        nose_y = nose_y + center[1]
        nose = plt.Line2D(nose_x, nose_y,
                          solid_joinstyle='round', solid_capstyle='round',
                          color=hprops['head_linecolor'],
                          linewidth=hprops['nose_linewidth'],
                          axes=a)

        # Ears:
        q = .04 # ear lengthening
        ear_x = np.array(
            [.497-.005, .510,.518, .5299, .5419, .54, .547,
             .532, .510, .489-.005])*(radius/0.5)
        ear_y = np.array(
            [q+.0555, q+.0775, q+.0783, q+.0746, q+.0555,
             -.0055, -.0932, -.1313, -.1384, -.1199])*(radius/0.5)
        # Convert to polar coordinates for rotating:
        rightear_polar_angle, rightear_polar_radius = cart2pol(ear_x, ear_y)
        leftear_polar_angle, leftear_polar_radius = cart2pol(-ear_x, ear_y)

        rightear_polar_angle = rightear_polar_angle+deg2rad(nose_dir)