Re: pathing

new topic     » topic index » view thread      » older message » newer message

Hello Barbarella again,

See two functions more, pure sequence math,
without additional loop.

Results for code 1 are:

36.85
36.8
36.85
36.8

Results for code 2 are:

36.53
36.52
36.53
36.53


--- code 1
sequence  P1, P2, P3, P4, curve
    P1={0,0}
    P2={0,0}
    P3={0,0}
    P4={0,0}
global function Bezier_curve(integer points, 
				sequence p1,  
				sequence p2,
				sequence p3,  
				sequence p4)
    atom t, tsq, omt, omtsq, delta
    curve = repeat({0,0}, points)
    delta = 1 / (points - 1)
    t = 0.0
    for i = 1 to points do
	omt = 1.0 - t
      omtsq = omt * omt
	tsq =  t * t
	 P1 = p1 * (omtsq * omt)
	 P2 = p2 * (3 * omtsq * t)
	 P3 = p3 * (3 * omt * tsq)
	 P4 = p4 * (t * tsq)
   curve[i] = P1 + P2 + P3 + P4
	 t += delta
    end for
    return curve
end function
--- end of code 1

--- code 2
sequence curve
global function Bezier_curve(integer points, 
				sequence p1,  
				sequence p2,
				sequence p3,  
				sequence p4)
    atom t, tsq, omt, omtsq, delta
    curve = repeat({0,0}, points)
    delta = 1 / (points - 1)
    t = 0.0
    for i = 1 to points do
	omt = 1.0 - t
    omtsq = omt * omt
	tsq = t * t
 curve[i] = (p1 * (omtsq * omt  )) +
	      (p2 * (3 * omtsq * t)) +
	      (p3 * (3 * omt * tsq)) +
	      (p4 * (t * tsq      ))

	 t += delta
    end for
    return curve
end function
--- end of code 2


Regards,
Igor Kachan
kinz at peterlink.ru

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu