Commit 28e92c3a authored by Jayant Khatkar's avatar Jayant Khatkar
Browse files

4 sides of cube, curved

parent 32c5a171
...@@ -4,6 +4,7 @@ from gcode2contour import Position, contour ...@@ -4,6 +4,7 @@ from gcode2contour import Position, contour
from sympy.plotting import plot3d from sympy.plotting import plot3d
from mpl_toolkits.mplot3d import Axes3D from mpl_toolkits.mplot3d import Axes3D
import matplotlib.colors as mcolors import matplotlib.colors as mcolors
from copy import deepcopy, copy
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
...@@ -115,6 +116,36 @@ class solver: ...@@ -115,6 +116,36 @@ class solver:
return v1, zs return v1, zs
def trim_contour(self, c, zlims):
"""
take a contour and split it at z limits
returns a list of contours.
This list will be the original contour if it doesnt reach out of the limits
If it doesn, regions outside the limits will be cut off, and regions inside
will be split
"""
c_out = []
j = 0 # index of last intersection with limit
state = zlims[0] < c.pos[0][2] < zlims[1]
for i, pos in enumerate(c):
if (zlims[0] < pos[2] < zlims[1]) is not state:
# State change has happened
if state:
# Leaving zlim, save contour so far
c_out.append(contour(c.pos[j:i],0))
else:
# Entering zlim, set start point
j = i
state = not state #save new state
if state:
# the last stretch was in range
c_out.append(contour(c.pos[j:i],0))
return c_out
def contour_n(self, n): def contour_n(self, n):
""" """
Get 4 contours for the nth layer Get 4 contours for the nth layer
...@@ -125,22 +156,33 @@ class solver: ...@@ -125,22 +156,33 @@ class solver:
expr1 = self.plane_intersection(self.x, self.range[self.x][0], layer = n) expr1 = self.plane_intersection(self.x, self.range[self.x][0], layer = n)
ys, zs = self.sample(expr1, self.y) ys, zs = self.sample(expr1, self.y)
contours.append(contour([Position(self.range[self.x][0],ys[i],zs[i]) for i in range(len(ys))], 0)) contours += self.trim_contour(
contour([Position(self.range[self.x][0],ys[i],zs[i]) for i in range(len(ys))], 0),
self.range[self.z]
)
expr2 = self.plane_intersection(self.x, self.range[self.x][1], layer = n) expr2 = self.plane_intersection(self.x, self.range[self.x][1], layer = n)
ys, zs = self.sample(expr2, self.y) ys, zs = self.sample(expr2, self.y)
contours.append(contour([Position(self.range[self.x][1],ys[i],zs[i]) for i in range(len(ys))], 0)) contours += self.trim_contour(
contour([Position(self.range[self.x][1],ys[i],zs[i]) for i in range(len(ys))], 0),
self.range[self.z]
)
expr3 = self.plane_intersection(self.y, self.range[self.y][0], layer = n) expr3 = self.plane_intersection(self.y, self.range[self.y][0], layer = n)
xs, zs = self.sample(expr3, self.x) xs, zs = self.sample(expr3, self.x)
contours.append(contour([Position(xs[i],self.range[self.y][0],zs[i]) for i in range(len(ys))], 0)) contours += self.trim_contour(
contour([Position(xs[i],self.range[self.y][0],zs[i]) for i in range(len(ys))], 0),
self.range[self.z]
)
expr4 = self.plane_intersection(self.y, self.range[self.y][1], layer = n) expr4 = self.plane_intersection(self.y, self.range[self.y][1], layer = n)
xs, zs = self.sample(expr4, self.x) xs, zs = self.sample(expr4, self.x)
contours.append(contour([Position(xs[i],self.range[self.y][1],zs[i]) for i in range(len(ys))], 0)) contours += self.trim_contour(
contour([Position(xs[i],self.range[self.y][1],zs[i]) for i in range(len(ys))], 0),
self.range[self.z]
)
# TODO Join the 4 contours into one # TODO Join adjacent contours into one
# TODO break up contours at z limits
return contours return contours
...@@ -155,10 +197,10 @@ class solver: ...@@ -155,10 +197,10 @@ class solver:
if __name__ == '__main__': if __name__ == '__main__':
s = solver(0.02, 100, 100, 0.01) s = solver(0.02, 100, 100, 0.003)
contours = [] contours = []
for i in range(10): for i in np.arange(-15,55):
contours += s.contour_n(i) contours += s.contour_n(i)
plot_contours(contours) plot_contours(contours)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment