surfaces/surf/util.py
Stephen M. McQuay 93891b917b Moved documentation, and added more operators to Vertex
- added __neg__
    - added cross for Vertex * Vertex
    - added tests for these
    - moved the cube docstring up into the cube generating function
2012-03-20 07:16:15 -06:00

160 lines
5.1 KiB
Python

from surf.geometry import Vertex, Edge, Face, Polygon
def cube():
"""
This function returns a populated Polygon object. The object is a cube with
a vertex at the origin, and another at (1, 1, 1).
v4 v5
*-----e8-----*
| |
| |
e|4 f4 e|5
| |
v4 v|0 v|1 v5
*-----e4-----*-----e0-----*-----e5-----*
| | | |
| | | |
e11| f3 e|3 f0 e|1 f1 e|9
| | | |
| | | |
*-----e7-----*-----e2-----*-----e6-----*
v7 v|3 v|2 v6
| |
e|7 f2 e|6
| |
v|7 v|6
*-----e10----*
| |
| |
e|11 f5 e|9
| |
| |
*-----e8-----*
v4 v5
v0 - <0,1,0>
v1 - <1,1,0>
v2 - <1,0,0>
v3 - <0,0,0>
v4 - <0,1,1>
v5 - <1,1,1>
v6 - <1,0,1>
v7 - <0,0,1>
face list
f0 - e0, e1, e2, e3
f1 - e1, e5, e9, e6
f2 - e2, e6, e10, e7
f3 - e4, e3, e7, e11
f4 - e8, e5, e0, e4
f5 - e10, e9, e8, e11
winged edges ordered by face, then by vertex reference
edge list
e0 - v0, v1; f0, f4; e3, e1, e4, e5
e1 - v1, v2; f0, f1; e0, e2, e5, e6
e2 - v3, v2; f0, f2; e3, e7, e1, e6
e3 - v0, v3; f3, f0; e4, e7, e0, e2
e4 - v4, v0; f3, f4; e11, e3, e0 e8
e5 - v5, v1; f4, f1; e8, e0, e9, e1
e6 - v2, v6; f1, f2; e1, e9, e2, e10
e7 - v7, v3; f3, f2; e11, e3, e10, e2
e8 - v4, v5, f4, f5; e4, e5, e11, e9
e9 - v5, v6; f1, f5; e5, e6, e8, e10
e10 - v7, v6; f2, f5; e7, e6, e11, e9
e11 - v4, v7; f3, f5; e4, e7, e8, 10
vertex list
v0 - e0, e3, e4
v1 - e0, e5, e1
v2 - e1, e6, e2
v3 - e2, e7, e3
v4 - e4, e11, e8
v5 - e5, e9, e8
v6 - e2, e9, e10
v7 - e7, e10, e11
"""
v = []
v.append(Vertex(0.0, 1.0, 0.0))
v.append(Vertex(1.0, 1.0, 0.0))
v.append(Vertex(1.0, 0.0, 0.0))
v.append(Vertex(0.0, 0.0, 0.0))
v.append(Vertex(0.0, 1.0, 1.0))
v.append(Vertex(1.0, 1.0, 1.0))
v.append(Vertex(1.0, 0.0, 1.0))
v.append(Vertex(0.0, 0.0, 1.0))
e = []
e.append(Edge())
e.append(Edge())
e.append(Edge())
e.append(Edge())
e.append(Edge())
e.append(Edge())
e.append(Edge())
e.append(Edge())
e.append(Edge())
e.append(Edge())
e.append(Edge())
e.append(Edge())
f = []
f.append(Face())
f.append(Face())
f.append(Face())
f.append(Face())
f.append(Face())
f.append(Face())
# vertex list
v[0].edges = [e[0], e[3], e[4]]
v[1].edges = [e[0], e[5], e[1]]
v[2].edges = [e[1], e[6], e[2]]
v[3].edges = [e[2], e[7], e[3]]
v[4].edges = [e[4], e[11], e[8]]
v[5].edges = [e[5], e[9], e[8]]
v[6].edges = [e[6], e[9], e[10]]
v[7].edges = [e[7], e[10], e[11]]
# face list
f[0].edges = [e[0], e[1], e[2], e[3]]
f[1].edges = [e[1], e[5], e[9], e[6]]
f[2].edges = [e[2], e[6], e[10], e[7]]
f[3].edges = [e[4], e[3], e[7], e[11]]
f[4].edges = [e[8], e[5], e[0], e[4]]
f[5].edges = [e[10], e[9], e[8], e[11]]
#winged edges ordered by face, then by vertex reference
e[0].vertices, e[0].faces, e[0].edges = [v[0], v[1]], [f[0], f[4]], [e[3], e[1], e[4], e[5]]
e[1].vertices, e[1].faces, e[1].edges = [v[1], v[2]], [f[0], f[1]], [e[0], e[2], e[5], e[6]]
e[2].vertices, e[2].faces, e[2].edges = [v[2], v[3]], [f[0], f[2]], [e[1], e[3], e[6], e[7]]
e[3].vertices, e[3].faces, e[3].edges = [v[3], v[0]], [f[3], f[0]], [e[4], e[7], e[0], e[2]]
e[4].vertices, e[4].faces, e[4].edges = [v[0], v[4]], [f[3], f[4]], [e[11], e[3], e[0], e[8]]
e[5].vertices, e[5].faces, e[5].edges = [v[5], v[1]], [f[4], f[1]], [e[8], e[0], e[9], e[1]]
e[6].vertices, e[6].faces, e[6].edges = [v[2], v[6]], [f[1], f[2]], [e[1], e[9], e[2], e[10]]
e[7].vertices, e[7].faces, e[7].edges = [v[7], v[3]], [f[3], f[2]], [e[11], e[3], e[10], e[2]]
e[8].vertices, e[8].faces, e[8].edges = [v[4], v[5]], [f[4], f[5]], [e[4], e[5], e[11], e[9]]
e[9].vertices, e[9].faces, e[9].edges = [v[5], v[6]], [f[1], f[5]], [e[5], e[6], e[8], e[10]]
e[10].vertices, e[10].faces, e[10].edges = [v[7], v[6]], [f[2], f[5]], [e[7], e[6], e[11], e[9]]
e[11].vertices, e[11].faces, e[11].edges = [v[4], v[7]], [f[3], f[5]], [e[4], e[7], e[8], e[10]]
# just to prove to myself that the objects are the same, this is what years of pass by value have done to me...
# print id(v[0].x)
# print id(e[0].vertices[0].x)
# print id(f[0].edges[0].vertices[0].x)
# v[0].x = 9
# print id(v[0].x)
# print id(e[0].vertices[0].x)
# print id(f[0].edges[0].vertices[0].x)
# print v[0].x
# print e[0].vertices[0].x
# print f[0].edges[0].vertices[0].x
return Polygon(v, e, f)