small change in paperfold
This commit is contained in:
parent
b11ee2f93a
commit
5790a0f5ed
@ -55,7 +55,8 @@ class Paperfold(inkex.EffectExtension):
|
|||||||
# Compute the third point of a triangle when two points and all edge lengths are given
|
# Compute the third point of a triangle when two points and all edge lengths are given
|
||||||
def getThirdPoint(self, v0, v1, l01, l12, l20):
|
def getThirdPoint(self, v0, v1, l01, l12, l20):
|
||||||
v2rotx = (l01 ** 2 + l20 ** 2 - l12 ** 2) / (2 * l01)
|
v2rotx = (l01 ** 2 + l20 ** 2 - l12 ** 2) / (2 * l01)
|
||||||
v2roty0 = np.sqrt((l01 + l20 + l12) * (l01 + l20 - l12) * (l01 - l20 + l12) * (-l01 + l20 + l12)) / (2 * l01)
|
val = (l01 + l20 + l12) * (l01 + l20 - l12) * (l01 - l20 + l12) * (-l01 + l20 + l12)
|
||||||
|
v2roty0 = np.sqrt(abs(val)) / (2 * l01)
|
||||||
|
|
||||||
v2roty1 = - v2roty0
|
v2roty1 = - v2roty0
|
||||||
|
|
||||||
@ -144,6 +145,10 @@ class Paperfold(inkex.EffectExtension):
|
|||||||
dihedralAngles = np.empty(numUnfoldedEdges, dtype=float) # Valley folding or mountain folding
|
dihedralAngles = np.empty(numUnfoldedEdges, dtype=float) # Valley folding or mountain folding
|
||||||
connections = np.empty(numFaces, dtype=int) # Saves which original triangle belongs to the unrolled one
|
connections = np.empty(numFaces, dtype=int) # Saves which original triangle belongs to the unrolled one
|
||||||
|
|
||||||
|
numFaces = mesh.n_faces()
|
||||||
|
sizeTree = spanningTree.number_of_edges()
|
||||||
|
numUnfoldedEdges = 3 * numFaces - sizeTree
|
||||||
|
|
||||||
# Select the first triangle as desired
|
# Select the first triangle as desired
|
||||||
startingNode = list(spanningTree.nodes())[0]
|
startingNode = list(spanningTree.nodes())[0]
|
||||||
startingTriangle = mesh.face_handle(startingNode)
|
startingTriangle = mesh.face_handle(startingNode)
|
||||||
@ -218,6 +223,7 @@ class Paperfold(inkex.EffectExtension):
|
|||||||
|
|
||||||
# We walk through the tree
|
# We walk through the tree
|
||||||
for dualEdge in nx.dfs_edges(spanningTree, source=startingNode):
|
for dualEdge in nx.dfs_edges(spanningTree, source=startingNode):
|
||||||
|
try:
|
||||||
foldingEdge = mesh.edge_handle(spanningTree[dualEdge[0]][dualEdge[1]]['idx'])
|
foldingEdge = mesh.edge_handle(spanningTree[dualEdge[0]][dualEdge[1]]['idx'])
|
||||||
# Find the corresponding half edge in the output triangle
|
# Find the corresponding half edge in the output triangle
|
||||||
foldingHalfEdge = mesh.halfedge_handle(foldingEdge, 0)
|
foldingHalfEdge = mesh.halfedge_handle(foldingEdge, 0)
|
||||||
@ -276,7 +282,9 @@ class Paperfold(inkex.EffectExtension):
|
|||||||
# Identify the half edges
|
# Identify the half edges
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
halfEdgeConnections[originalHalfEdges[i].idx()] = unfoldedHalfEdges[i].idx()
|
halfEdgeConnections[originalHalfEdges[i].idx()] = unfoldedHalfEdges[i].idx()
|
||||||
|
except Exception as e:
|
||||||
|
inkex.utils.debug("Error walking the dual tree at dualEdge {}".format(e))
|
||||||
|
exit(1)
|
||||||
return [unfoldedMesh, isFoldingEdge, connections, glueNumber, dihedralAngles]
|
return [unfoldedMesh, isFoldingEdge, connections, glueNumber, dihedralAngles]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
inkex.utils.debug("Error: model could not be unfolded. Check for:")
|
inkex.utils.debug("Error: model could not be unfolded. Check for:")
|
||||||
@ -286,7 +294,6 @@ class Paperfold(inkex.EffectExtension):
|
|||||||
inkex.utils.debug(" - missing units")
|
inkex.utils.debug(" - missing units")
|
||||||
inkex.utils.debug(" - missing coordinate system")
|
inkex.utils.debug(" - missing coordinate system")
|
||||||
inkex.utils.debug(" - multiple bodies in one file")
|
inkex.utils.debug(" - multiple bodies in one file")
|
||||||
inkex.utils.debug("error was: " + str(e))
|
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user