Since I have been writing a big python program for my project. I have another query of which I cant figure out the solution. Here is the code.
poly = [[k6,3], [k5,2], [k4,1], [k0,0]]
w = 5 # weight for rational bezier curve equation
def time() :
with open(transcriptionFile, "r") as tFile :
for line in tFile :
li = line.split()
if li :
start_time = (int(li[0]) / 10000000.)
end_time = (int(li[1]) / 10000000.)
duration = ((int(li[1]) -int(li[0]))/10000000.)
print start_time,' ',end_time,' ',duration
poly_coeff(start_time, end_time, duration)
def poly_coeff(stime, etime, dur) :
"""The equation is k6 * u^3 + k5 * u^2 + k4 * u + k0 = 0. Computing the coefficients of this equation."""
"""Substituting the required values we get the coefficients."""
t_u = dur
t0 = stime
t3 = etime
t1 = t2 = (stime + etime) / 2
w0 = w1 = w2 = w3 = w
k0 = w0 * (t_u - t0)
k1 = w1 * (t_u - t1)
k2 = w2 * (t_u - t2)
k3 = w3 * (t_u - t3)
k4 = 3 * (k1 - k0)
k5 = 3 * (k2 - 2 * k1 + k0)
k6 = k3 - 3 * k2 + 3 * k1 -k0
print k0, k1, k2, k3, k4, k5, k6
if __name__ == "__main__" :
if len(sys.argv) != 2 :
Usage()
else :
transcriptionFile = sys.argv[1]
time()
Newton(poly, 0.42, 1, 0)
There is a list of start time, end time and their duration. All of them are passed to the function poly_coeff() to generate the polynomial coefficients. There will be as many as there are in the list. Then for each polynomial generated, its corresponding coefficients should be passed as poly to Newton() function to carry out other calculations. And at the top, the polynomial is represented as poly. In poly, each k6, k5, k4 and k0 values generated should be passed. Of course it is not how to do but just to clear what I am trying to do. Please help. Thank you very much.
The flow of your code was quite confusing. I assume that you want to calculate the poly for each line of your input file, then call
Newton(poly, 0.42, 1, 0).I changed your
time()function to take the filename as a parameter, and changed your poly_coeff method to return the poly you have calculated. Then in thefor line in tFile:loop intime(), I get the result frompoly_coeff()and pass that intoNewton().Hopefully that is close to what you want to do…