# This is a script that uses Bezier curves to draw a nice # representation of the letter 'd'. The script is incomplete # in several ways. # import numpy as np import matplotlib.pyplot as pp # # Here you should define your subroutine DrawBezierCurve(). The cubic Bezier # curve is defined by 4 control points. The curve should interpolate P1 and P4. # def DrawBezierCurve( P1,P2,P3,P4,n): # t=np.linspace(0,1,n) x=1 return # # Create a vector of points to use for defining straight line segments. # Points=np.array([ [70.0, 23.0, 23.0, 23.0, 23.0, 23.0, 23.0, 0.0, 0.0, 46.0, 46.0, 70.0] , [ 4.0, 0.0, 20.0, 35.0, 107.0, 125.0, 195.0, 213.0, 222.0, 225.0, 28.0, 13.0] ]) # # Create a matrix that can be used to store the control points for the # Bezi'er curves. In the exercise you will successively add more points # into this matrix. # Control=np.array([ [ 0.0 ] , [ 0.0 ] ]) # # Code that can be used to cerate an "italic style" d. # #Points[0,:]=Points[0,:]+0.07*Points[1,:] #Control[0,:]=Control[0,:]+0.07*Control[1,:] # # Now draw the line segments of the 'd'. # pp.plot( Points[0, [11,0,1,2] ],Points[1, [11,0,1,2] ],'k' ) pp.plot( Points[0, [3,4] ], Points[1, [3,4] ],'k') pp.plot( Points[0, [5,6] ], Points[1, [5,6] ],'k') pp.plot( Points[0, [7,8,9,10] ], Points[1, [7,8,9,10] ],'k') # # Here is room to add the curve segments for the other exercises. In all cases # add the points you need to either Points or Control above. Then pick out the # 4 control points for the curve you want to draw, e.g. P1=Points[:,3] and make # a subroutine call DrawBezierCurve(P1,P2,P3,P4) # # # Finally we set the proper axis-limits and make the plot visible. # pp.xlim([-70.0,80.0]) pp.ylim([-10.0,250.0]) pp.set_aspect('equal', 'box') pp.show()