In [1]:
# set up
import numpy as np
from numpy import linalg as LA
from math import atan2
import sys
import os
sys.path.insert(0, os.path.abspath('..'))
import salientregions as sr
In [2]:
# elipse1
a = 15.9; b = 9.2; angle_rad = np.pi/8 #np.pi/13 #np.pi/4 #np.pi/3 #np.pi/2 #0- works only for angles in [0,90] deg.
[A, B, C] = sr.helpers.standard2poly_ellipse(a, b, angle_rad)
print "a, b, angle_rad:", a, b, angle_rad
print "A, B, C: ", A, B, C
In [ ]:
# construct a matrix from the values
M = np.array([[A,B],[B,C]])
print M
In [ ]:
# find the eigenvalues
evals = LA.eigh(M)[0]
order = evals.argsort()[::-1]
evals = evals[order]
e_min = evals[-1]
e_max = evals[0]
print "Eigen values, min, max: ", evals, e_min, e_max
In [ ]:
#angle_rad_c = np.arctan2(*evecs[:, 0][::-1])
if B == 0:
if A < C:
angle_rad_c = 0
else:
angle_rad_c = np.pi/2
else:
if A < C:
angle_rad_c = 0.5*np.arctan(2*B/(A-C))
else:
angle_rad_c = np.pi/2 + 0.5*np.arctan(2*B/(A-C))
print "The angle (rad): ", angle_rad_c
#if angle_rad_c < 0:
#angle_rad_c = np.pi - angle_rad_c
#print "The angle (rad): ", angle_rad_c
In [ ]:
# axis lengths
a_c = 1/np.sqrt(e_min)
print "Major axis semi-length: ", a_c
b_c = 1/np.sqrt(e_max)
print "Minor axis semi-length: ", b_c
In [ ]:
print "difference true-converted angle: ", angle_rad - angle_rad_c
print "difference true-converted minor axis semi-len: ", b - b_c
print "difference true-converted major axis semi-len: ", a - a_c
assert sr.helpers.array_diff(angle_rad, angle_rad_c,1e-05, 1e-08)
assert sr.helpers.array_diff(a, a_c,1e-05, 1e-08)
assert sr.helpers.array_diff(b, b_c,1e-05, 1e-08)
In [ ]:
In [ ]: