simple plotting to see if it works.
This commit is contained in:
parent
c6434469fb
commit
a93c047a5d
67
geometry.py
67
geometry.py
@ -246,13 +246,11 @@ class Polygon(object):
|
|||||||
it needs to average vertices with all adjoinging faces
|
it needs to average vertices with all adjoinging faces
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, vertices, edges, faces):
|
def __init__(self):
|
||||||
self.vertices = vertices
|
self.vertices = []
|
||||||
self.edges = edges
|
self.edges = []
|
||||||
self.faces = faces
|
self.faces = []
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return str([edge for edge in self.edges])
|
|
||||||
def catmullClarkRefine(self):
|
def catmullClarkRefine(self):
|
||||||
'''
|
'''
|
||||||
For each face, add a face vertex
|
For each face, add a face vertex
|
||||||
@ -264,26 +262,32 @@ class Polygon(object):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
# each face knows how to subdivide and create a set of subfaces, including interior edges and setup their references correctly... <- not completely finished...
|
# each face knows how to subdivide and create a set of subfaces, including interior edges and setup their references correctly... <- not completely finished...
|
||||||
|
p = Polygon()
|
||||||
|
edges = []
|
||||||
|
vertices = []
|
||||||
|
faces = []
|
||||||
for face in self.faces:
|
for face in self.faces:
|
||||||
for subFace in face.subFaces:
|
for subFace in face.subFaces:
|
||||||
|
faces.append(subFace)
|
||||||
for edge in subFace.edges:
|
for edge in subFace.edges:
|
||||||
|
edges.append(edge)
|
||||||
for vertex in edge.vertices:
|
for vertex in edge.vertices:
|
||||||
print vertex
|
vertices.append(vertex)
|
||||||
|
p.faces = faces
|
||||||
|
p.vertices = vertices
|
||||||
|
p.edges = edges
|
||||||
# plotting these in excel seems to show the correct values (at first glace...)
|
# plotting these in excel seems to show the correct values (at first glace...)
|
||||||
|
|
||||||
|
|
||||||
# so now what.........
|
# so now what.........
|
||||||
|
|
||||||
# (F + 2R + (n-3) P) / n
|
# (F + 2R + (n-3) P) / n
|
||||||
#
|
#
|
||||||
# F = average of all face vertices touching P
|
# F = average of all face vertices touching P
|
||||||
# R = average of all edge vertices touching P
|
# R = average of all edge vertices touching P
|
||||||
# P original point
|
# P original point
|
||||||
# n = face vertices or edge vertices (should be the same number)
|
# n = face vertices or edge vertices (should be the same number)
|
||||||
|
return p
|
||||||
|
|
||||||
|
def createPolygon():
|
||||||
v = []
|
v = []
|
||||||
v.append(Vertex(0.0, 1.0, 0.0))
|
v.append(Vertex(0.0, 1.0, 0.0))
|
||||||
v.append(Vertex(1.0, 1.0, 0.0))
|
v.append(Vertex(1.0, 1.0, 0.0))
|
||||||
@ -363,24 +367,27 @@ e[11].vertices, e[11].faces, e[11].edges = [v[4], v[7]], [f[3], f[5]], [e[4], e[
|
|||||||
# print v[0].x
|
# print v[0].x
|
||||||
# print e[0].vertices[0].x
|
# print e[0].vertices[0].x
|
||||||
# print f[0].edges[0].vertices[0].x
|
# print f[0].edges[0].vertices[0].x
|
||||||
|
p = Polygon()
|
||||||
|
p.vertices = v
|
||||||
|
p.edges = e
|
||||||
|
p.faces = f
|
||||||
|
return p
|
||||||
|
|
||||||
polygon = Polygon(v, e, f)
|
polygon = createPolygon()
|
||||||
polygon.catmullClarkRefine()
|
newPolygon = polygon.catmullClarkRefine()
|
||||||
|
|
||||||
|
from numpy import *
|
||||||
|
import pylab
|
||||||
|
import mpl_toolkits.mplot3d.axes3d as p3
|
||||||
|
|
||||||
# from numpy import *
|
fig = pylab.figure()
|
||||||
# import pylab
|
ax = p3.Axes3D(fig)
|
||||||
# import mpl_toolkits.mplot3d.axes3d as p3
|
for edge in newPolygon.edges:
|
||||||
|
xs = [vertex.x for vertex in edge.vertices]
|
||||||
# fig = pylab.figure()
|
ys = [vertex.y for vertex in edge.vertices]
|
||||||
# ax = p3.Axes3D(fig)
|
zs = [vertex.z for vertex in edge.vertices]
|
||||||
# ax.plot_wireframe(xs, ys, zs)
|
ax.plot_wireframe(xs, ys, zs)
|
||||||
# ax.set_xlabel('X')
|
ax.set_xlabel('X')
|
||||||
# ax.set_ylabel('Y')
|
ax.set_ylabel('Y')
|
||||||
# ax.set_zlabel('Z')
|
ax.set_zlabel('Z')
|
||||||
# pylab.show()
|
pylab.show()
|
||||||
|
|
||||||
# v4 = Vertex(4, 0, 0, 1)
|
|
||||||
# v5 = Vertex(5, 1, 0, 1)
|
|
||||||
# v6 = Vertex(6, 0, 1, 1)
|
|
||||||
# v7 = Vertex(7, 1, 1, 1)
|
|
Loading…
Reference in New Issue
Block a user