Submitted to Pattern Recognition Letters
Alberto Ruiz, aruiz@um.es
Derivation of the expressions using sympy.
from sympy import *
init_printing(pretty_print=True)
v,b,c,r = symbols('v b c r')
t,t_0,t_1 = symbols('t t_0 t_1', positive=True)
w = symbols('omega', integer=True)
# Fourier basis
def H(w,t):
return exp(2*pi*I*w*t)
H0 = exp(-2*pi*I*t_0)**w
H1 = exp(-2*pi*I*t_1)**w
Check of equation (7):
arc = c + r*exp(I*(b + v*t))
S1 = integrate(conjugate(H(w,t)) * arc, (t,t_0,t_1), conds='none')
S1
def alpha(w,x):
return I*(x-c)/(2*pi*w - v) + I*c/(2*pi*w)
P = c + r*exp(I*(v*t_0+b))
Q = c + r*exp(I*(v*t_1+b))
S2 = (alpha(w,Q)*H1 - alpha(w,P)*H0)
S2
(S1-S2).simplify()
Special cases:
integrate(conjugate(H(0,t)) * arc, (t,t_0,t_1), conds='none')
Limit(S1,v,2*pi*w).doit().expand()
Check of equation (15):
seg = b + v*t
S1 = integrate(conjugate(H(w,t)) * seg, (t,t_0,t_1), conds='none')
S1
def alpha(w,x):
return I*x/(2*pi*w) + v/(2*pi*w)**2
P = v*t_0+b
Q = v*t_1+b
S2 = (alpha(w,Q)*H1 - alpha(w,P)*H0)
S2
(S1-S2).simplify()
Special case:
integrate(conjugate(H(0,t)) * seg, (t,t_0,t_1), conds='none')
arcs
nor = (conjugate(arc)*arc).expand().subs({conjugate(v):v,conjugate(b):b,conjugate(r):r})
nor
integrate(nor, t, conds='none').simplify()
segments
nor = (conjugate(seg)*seg).expand()
nor
integrate(nor, t, conds='none').expand().simplify()
from sympy import *
init_printing(pretty_print=True)
def show(x):
display(x)
print()
print('Python:', str(x))
print()
print('LaTeX:', latex(x))
Parameterization:
x_1,x_2,y_1,y_2 = symbols('x_1 x_2 y_1 y_2')
c_x,c_y,r,a,b,t = symbols('c_x c_y r a b t')
x=c_x+r*cos(b+a*t)
y=c_y+r*sin(b+a*t)
Definition of moment:
def m(p,q):
return -x**p * y**(q+1) * x.diff(t) /(q+1)/2 + x**(p+1) * y**q *y.diff(t) /(p+1)/2
Rewrite the results in terms of the extremes of the arc:
def sus(x):
return x.subs({r*cos(b):x_1, r*sin(b):y_1, r*cos(a+b):x_2, r*sin(a+b):y_2 })
Generation of the desired moments:
M00 = sus(integrate(m(0,0),(t,0,1),conds='none').expand())
show(2*M00)
Python: a*x_2**2 + a*y_2**2 - c_x*y_1 + c_x*y_2 + c_y*x_1 - c_y*x_2 LaTeX: a x_{2}^{2} + a y_{2}^{2} - c_{x} y_{1} + c_{x} y_{2} + c_{y} x_{1} - c_{y} x_{2}
Quick check with the area of a circle:
M00.subs({a:2*pi,y_2:y_1,x_2:x_1}).simplify().subs({x_1:r,y_1:0})
M10 = sus(integrate(m(1,0),(t,0,1),conds='none').expand())
show(12*M10)
Python: 6*a*c_x*x_2**2 + 6*a*c_x*y_2**2 - 3*c_x**2*y_1 + 3*c_x**2*y_2 + 6*c_x*c_y*x_1 - 6*c_x*c_y*x_2 + 3*c_y*x_1**2 - 3*c_y*x_2**2 - 3*x_1**2*y_1 + 3*x_2**2*y_2 - 4*y_1**3 + 4*y_2**3 LaTeX: 6 a c_{x} x_{2}^{2} + 6 a c_{x} y_{2}^{2} - 3 c_{x}^{2} y_{1} + 3 c_{x}^{2} y_{2} + 6 c_{x} c_{y} x_{1} - 6 c_{x} c_{y} x_{2} + 3 c_{y} x_{1}^{2} - 3 c_{y} x_{2}^{2} - 3 x_{1}^{2} y_{1} + 3 x_{2}^{2} y_{2} - 4 y_{1}^{3} + 4 y_{2}^{3}
M01 = sus(integrate(m(0,1),(t,0,1),conds='none').expand())
show(12*M01)
Python: 6*a*c_y*x_2**2 + 6*a*c_y*y_2**2 - 6*c_x*c_y*y_1 + 6*c_x*c_y*y_2 + 3*c_x*x_1**2 - 3*c_x*x_2**2 + 3*c_y**2*x_1 - 3*c_y**2*x_2 + 4*x_1**3 + 3*x_1*y_1**2 - 4*x_2**3 - 3*x_2*y_2**2 LaTeX: 6 a c_{y} x_{2}^{2} + 6 a c_{y} y_{2}^{2} - 6 c_{x} c_{y} y_{1} + 6 c_{x} c_{y} y_{2} + 3 c_{x} x_{1}^{2} - 3 c_{x} x_{2}^{2} + 3 c_{y}^{2} x_{1} - 3 c_{y}^{2} x_{2} + 4 x_{1}^{3} + 3 x_{1} y_{1}^{2} - 4 x_{2}^{3} - 3 x_{2} y_{2}^{2}
M20 = sus(integrate(m(2,0),(t,0,1),conds='none').expand())
show(24*M20)
Python: 12*a*c_x**2*x_2**2 + 12*a*c_x**2*y_2**2 + 3*a*x_2**4 + 6*a*x_2**2*y_2**2 + 3*a*y_2**4 - 4*c_x**3*y_1 + 4*c_x**3*y_2 + 12*c_x**2*c_y*x_1 - 12*c_x**2*c_y*x_2 + 12*c_x*c_y*x_1**2 - 12*c_x*c_y*x_2**2 - 12*c_x*x_1**2*y_1 + 12*c_x*x_2**2*y_2 - 16*c_x*y_1**3 + 16*c_x*y_2**3 + 4*c_y*x_1**3 - 4*c_y*x_2**3 - x_1**3*y_1 - 3*x_1*y_1**3 + x_2**3*y_2 + 3*x_2*y_2**3 LaTeX: 12 a c_{x}^{2} x_{2}^{2} + 12 a c_{x}^{2} y_{2}^{2} + 3 a x_{2}^{4} + 6 a x_{2}^{2} y_{2}^{2} + 3 a y_{2}^{4} - 4 c_{x}^{3} y_{1} + 4 c_{x}^{3} y_{2} + 12 c_{x}^{2} c_{y} x_{1} - 12 c_{x}^{2} c_{y} x_{2} + 12 c_{x} c_{y} x_{1}^{2} - 12 c_{x} c_{y} x_{2}^{2} - 12 c_{x} x_{1}^{2} y_{1} + 12 c_{x} x_{2}^{2} y_{2} - 16 c_{x} y_{1}^{3} + 16 c_{x} y_{2}^{3} + 4 c_{y} x_{1}^{3} - 4 c_{y} x_{2}^{3} - x_{1}^{3} y_{1} - 3 x_{1} y_{1}^{3} + x_{2}^{3} y_{2} + 3 x_{2} y_{2}^{3}
M02 = sus(integrate(m(0,2),(t,0,1),conds='none').expand())
show(24*M02)
Python: 12*a*c_y**2*x_2**2 + 12*a*c_y**2*y_2**2 + 3*a*x_2**4 + 6*a*x_2**2*y_2**2 + 3*a*y_2**4 - 12*c_x*c_y**2*y_1 + 12*c_x*c_y**2*y_2 + 12*c_x*c_y*x_1**2 - 12*c_x*c_y*x_2**2 - 4*c_x*y_1**3 + 4*c_x*y_2**3 + 4*c_y**3*x_1 - 4*c_y**3*x_2 + 16*c_y*x_1**3 + 12*c_y*x_1*y_1**2 - 16*c_y*x_2**3 - 12*c_y*x_2*y_2**2 + 3*x_1**3*y_1 + x_1*y_1**3 - 3*x_2**3*y_2 - x_2*y_2**3 LaTeX: 12 a c_{y}^{2} x_{2}^{2} + 12 a c_{y}^{2} y_{2}^{2} + 3 a x_{2}^{4} + 6 a x_{2}^{2} y_{2}^{2} + 3 a y_{2}^{4} - 12 c_{x} c_{y}^{2} y_{1} + 12 c_{x} c_{y}^{2} y_{2} + 12 c_{x} c_{y} x_{1}^{2} - 12 c_{x} c_{y} x_{2}^{2} - 4 c_{x} y_{1}^{3} + 4 c_{x} y_{2}^{3} + 4 c_{y}^{3} x_{1} - 4 c_{y}^{3} x_{2} + 16 c_{y} x_{1}^{3} + 12 c_{y} x_{1} y_{1}^{2} - 16 c_{y} x_{2}^{3} - 12 c_{y} x_{2} y_{2}^{2} + 3 x_{1}^{3} y_{1} + x_{1} y_{1}^{3} - 3 x_{2}^{3} y_{2} - x_{2} y_{2}^{3}
M11 = sus(integrate(m(1,1),(t,0,1),conds='none').expand())
show(48*M11)
Python: 24*a*c_x*c_y*x_2**2 + 24*a*c_x*c_y*y_2**2 - 12*c_x**2*c_y*y_1 + 12*c_x**2*c_y*y_2 + 6*c_x**2*x_1**2 - 6*c_x**2*x_2**2 + 12*c_x*c_y**2*x_1 - 12*c_x*c_y**2*x_2 + 16*c_x*x_1**3 + 12*c_x*x_1*y_1**2 - 16*c_x*x_2**3 - 12*c_x*x_2*y_2**2 + 6*c_y**2*x_1**2 - 6*c_y**2*x_2**2 - 12*c_y*x_1**2*y_1 + 12*c_y*x_2**2*y_2 - 16*c_y*y_1**3 + 16*c_y*y_2**3 + 6*x_1**4 + 6*x_1**2*y_1**2 - 6*x_2**4 - 6*x_2**2*y_2**2 LaTeX: 24 a c_{x} c_{y} x_{2}^{2} + 24 a c_{x} c_{y} y_{2}^{2} - 12 c_{x}^{2} c_{y} y_{1} + 12 c_{x}^{2} c_{y} y_{2} + 6 c_{x}^{2} x_{1}^{2} - 6 c_{x}^{2} x_{2}^{2} + 12 c_{x} c_{y}^{2} x_{1} - 12 c_{x} c_{y}^{2} x_{2} + 16 c_{x} x_{1}^{3} + 12 c_{x} x_{1} y_{1}^{2} - 16 c_{x} x_{2}^{3} - 12 c_{x} x_{2} y_{2}^{2} + 6 c_{y}^{2} x_{1}^{2} - 6 c_{y}^{2} x_{2}^{2} - 12 c_{y} x_{1}^{2} y_{1} + 12 c_{y} x_{2}^{2} y_{2} - 16 c_{y} y_{1}^{3} + 16 c_{y} y_{2}^{3} + 6 x_{1}^{4} + 6 x_{1}^{2} y_{1}^{2} - 6 x_{2}^{4} - 6 x_{2}^{2} y_{2}^{2}
sus(integrate(m(3,0),(t,0,1),conds='none').expand())
etc...
x = x_1 + (x_2-x_1)*t
y = y_1 + (y_2-y_1)*t
def m(p,q):
return -x**p * y**(q+1) * x.diff(t) /(q+1)/2 + x**(p+1) * y**q *y.diff(t) /(p+1)/2
M00 = integrate(m(0,0),(t,0,1),conds='none').expand()
show(2*M00)
Python: x_1*y_2 - x_2*y_1 LaTeX: x_{1} y_{2} - x_{2} y_{1}
M10 = integrate(m(1,0),(t,0,1),conds='none').expand()
show(12*M10)
Python: x_1**2*y_1 + 2*x_1**2*y_2 - 2*x_1*x_2*y_1 + 2*x_1*x_2*y_2 - 2*x_2**2*y_1 - x_2**2*y_2 LaTeX: x_{1}^{2} y_{1} + 2 x_{1}^{2} y_{2} - 2 x_{1} x_{2} y_{1} + 2 x_{1} x_{2} y_{2} - 2 x_{2}^{2} y_{1} - x_{2}^{2} y_{2}
M01 = integrate(m(0,1),(t,0,1),conds='none').expand()
show(12*M01)
Python: -x_1*y_1**2 + 2*x_1*y_1*y_2 + 2*x_1*y_2**2 - 2*x_2*y_1**2 - 2*x_2*y_1*y_2 + x_2*y_2**2 LaTeX: - x_{1} y_{1}^{2} + 2 x_{1} y_{1} y_{2} + 2 x_{1} y_{2}^{2} - 2 x_{2} y_{1}^{2} - 2 x_{2} y_{1} y_{2} + x_{2} y_{2}^{2}
M20 = integrate(m(2,0),(t,0,1),conds='none').expand()
show(12*M20)
Python: x_1**3*y_1 + x_1**3*y_2 - x_1**2*x_2*y_1 + x_1**2*x_2*y_2 - x_1*x_2**2*y_1 + x_1*x_2**2*y_2 - x_2**3*y_1 - x_2**3*y_2 LaTeX: x_{1}^{3} y_{1} + x_{1}^{3} y_{2} - x_{1}^{2} x_{2} y_{1} + x_{1}^{2} x_{2} y_{2} - x_{1} x_{2}^{2} y_{1} + x_{1} x_{2}^{2} y_{2} - x_{2}^{3} y_{1} - x_{2}^{3} y_{2}
M02 = integrate(m(0,2),(t,0,1),conds='none').expand()
show(12*M02)
Python: -x_1*y_1**3 + x_1*y_1**2*y_2 + x_1*y_1*y_2**2 + x_1*y_2**3 - x_2*y_1**3 - x_2*y_1**2*y_2 - x_2*y_1*y_2**2 + x_2*y_2**3 LaTeX: - x_{1} y_{1}^{3} + x_{1} y_{1}^{2} y_{2} + x_{1} y_{1} y_{2}^{2} + x_{1} y_{2}^{3} - x_{2} y_{1}^{3} - x_{2} y_{1}^{2} y_{2} - x_{2} y_{1} y_{2}^{2} + x_{2} y_{2}^{3}
M11 = integrate(m(1,1),(t,0,1),conds='none').expand()
show(24*M11)
Python: 2*x_1**2*y_1*y_2 + x_1**2*y_2**2 - 2*x_1*x_2*y_1**2 + 2*x_1*x_2*y_2**2 - x_2**2*y_1**2 - 2*x_2**2*y_1*y_2 LaTeX: 2 x_{1}^{2} y_{1} y_{2} + x_{1}^{2} y_{2}^{2} - 2 x_{1} x_{2} y_{1}^{2} + 2 x_{1} x_{2} y_{2}^{2} - x_{2}^{2} y_{1}^{2} - 2 x_{2}^{2} y_{1} y_{2}