Created
January 1, 2010 01:21
-
-
Save wiennat/267001 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Point: | |
| def __init__(self, x=0, y=0): | |
| self.x = x | |
| self.y = y | |
| def linear(a, b, t): | |
| c = Point() | |
| c.x = (b.x - a.x)*t + a.x | |
| c.y = (b.y - a.y)*t + a.y | |
| return c | |
| def bezier(a,b,c,d,t): | |
| ab = linear(a, b, t) | |
| bc = linear(b, c, t) | |
| cd = linear(c, d, t) | |
| abc = linear(ab, bc, t) | |
| bcd = linear(bc, cd, t) | |
| abcd = linear(abc, bcd, t) | |
| return abcd | |
| def bezier2(a,b,c,d,t): | |
| t1 = (1-t)**3 | |
| t2 = 3*((1-t)**2)*t | |
| t3 = 3*(1-t)*(t)**2 | |
| t4 = t**3 | |
| x = t1*a.x + t2*b.x + t3*c.x + t4*d.x | |
| y = t1*a.y + t2*b.y + t3*c.y + t4*d.y | |
| return Point(x,y) | |
| def main(): | |
| a = Point(3, 8) | |
| b = Point(4, 5) | |
| c = Point(8, 2) | |
| d = Point(5, 9) | |
| t = 0.82 | |
| e = bezier(a,b,c,d,t) | |
| print "t %f x %f y %f" % (t, e.x, e.y) | |
| e = bezier(a,b,c,d,t) | |
| print "t %f x %f y %f" % (t, e.x, e.y) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment