1 | initial version |
I noticed Sage plot inner structure posted on the sidebar and after some time puzzling through the details came up with the following code to work off of:
x,y = var('x,y')
gridDim = 300
xmin = -2
xmax = 2
deltax = (xmax-xmin)/(gridDim-1)
ymin = -2
ymax = 2
deltay = (ymax-ymin)/(gridDim-1)
xvals = []
yvals = []
f(x,y)=x^2+y^2-2
P=implicit_plot(f, (x,-2,2), (y,-2,2),plot_points=gridDim)
C = P._objects[0]
for i in range(0,gridDim):
for j in range(0,gridDim):
if abs(C.xy_data_array[i][j])<.02:
xvals += [xmin+j*deltax]
yvals += [ymin+i*deltay]
To look at the points on the curve add these 2 lines:
for i in range(0,len(xvals)):
print "(%f,%f),"%(xvals[i],yvals[i])
As the link showed, the default number of points is a grid of 150 by 150. I found it necessary to have a bigger grid size and the plot_points=200 makes a 200 by 200 grid of 40,000 points. The comment "Then you get the points by looking at sign changes, or values close to zero." refers to the fact that most of those points aren't plotted. The actual points that end up getting plotted from the grid are just those where the value is small--I chose abs(C.xy_data_array[i][j])<.02 and have been getting expected results..
2 | No.2 Revision |
I noticed Sage plot inner structure posted on the sidebar and after some time puzzling through the details came up with the following code to work off of:
x,y = var('x,y')
gridDim = 300
xmin = -2
xmax = 2
deltax = (xmax-xmin)/(gridDim-1)
ymin = -2
ymax = 2
deltay = (ymax-ymin)/(gridDim-1)
xvals = []
yvals = []
f(x,y)=x^2+y^2-2
P=implicit_plot(f, (x,-2,2), (y,-2,2),plot_points=gridDim)
(x,xmin,xmax), (y,ymin,ymax),plot_points=gridDim)
C = P._objects[0]
for i in range(0,gridDim):
for j in range(0,gridDim):
if abs(C.xy_data_array[i][j])<.02:
xvals += [xmin+j*deltax]
yvals += [ymin+i*deltay]
To look at the points on the curve add these 2 lines:
for i in range(0,len(xvals)):
print "(%f,%f),"%(xvals[i],yvals[i])
As the link showed, the default number of points is a grid of 150 by 150. I found it necessary to have a bigger grid size and the plot_points=200 makes a 200 by 200 grid of 40,000 points. The comment "Then you get the points by looking at sign changes, or values close to zero." refers to the fact that most of those points aren't plotted. The actual points that end up getting plotted from the grid are just those where the value f(x,y) is small--I close to 0--I chose abs(C.xy_data_array[i][j])<.02 and have been getting expected results.. results.