arc.point now supports numpy arrays and math and cmath functions now imported from numpy
parent
69e2e27efb
commit
1c9363d426
|
@ -4,8 +4,6 @@ Arc."""
|
||||||
|
|
||||||
# External dependencies
|
# External dependencies
|
||||||
from __future__ import division, absolute_import, print_function
|
from __future__ import division, absolute_import, print_function
|
||||||
from math import sqrt, cos, sin, tan, acos, asin, degrees, radians, log, pi, ceil
|
|
||||||
from cmath import exp, sqrt as csqrt, phase
|
|
||||||
import re
|
import re
|
||||||
try:
|
try:
|
||||||
from collections.abc import MutableSequence # noqa
|
from collections.abc import MutableSequence # noqa
|
||||||
|
@ -14,6 +12,13 @@ except ImportError:
|
||||||
from warnings import warn
|
from warnings import warn
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
# these imports were originally from math and cmath, now are from numpy
|
||||||
|
# in order to encourage code that generalizes to vector inputs
|
||||||
|
from numpy import sqrt, cos, sin, tan, arccos as acos, arcsin as asin, \
|
||||||
|
degrees, radians, log, pi, ceil
|
||||||
|
from numpy import exp, sqrt as csqrt, angle as phase
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from scipy.integrate import quad
|
from scipy.integrate import quad
|
||||||
_quad_available = True
|
_quad_available = True
|
||||||
|
@ -859,7 +864,8 @@ class QuadraticBezier(object):
|
||||||
|
|
||||||
def point(self, t):
|
def point(self, t):
|
||||||
"""returns the coordinates of the Bezier curve evaluated at t."""
|
"""returns the coordinates of the Bezier curve evaluated at t."""
|
||||||
return (1 - t)**2*self.start + 2*(1 - t)*t*self.control + t**2*self.end
|
tc = 1 - t
|
||||||
|
return tc*tc*self.start + 2*tc*t*self.control + t*t*self.end
|
||||||
|
|
||||||
def points(self, ts):
|
def points(self, ts):
|
||||||
"""Faster than running Path.point many times."""
|
"""Faster than running Path.point many times."""
|
||||||
|
@ -1522,20 +1528,16 @@ class Arc(object):
|
||||||
self.delta += 360
|
self.delta += 360
|
||||||
|
|
||||||
def point(self, t):
|
def point(self, t):
|
||||||
if t == 0:
|
|
||||||
return self.start
|
angle = (self.theta + t*self.delta)*pi/180
|
||||||
if t == 1:
|
|
||||||
return self.end
|
|
||||||
angle = radians(self.theta + t*self.delta)
|
|
||||||
cosphi = self.rot_matrix.real
|
cosphi = self.rot_matrix.real
|
||||||
sinphi = self.rot_matrix.imag
|
sinphi = self.rot_matrix.imag
|
||||||
rx = self.radius.real
|
rx = self.radius.real
|
||||||
ry = self.radius.imag
|
ry = self.radius.imag
|
||||||
|
|
||||||
# z = self.rot_matrix*(rx*cos(angle) + 1j*ry*sin(angle)) + self.center
|
|
||||||
x = rx*cosphi*cos(angle) - ry*sinphi*sin(angle) + self.center.real
|
x = rx*cosphi*cos(angle) - ry*sinphi*sin(angle) + self.center.real
|
||||||
y = rx*sinphi*cos(angle) + ry*cosphi*sin(angle) + self.center.imag
|
y = rx*sinphi*cos(angle) + ry*cosphi*sin(angle) + self.center.imag
|
||||||
return complex(x, y)
|
return x + y*1j
|
||||||
|
|
||||||
def point_to_t(self, point):
|
def point_to_t(self, point):
|
||||||
"""If the point lies on the Arc, returns its `t` parameter.
|
"""If the point lies on the Arc, returns its `t` parameter.
|
||||||
|
|
Loading…
Reference in New Issue