Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: Blog
Views: 67
Author: Vincent J. Matsko Date: 3 January 2016, Day020 Post: Envelopes I
from sage.plot.colors import rgbcolor # Don't forget to copy to a project of your own! # We have to be careful with points in Python. # To easily perform mathematical operations, we need to work with vectors, which are mathematical objects. # Then we need to use the vectors to make lines, which are graphics objects. # The color argument is a list of RGB values. def envelope (P, R, Q, n, color): # n is the number of lines in the envelope. # Converting to vectors. vP = vector(P); vR = vector(R); vQ = vector(Q); # The envelope lines will be stored here. envlines = []; for i in range(n): # remember that in Python, i will begin at 0. # Use linear interpolation here, and set the color. envlines.append(line([(n-i)/n * vP + i/n * vR, (n-i-1)/n * vR + (i+1)/n * vQ], rgbcolor=color)); # Returns the lines for use in other functions. return sum(envlines);
# Python uses the "+" to concatenate graphics elements. # Use an aspect ratio of 1 so that the scales on the x and y axes are the same. # Set the axes keyword to False so the axes don't show up. show(envelope ([0,1],[0,0],[1,0],15,(1,0.5,0)) + envelope ([0,1],[0,0],[-1,0],15,(0.5,0,1)) + envelope([0,-1],[0,0],[-1,0],15,(1,0.5,0)) + envelope([0,-1],[0,0],[1,0],15,(0.5,0,1)),aspect_ratio=1,axes=False)