bezmisc.py revision 80809dee6f6d120234c4570056c9a10c063953d8
'''
Copyright (C) 2005 Aaron Spike, aaron@ekips.org
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
def rootWrapper(a,b,c,d):
if a:
#TODO: find a new cubic solver and put it here
#return solveCubicMonic(b/a,c/a,d/a)
return ()
elif b:
if det:
else:
return -c/(2.0*b),
elif c:
return 1.0*(-d/c),
return ()
#parametric bezier
#ax,ay,bx,by,cx,cy,x0,y0=bezierparameterize(((bx0,by0),(bx1,by1),(bx2,by2),(bx3,by3)))
#parametric line
if aa:
coef2=1
else:
coef1=1
#cubic intersection coefficients
roots = rootWrapper(a,b,c,d)
retval = []
for i in roots:
i = i.real
return retval
return x,y
#quadratic coefficents of slope formula
if dx:
elif dy:
else:
return []
retval = []
for i in roots:
i = i.real
return retval
'''
Approximating the arc length of a bezier curve
if:
L1 = |P0 P1| +|P1 P2| +|P2 P3|
L0 = |P0 P3|
then:
L = 1/2*L0 + 1/2*L1
ERR = L1-L0
ERR approaches 0 as the number of subdivisions (m) increases
2^-4m
Reference:
Jens Gravesen <gravesen@mat.dth.dk>
"Adaptive subdivision and the length of Bezier curves"
mat-report no. 1992-10, Mathematical Institute, The Technical
University of Denmark.
'''
box = 0
else:
len = [0]
return len[0]
# balf = Bezier Arc Length Function
def balf(t):
n = 2
multiplier = (b - a)/6.0
endsum = f(a) + f(b)
interval = (b - a)/2.0
asum = 0.0
#print multiplier, endsum, interval, asum, bsum, est1, est0
n *= 2
multiplier /= 2.0
interval /= 2.0
bsum = 0.0
#print multiplier, endsum, interval, asum, bsum, est1, est0
return est1
t = 1.0
tdiv = t
tdiv /= 2.0
if diff < 0:
t += tdiv
else:
t -= tdiv
return t
#default bezier length method
if __name__ == '__main__':
import timing
#print linebezierintersect(((,),(,)),((,),(,),(,),(,)))
#print linebezierintersect(((0,1),(0,-1)),((-1,0),(-.5,0),(.5,0),(1,0)))
tol = 0.00000001
((0,0),(0,0),(5,0),(10,0)),
((0,0),(0,0),(5,1),(10,0)),
((-10,0),(0,0),(10,0),(10,10)),
((15,10),(0,0),(10,0),(-5,10))]
'''
for curve in curves:
timing.start()
g = bezierlengthGravesen(curve,tol)
timing.finish()
gt = timing.micro()
timing.start()
s = bezierlengthSimpson(curve,tol)
timing.finish()
st = timing.micro()
print g, gt
print s, st
'''