Here are the examples of the python api numpy.arctan2 taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
151 Examples
3
Example 1
def __init__(self, faceNorm, drawingNorm, a_3Dpos, a_2Dproj, b_3Dpos, b_2Dproj):
axis, angle = rotation_required_to_rotate_a_vector_to_be_aligned_to_another_vector( faceNorm, drawingNorm )
self.R1 = axis_rotation_matrix( angle, *axis )
debugPrint(4,""" R1: %s""" % self.R1 )
a_R1 = dotProduct( self.R1, a_3Dpos)
b_R1 = dotProduct( self.R1, b_3Dpos)
angle_actual = arctan2( b_R1[1] - a_R1[1], b_R1[0] - a_R1[0] )
angle_desired = arctan2( b_2Dproj[1] - a_2Dproj[1], b_2Dproj[0] - a_2Dproj[0] )
self.R2 = axis_rotation_matrix( angle_desired - angle_actual, u_x=0, u_y=0, u_z=1.0 ) #R2 maybe unessary...
self.R = dotProduct( self.R2, self.R1 )
a_R = dotProduct( self.R, a_3Dpos )
self.offset = a_2Dproj - a_R
3
Example 2
Project: nmrglue Source File: proc_lp.py
def cof2phase(z):
"""
Calculate a signal phase from a model coefficient
"""
# z = amp*exp(phase(i) so phase is the arg(z)
return np.arctan2(z.imag, z.real)
3
Example 3
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
3
Example 4
def _move_edge(self, obj=None, evt=None):
c = self.center.representation.world_position
r = self.edge.representation.world_position
r -= c
angle = np.arctan2(r[1], r[0])
radius = np.sqrt(np.sum(r**2))
self.set(angle=angle, radius=radius)
3
Example 5
@property
def position_angle(self):
"""
The position angle of sky_maj, sky_min in degrees counter-clockwise
from the +x axis (note that this is the +x axis in pixel coordinates,
which is the ``-x`` axis for conventional astronomy images).
"""
a, b = self._sky_paxes()
a = list(a)
a.pop(self.vaxis)
return np.degrees(np.arctan2(a[0], a[1])) * u.degree
3
Example 6
def psi(i, j, k, offset=(25, 25, 50)):
x = i-offset[0]
y = j-offset[1]
z = k-offset[2]
th = np.arctan2(z, (x**2+y**2)**0.5)
r = (x**2 + y**2 + z**2)**0.5
a0 = 1
ps = ((1./81.) * 1./(6.*np.pi)**0.5 * (1./a0)**(3/2) * (r/a0)**2 *
np.exp(-r/(3*a0)) * (3 * np.cos(th)**2 - 1))
return ps
3
Example 7
Project: hyphae Source File: hyphae.py
def sandpaint_color_line(self,x1,y1,x2,y2,k):
dx = x1 - x2
dy = y1 - y2
dd = sqrt(dx*dx+dy*dy)
a = arctan2(dy,dx)
scales = random(GRAINS)*dd
xp = x1 - scales*cos(a)
yp = y1 - scales*sin(a)
r,g,b = self.colors[k%self.ncolors]
self.ctx.set_source_rgba(r,g,b,ALPHA)
for x,y in zip(xp,yp):
self.ctx.rectangle(x,y,ONE,ONE)
self.ctx.fill()
3
Example 8
def cart2sph(x, y, z):
"""Cartesian to spherical coordinates."""
alpha = np.arctan2(y, x)
beta = np.arccos(z / np.sqrt(x**2 + y**2))
r = np.sqrt(x**2 + y**2 + z**2)
return alpha, beta, r
3
Example 9
def _compute_phasediff(cross_correlation_max):
"""
cuem*************************************
From skimage.feature.register_translation
*****************************************
Compute global phase difference between the two images (should be
zero if images are non-negative).
Parameters
----------
cross_correlation_max : complex
The complex value of the cross correlation at its maximum point.
"""
return np.arctan2(cross_correlation_max.imag, cross_correlation_max.real)
3
Example 10
Project: simpeg Source File: test_Problem1D_AnalyticVsNumeric.py
def getAppResPhs(NSEMdata):
# Make impedance
def appResPhs(freq,z):
app_res = ((1./(8e-7*np.pi**2))/freq)*np.abs(z)**2
app_phs = np.arctan2(z.imag,z.real)*(180/np.pi)
return app_res, app_phs
zList = []
for src in NSEMdata.survey.srcList:
zc = [src.freq]
for rx in src.rxList:
if 'i' in rx.rxType:
m=1j
else:
m = 1
zc.append(m*NSEMdata[src,rx])
zList.append(zc)
return [appResPhs(zList[i][0],np.sum(zList[i][1:3])) for i in np.arange(len(zList))]
3
Example 11
def _aspect(D, res=(1.0, 1.0)):
""" Return the slope aspect for each pixel.
http://webhelp.esri.com/arcgisdesktop/9.2/index.cfm?TopicName=How%20Aspect%20works
"""
Ddx = ((2 * D[1:-1,2:] + D[:-2,2:] + D[2:,2:]) -
(2 * D[1:-1,:-2] + D[:-2,:-2] + D[2:,:-2])) / (8.0 * res[0])
Ddy = ((2 * D[2:,1:-1] + D[2:,2:] + D[2:,:-2]) -
(2 * D[:-2,1:-1] + D[:-2,:-2] + D[:-2,2:])) / (8.0 * res[1])
return np.pad(np.arctan2(Ddy, -Ddx), ((1, 1), (1, 1)), "constant",
constant_values=(np.nan,))
3
Example 12
@property
def theta(self):
'''
Returns position angle in *radians*
'''
return np.arctan2(self.e2, self.e1) / 2.
3
Example 13
Project: pyNastran Source File: coord.py
def rectangular_to_spherical(self, xyz):
if len(xyz.shape) == 2:
x = xyz[:, 0]
y = xyz[:, 1]
z = xyz[:, 2]
else:
x = xyz[0]
y = xyz[1]
z = xyz[2]
R = sqrt(x * x + y * y + z * z)
phi = degrees(arctan2(y, x))
theta = degrees(arccos(z / R))
r_theta_phi = vstack([R, theta, phi])
return r_theta_phi
3
Example 14
Project: FreeCAD_drawing_dimensioning Source File: circleLib.py
def pointsAlongCircularArc_old(r, x_1, y_1, x_2, y_2, largeArc, sweep, noPoints, debug=False ):
c_x, c_y = findCircularArcCentrePoint(r, x_1, y_1, x_2, y_2, largeArc, sweep, debug)
angle_1 = arctan2( y_1 - c_y, x_1 - c_x)
angle_2 = arctan2( y_2 - c_y, x_2 - c_x)
if not sweep: # arc sweeps through increasing angles # arc drawing CCW,
if angle_2 > angle_1:
angle_2 = angle_2 - 2*pi
else:
if angle_1 > angle_2:
angle_2 = angle_2 + 2*pi
points = []
for i in range(1,noPoints+1):
a = angle_1 + (angle_2 - angle_1) * 1.0*i/noPoints
points.append([
c_x + r*cos(a),
c_y + r*sin(a)
])
return points
3
Example 15
def fun(self, x, *args):
self.nfev += 1
r = sqrt(x[0] ** 2 + x[1] ** 2)
theta = 1 / (2. * pi) * arctan2(x[1], x[0])
return x[2] ** 2 + 100 * ((x[2] - 10 * theta) ** 2 + (r - 1) ** 2)
3
Example 16
def _angle(self, v1, v2):
""" Compute the angle difference between two vectors
:param v1: The x,y coordinates of the vector
:type: v1: list
:param v2: The x,y coordinates of the vector
:type: v2: list
:rtype: float
"""
angle_diff = np.arctan2(v1[0], v1[1]) - np.arctan2(v2[0], v2[1])
if angle_diff < 0:
angle_diff += 2*np.pi
return angle_diff
3
Example 17
Project: NeuroM Source File: _neuronfunc.py
def trunk_origin_azimuths(nrn, neurite_type=NeuriteType.all):
'''Get a list of all the trunk origin azimuths of a neuron or population
The azimuth is defined as Angle between x-axis and the vector
defined by (initial tree point - soma center) on the x-z plane.
The range of the azimuth angle [-pi, pi] radians
'''
neurite_filter = is_type(neurite_type)
nrns = nrn.neurons if hasattr(nrn, 'neurons') else [nrn]
def _azimuth(section, soma):
'''Azimuth of a section'''
vector = mm.vector(section[0], soma.center)
return np.arctan2(vector[COLS.Z], vector[COLS.X])
return [_azimuth(s.root_node.points, n.soma)
for n in nrns for s in n.neurites if neurite_filter(s)]
3
Example 18
Project: render Source File: render.py
def sandstroke(self,xys,grains=10):
pix = self.pix
rectangle = self.ctx.rectangle
fill = self.ctx.fill
dx = xys[:,2] - xys[:,0]
dy = xys[:,3] - xys[:,1]
aa = arctan2(dy,dx)
directions = column_stack([cos(aa),sin(aa)])
dd = sqrt(square(dx)+square(dy))
for i,d in enumerate(dd):
for x,y in xys[i,:2] + directions[i,:]*random((grains,1))*d:
rectangle(x,y,pix,pix)
fill()
3
Example 19
Project: pyorbital Source File: geoloc.py
def subpoint(query_point, a=a, b=b):
"""Get the point on the ellipsoid under the *query_point*.
"""
x, y, z = query_point
r = sqrt(x * x + y * y)
lat = geodetic_lat(query_point)
lon = np.arctan2(y, x)
e2_ = (a * a - b * b) / (a * a)
n__ = a / sqrt(1 - e2_ * sin(lat)**2)
nx_ = n__ * cos(lat) * cos(lon)
ny_ = n__ * cos(lat) * sin(lon)
nz_ = (1 - e2_) * n__ * sin(lat)
return np.vstack([nx_, ny_, nz_])
3
Example 20
Project: kameleon-mcmc Source File: Flower.py
def emp_quantiles(self, X, quantiles=arange(0.1, 1, 0.1)):
norms = array([norm(x) for x in X])
angles = arctan2(X[:, 1], X[:, 0])
mu = self.radius + self.amplitude * cos(self.frequency * angles)
transformed = hstack((array([norms-mu]).T, X[:,2:self.dimension]))
cov=eye(self.dimension-1)
cov[0,0]=self.variance
gaussian=Gaussian(zeros([self.dimension-1]), cov)
return gaussian.emp_quantiles(transformed)
3
Example 21
Project: pymote Source File: aoastitcher.py
def _get_rotation_matrix_2_common_nodes(self, commonNodes, dstSubPos,
srcSubPos):
"""
Calculates rotation matrix based only on two common nodes
Warning: should not be used when local systems could be
reflected i.e. when they are formed by distance measurements.
"""
vector1 = dstSubPos[commonNodes[0]] - dstSubPos[commonNodes[1]]
vector2 = srcSubPos[commonNodes[0]] - srcSubPos[commonNodes[1]]
theta1 = arctan2(vector1[1], vector1[0])
theta2 = arctan2(vector2[1], vector2[0])
theta = theta1 - theta2
# in ccw direction
R = array([[cos(theta), -sin(theta)], [sin(theta), cos(theta)]])
return R
3
Example 22
def transform(self, R, s, t, pos, ori=nan):
""" Transform node position. """
assert None not in (R, s, t)
assert not imag(R).any()
R = real(R)
if not isnan(ori):
# angle of rotation matrix R in ccw
Rtheta = arctan2(R[1, 0], R[0, 0])
ori = mod(ori - Rtheta, 2*pi)
return concatenate((t + dot(dot(s, R), pos), [ori]))
3
Example 23
Project: cortex Source File: euclidean.py
def make_spiral(self, r=0.25, G=0.0001):
for k in range(10):
x = self.X[:, 0] - 0.5
y = self.X[:, 1] - 0.5
theta = np.arctan2(x, y)
ds = [r * (i + theta / (2 * np.pi)) for i in range(int(1 / r))]
alphas = [np.sqrt(x ** 2 + y ** 2) / d for d in ds]
for alpha in alphas:
d = np.concatenate([(x * (1 - alpha))[:, None], (y * (1 - alpha))[:, None]], axis=1)
f = -G * d / (d ** 2).sum(axis=1, keepdims=True)
self.X += f
self.X = np.clip(self.X, 0, 1)
rs = np.arange(0, 0.7, 0.001)
theta = 2 * np.pi * rs / r
y = rs * np.sin(theta) + 0.5
x = -rs * np.cos(theta) + 0.5
spiral = zip(x, y)
self.collection = matplotlib.collections.LineCollection([spiral], colors='k')
3
Example 24
@property
def position_angle(self):
"""
The position angle of sky_maj, sky_min in degrees counter-clockwise
from the +x axis.
"""
a, b = self._sky_paxes()
return np.degrees(np.arctan2(a[0], a[1])) * u.degree
3
Example 25
Project: python-skyfield Source File: functions.py
def to_polar(xyz):
"""Convert ``[x y z]`` into spherical coordinates ``(r, theta, phi)``.
``r`` - vector length
``theta`` - angle above (+) or below (-) the xy-plane
``phi`` - angle around the z-axis
The order of the three return values is intended to match ISO 31-11.
"""
r = length_of(xyz)
x, y, z = xyz
theta = arcsin(z / r)
phi = arctan2(y, x) % tau
return r, theta, phi
3
Example 26
Project: fatiando Source File: _prism_numpy.py
def safe_atan2(y, x):
"""
Correct the value of the angle returned by arctan2 to match the sign of the
tangent. Also return 0 instead of 2Pi for 0 tangent.
"""
res = arctan2(y, x)
res[y == 0] = 0
res[(y > 0) & (x < 0)] -= pi
res[(y < 0) & (x < 0)] += pi
return res
3
Example 27
@property
def theta(self):
'''
Returns position angle in *radians*
'''
return np.arctan2(self.ee2, self.ee1) / 2.
3
Example 28
Project: pyNastran Source File: coord.py
def rectangular_to_cylindrical(self, xyz):
if len(xyz.shape) == 2:
x = xyz[:, 0]
y = xyz[:, 1]
z = xyz[:, 2]
else:
x = xyz[0]
y = xyz[1]
z = xyz[2]
theta = degrees(arctan2(y, x))
R = sqrt(x * x + y * y)
r_theta_z = vstack([R, theta, z])
return r_theta_z
3
Example 29
Project: pycortex Source File: freesurfer.py
def stretch_mwall(pts, polys, mwall):
inflated = pts.copy()
center = pts[mwall].mean(0)
radius = max((pts.max(0) - pts.min(0))[1:])
angles = np.arctan2(pts[mwall][:,2], pts[mwall][:,1])
pts[mwall, 0] = center[0]
pts[mwall, 1] = radius * np.cos(angles) + center[1]
pts[mwall, 2] = radius * np.sin(angles) + center[2]
return SpringLayout(pts, polys, inflated, pins=mwall)
3
Example 30
def _compute_phasediff(cross_correlation_max):
"""
Compute global phase difference between the two images (should be
zero if images are non-negative).
Parameters
----------
cross_correlation_max : complex
The complex value of the cross correlation at its maximum point.
"""
return np.arctan2(cross_correlation_max.imag, cross_correlation_max.real)
3
Example 31
def quaternion_to_euler( q_1, q_2, q_3, q_0): #order to match FreeCads, naming to match wikipedias
'''
http://en.wikipedia.org/wiki/Rotation_formalisms_in_three_dimensions
for conversion to 3-1-3 Euler angles (dont know about this one, seems to me to be 3-2-1...)
'''
psi = arctan2( 2*(q_0*q_1 + q_2*q_3), 1 - 2*(q_1**2 + q_2**2) )
phi = arcsin2( 2*(q_0*q_2 - q_3*q_1) )
theta = arctan2( 2*(q_0*q_3 + q_1*q_2), 1 - 2*(q_2**2 + q_3**2) )
return theta, phi, psi # gives same answer as FreeCADs toEuler function
3
Example 32
Project: pyNastran Source File: data_in_material_coord.py
def thetadeg_to_principal(Sxx, Syy, Sxy):
"""Calculate the angle to the principal plane stress state
Parameters
----------
Sxx, Syy, Sxy : array-like
Sigma_xx, Sigma_yy, Sigma_xy stresses.
Returns
-------
thetadeg : np.ndarray
Array with angles for which the given stresses are transformed to the
principal stress state.
"""
Scenter = (Sxx + Syy)/2.
thetarad = np.arctan2(Sxy, Scenter - Syy)
return np.rad2deg(thetarad)/2.
3
Example 33
def dxfwrite_arc_parms(self, x_c, y_c, r):
x1, y1 = self.P[0]
x2, y2 = self.P[-1]
x_c, y_c = self.c_x, self.c_y
startangle = arctan2( y1 - y_c, x1 - x_c) / pi * 180
endangle = arctan2( y2 - y_c, x2 - x_c) / pi * 180
return r, (x_c, y_c), startangle, endangle
3
Example 34
def propagateRay(self, ray):
"""Refract, reflect, absorb, and/or scatter ray. This function may create and return new rays"""
surface = self.surfaces[0]
p1, ai = surface.intersectRay(ray)
if p1 is not None:
p1 = surface.mapToItem(ray, p1)
rd = ray['dir']
a1 = np.arctan2(rd[1], rd[0])
ar = a1 + np.pi - 2*ai
ray.setEnd(p1)
dp = Point(np.cos(ar), np.sin(ar))
ray = Ray(parent=ray, dir=dp)
else:
ray.setEnd(None)
return [ray]
3
Example 35
def svg(self, strokeWidth, lineColor):
if self.points[0] <> self.points[-1]:
r = self.radius
largeArc = False #abs(dEnd - dStart) >= pi #given the construction method
#determine sweep flag
p1, p2 = self.points[:2]
angle1 = arctan2( p1.y-self.center.y , p1.x-self.center.x )
angle2 = arctan2( p2.y-self.center.y , p2.x-self.center.x )
if abs(angle1 - angle2) < pi/2: # has not crossed pi/2 or -pi/2 mark
sweep = angle1 < angle2
else:
sweep = angle1 < 0
return ' '.join( ['<path d = "M %f %f A %f %f 0 %i %i %f %f" style="stroke:%s;stroke-width:%1.2f;fill:none" />' % (p1.x, p1.y,r,r,largeArc,sweep, p2.x, p2.y, lineColor, strokeWidth ) for p1,p2 in zip(self.points[:-1], self.points[1:]) ] )
else:
return '<circle cx="%f" cy="%f" r="%f" stroke="%s" stroke-width="%1.2f" fill="none" />' % (self.center.x, self.center.y, self.radius, lineColor, strokeWidth)
3
Example 36
Project: xraylarch Source File: mathutils.py
def complex_phase(arr, _larch=None):
"return phase, modulo 2pi jumps"
phase = np.arctan2(arr.imag, arr.real)
d = np.diff(phase)/np.pi
out = 1.0*phase[:]
out[1:] -= np.pi*(np.round(abs(d))*np.sign(d)).cuemsum()
return out
3
Example 37
Project: hyphae Source File: hyphae.py
def sandpaint_line(self,x1,y1,x2,y2,r):
dx = x1-x2
dy = y1-y2
a = arctan2(dy,dx)
dots = 2*int(r*SIZE)
scales = linspace(0,r,dots)
xp = x1 - scales*cos(a) + random(dots)*ONE*LINE_NOISE
yp = y1 - scales*sin(a) + random(dots)*ONE*LINE_NOISE
self.ctx.set_source_rgba(FRONT,FRONT,FRONT)
for x,y in zip(xp,yp):
self.ctx.rectangle(x,y,ONE,ONE)
self.ctx.fill()
3
Example 38
Project: scipy Source File: bsplines.py
def _coeff_smooth(lam):
xi = 1 - 96 * lam + 24 * lam * sqrt(3 + 144 * lam)
omeg = arctan2(sqrt(144 * lam - 1), sqrt(xi))
rho = (24 * lam - 1 - sqrt(xi)) / (24 * lam)
rho = rho * sqrt((48 * lam + 24 * lam * sqrt(3 + 144 * lam)) / xi)
return rho, omeg
3
Example 39
Project: orbitals Source File: orbitals.py
def set_distances(X,Y,A,R):
for i in xrange(NUM):
dx = X[i] - X
dy = Y[i] - Y
R[i,:] = square(dx)+square(dy)
A[i,:] = arctan2(dy,dx)
sqrt(R,R)
3
Example 40
Project: NeuroM Source File: treefunc.py
def trunk_origin_azimuth(tree, soma):
'''Angle between x-axis and vector defined by (initial tree point - soma center)
on the x-z plane.
Returns:
Angle in radians between -pi and pi
'''
vector = trunk_origin_direction(tree, soma)
return np.arctan2(vector[COLS.Z], vector[COLS.X])
3
Example 41
Project: nmrglue Source File: proc_lp.py
def root2freq(pole):
"""
Calculate the frequency from a LP root
"""
# frequency is the angle from the x-axis to the point in the complex plane
# arg(pole) / (2*pi) = atan2(imag,real) / (2*pi)
return np.arctan2(pole.imag, pole.real) / (2. * np.pi)
3
Example 42
def psi(i, j, k, offset=(25, 25, 50)):
x = i-offset[0]
y = j-offset[1]
z = k-offset[2]
th = np.arctan2(z, (x**2+y**2)**0.5)
phi = np.arctan2(y, x)
r = (x**2 + y**2 + z **2)**0.5
a0 = 1
#ps = (1./81.) * (2./np.pi)**0.5 * (1./a0)**(3/2) * (6 - r/a0) * (r/a0) * np.exp(-r/(3*a0)) * np.cos(th)
ps = (1./81.) * 1./(6.*np.pi)**0.5 * (1./a0)**(3/2) * (r/a0)**2 * np.exp(-r/(3*a0)) * (3 * np.cos(th)**2 - 1)
return ps
3
Example 43
def is_convex(self):
for (edge1, edge2) in zip(self.edges, self.edges[1:] + [self.edges[0]]):
v = edge2.dir_vector - edge1.dir_vector
angle = np.arctan2(v[1], v[0])
if angle >= np.pi or (angle < 0 and angle + 2*np.pi >= np.pi):
return False
return True
3
Example 44
@node_in_network
def read(self, node):
network = node.network
measurements = {}
p = network.pos[node]
o = network.ori[node]
for neighbor in network.neighbors(node):
v = network.pos[neighbor] - p
measurement = (arctan2(v[1], v[0]) - o) % (2 * pi)
measurement = self.probabilityFunction.getNoisyReading(measurement)
measurements.update({neighbor: measurement})
return {'AoA': measurements}
3
Example 45
Project: SHARPpy Source File: map.py
def _xytoll_stere(self, xs, ys, lambda_0, phi_0, m, rad_earth):
sign = -1 if (phi_0 < 0) else 1
lon = (lambda_0 + 90 - sign * np.degrees(np.arctan2(ys, xs)))
lat = sign * np.degrees(2 * np.arctan(rad_earth * m * (1 + sign * np.sin(np.radians(phi_0))) / np.hypot(xs, ys)) - np.pi / 2)
if lon < -180: lon += 360
elif lon > 180: lon -= 360
return lat, lon
3
Example 46
Project: pypot Source File: optitrack.py
def quat2euler(q):
qx, qy, qz, qw = q
sqx, sqy, sqz, sqw = q ** 2
invs = 1.0 / (sqx + sqy + sqz + sqw)
yaw = numpy.arctan2(2.0 * (qx * qz + qy * qw) * invs, (sqx - sqy - sqz + sqw) * invs)
pitch = -numpy.arcsin(2.0 * (qx * qy - qz * qw) * invs)
roll = numpy.arctan2(2.0 * (qy * qz + qx * qw) * invs, (-sqx + sqy - sqz + sqw) * invs)
return numpy.array((yaw, pitch, roll))
3
Example 47
def psi(i, j, k, offset=(50,50,100)):
x = i-offset[0]
y = j-offset[1]
z = k-offset[2]
th = np.arctan2(z, (x**2+y**2)**0.5)
phi = np.arctan2(y, x)
r = (x**2 + y**2 + z **2)**0.5
a0 = 2
#ps = (1./81.) * (2./np.pi)**0.5 * (1./a0)**(3/2) * (6 - r/a0) * (r/a0) * np.exp(-r/(3*a0)) * np.cos(th)
ps = (1./81.) * 1./(6.*np.pi)**0.5 * (1./a0)**(3/2) * (r/a0)**2 * np.exp(-r/(3*a0)) * (3 * np.cos(th)**2 - 1)
return ps
3
Example 48
def _angle(self, v1, v2):
""" Compute the angle difference between two vectors
:param v1: The x,y coordinates of the vector
:type: v1: list
:param v2: The x,y coordinates of the vector
:type: v2: list
:rtype: float
"""
angle_diff = np.arctan2(v1[0], v1[1]) - np.arctan2(v2[0], v2[1])
if angle_diff < 0:
angle_diff += 2 * np.pi
return angle_diff
3
Example 49
Project: trackpy Source File: masks.py
@memo
def theta_mask(radius):
"""Mask of values giving angular position relative to center. The angle is
defined according to ISO standards in which the angle is measured counter-
clockwise from the x axis, measured in a normal coordinate system with y-
axis pointing up and x axis pointing right.
In other words: for increasing angle, the coordinate moves counterclockwise
around the feature center starting on the right side.
However, in most images, the y-axis will point down so that the coordinate
will appear to move clockwise around the feature center.
"""
# 2D only
radius = validate_tuple(radius, 2)
tan_of_coord = lambda y, x: np.arctan2(y - radius[0], x - radius[1])
return np.fromfunction(tan_of_coord, [r * 2 + 1 for r in radius])
3
Example 50
Project: PyCV-time Source File: opt_flow.py
def draw_hsv(flow):
h, w = flow.shape[:2]
fx, fy = flow[:,:,0], flow[:,:,1]
ang = np.arctan2(fy, fx) + np.pi
v = np.sqrt(fx*fx+fy*fy)
hsv = np.zeros((h, w, 3), np.uint8)
hsv[...,0] = ang*(180/np.pi/2)
hsv[...,1] = 255
hsv[...,2] = np.minimum(v*4, 255)
bgr = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
return bgr