def calculate_trajectory(self): patternLength = self.pattern.length if self.trajectory_type == "coordinate": values = [(v.x, v.y) for v in self.trajectory_set] t = 0.0 self.values = [] # calculate the initial value self.values.append( bezier(values[0], values[1], values[2], values[3], t)) dt = 1.0 / (patternLength - 1) for i in xrange(1, patternLength): t += dt self.values.append( bezier(values[0], values[1], values[2], values[3], t)) elif self.trajectory_type == "boolean": ft_set = self.trajectory_set.order_by('instrument') self.values = [ i for i in xrange(ft_set.count()) if ft_set[i].value ] else: ft_set = self.trajectory_set.order_by('instrument') self.values = [(i, ft_set[i].value) for i in xrange(ft_set.count())]
def exer1_4(): """ Split a bezier curve defined by control vertexes in a specific point of the parametric domain. """ V = np.array([[0,0,0],[1,2,0],[3,2,3],[2,6,2]]) C1,C2 = fn.splitControlPoints(V, 0.6) fn.drawVertexes(fn.bezier(C1)) fn.drawVertexes(C1) fn.drawVertexes(C1,'o') fn.drawVertexes(fn.bezier(C2)) fn.drawVertexes(C2) fn.drawVertexes(C2,'o')
def exer1_7(): """ Given the control vertexes of a Bezier curve and a set of extra vertexes, attach the extra vertexes to the original ones with the chosen continuity (some vertexes will be created). """ V = np.array([[0,0,0],[1,2,0],[3,2,0],[6,-1,0]]) Va = fn.attachWithC(V, np.array([[2,-1,3]]),C=2,hOrig=1.,hAttach=1.) fn.drawVertexes(fn.bezier(V)) fn.drawVertexes(V) fn.drawVertexes(V,'o') fn.drawVertexes(fn.bezier(Va)) fn.drawVertexes(Va) fn.drawVertexes(Va,'o')
def exer1_5(): """ Show the effects of the increase of the multiplicity of a control vertex of a Bezier curve. """ V1 = np.array([[0,0,0],[1,2,0],[3,2,3],[2,6,2]]) V2 = np.array([[0,0,0],[1,2,0],[3,2,3],[3,2,3],[2,6,2]]) V3 = np.array([[0,0,0],[1,2,0],[3,2,3],[3,2,3],[3,2,3],[2,6,2]]) V4 = np.array([[0,0,0],[1,2,0],[3,2,3],[3,2,3],[3,2,3],[3,2,3],[2,6,2]]) fn.drawVertexes(V1) fn.drawVertexes(V1,'o') fn.drawVertexes(fn.bezier(V1)) fn.drawVertexes(fn.bezier(V2)) fn.drawVertexes(fn.bezier(V3)) fn.drawVertexes(fn.bezier(V4))
def exer1_2(): """ Draw a Bezier curve using De Casteljau algorithm. """ V = np.array([[0,0,0],[1,2,0],[3,2,3],[2,6,2]]) fn.drawVertexes(fn.bezier(V)) fn.drawVertexes(V) fn.drawVertexes(V,'o')
def exer1_3(): """ Calculate the Bezier curve of the parametric curve: X(t)=1+t+t^2 Y(t)=t^3 for t in [0,1]. """ X = sympy.Poly('1+t+t**2') Y = sympy.Poly('t**3') P = fn.mergePoly(X,Y) #P = np.array([[1,0],[1,0],[1,0],[0,1]]) V = fn.exp2bernstein(P) fn.drawVertexes(fn.bezier(V)) fn.drawVertexes(V) fn.drawVertexes(V,'o')
def exer1_6(): """ Increase the grade of a Bezier curve defined by his control vertexes. """ V = np.array([[0,0,0],[1,2,0],[3,2,3],[2,6,2]]) V1 = fn.increaseGrade(V) V2 = fn.increaseGrade(V1) V3 = fn.increaseGrade(V2) fn.drawVertexes(fn.bezier(V)) fn.drawVertexes(V) fn.drawVertexes(V,'o') fn.drawVertexes(V1) fn.drawVertexes(V1,'o') fn.drawVertexes(V2) fn.drawVertexes(V2,'o') fn.drawVertexes(V3) fn.drawVertexes(V3,'o')