![]() |
Python_2
1.0
|
Draws a 3D polyhedron and allows a user to rotate it (mouse left button and wheel). More...
Functions | |
def | matMul (m1, m2) |
Return m1 x m2 (m1 multiplied by m2). More... | |
def | vecSub (v1, v2) |
Return vector v2 - v1. More... | |
def | vecAdd (v1, v2) |
Return vector v2 + v1. More... | |
def | vecScale (v, s) |
Return vector v * s. More... | |
def | veclen (p, q) |
Length of vector from point p = (x1,y1,...,x1n) to q = (x,y,...,xn). More... | |
def | normalize (p) |
Normalize a vector. More... | |
def | transpose (M) |
Transpose a matrix. More... | |
def | bbox (p) |
Bounding Box of a polyhedron. More... | |
def | translate (poly, t) |
Translate a polyhedron. More... | |
def | centroid (vtx) |
Centroid of a convex face. More... | |
def | crossProd (U, V) |
Return cross product U x V. More... | |
def | dotProd (u, v) |
Return the dot product of two vectors. More... | |
def | getNormal2 (p) |
Face normal vector. More... | |
def | ROT_X (x) |
counter-clockwise rotation about the X axis More... | |
def | ROT_Y (y) |
counter-clockwise rotation about the Y axis More... | |
def | ROT_Z (z) |
counter-clockwise rotation about the Z axis More... | |
def | EPS (d) |
angular displacement as a function of a number of pixels. More... | |
def | eps (d) |
angular displacement as a function of the sign of a number of pixels. More... | |
def | getNormal (poly) |
Polygon normal by Newell's method. More... | |
def | drawAxes () |
Draw coordinate axes. More... | |
def | makeBox (box) |
Make a bounding box. More... | |
def | drawBbox () |
Draw the current polygon bounding box. More... | |
def | DrawObj (obj, col) |
Draw a polyhedron. More... | |
def | getNormalLine (p, C, col) |
Return a line corresponding to a face normal. More... | |
def | drawFace (p, pc, cent, col1, col) |
Draw a face of the polyhedron, if it is visible. More... | |
def | init () |
def | cbClicked (event) |
def | cbMotion (event) |
def | wheelUp (event) |
def | wheelDown (event) |
def | wheel (event) |
def | resize (event) |
def | toggleFill (event) |
def | toggleNormal (event) |
def | toggleObj (event) |
def | toggleDebug (event) |
def | help (event) |
def | exit (event) |
def | main () |
Draws a 3D polyhedron and allows a user to rotate it (mouse left button and wheel).
The polyhedron is represented by a 3 x number_of_vertices matrix. Each column represents a 3D vertex.
note: a m x n matrix is represented by a list of lines: [[l_1] [l_2] .. [l_m]]. m = len(mat), n = len(mat[0]), mat(i,j) = mat[i][j]
def _12a_poly.bbox | ( | p | ) |
Bounding Box of a polyhedron.
Referenced by toggleObj().
def _12a_poly.cbClicked | ( | event | ) |
Save current mouse position.
Referenced by cbMotion().
def _12a_poly.cbMotion | ( | event | ) |
def _12a_poly.centroid | ( | vtx | ) |
Centroid of a convex face.
Referenced by DrawObj(), getNormalLine(), and toggleObj().
def _12a_poly.crossProd | ( | U, | |
V | |||
) |
Return cross product U x V.
def _12a_poly.dotProd | ( | u, | |
v | |||
) |
Return the dot product of two vectors.
Referenced by getNormalLine().
def _12a_poly.drawAxes | ( | ) |
def _12a_poly.drawBbox | ( | ) |
def _12a_poly.drawFace | ( | p, | |
pc, | |||
cent, | |||
col1, | |||
col | |||
) |
Draw a face of the polyhedron, if it is visible.
p | world coordinate points. |
pc | screen coordinate points. |
cent | centroid of the polyhedron. |
col1 | fill color. |
col | outline color. |
Draw a face of the polyhedron.
References getNormalLine().
Referenced by DrawObj().
def _12a_poly.DrawObj | ( | obj, | |
col | |||
) |
Draw a polyhedron.
Not all faces are visible at the same time. Use back face culling to eliminate invisible faces from camera point of view.
obj | vertex coordinate matrix. |
col | color of the edges. |
Draw a polyhedron.
References centroid(), drawAxes(), drawBbox(), drawFace(), and transpose().
Referenced by cbMotion(), _12a_poly_interface.draw(), main(), resize(), toggleFill(), toggleNormal(), wheel(), wheelDown(), and wheelUp().
def _12a_poly.EPS | ( | d | ) |
angular displacement as a function of a number of pixels.
Referenced by cbMotion(), _12_tet.cbMottion(), _12_tet.init(), _12_tet.wheel(), wheel(), _12_tet.wheelDown(), wheelDown(), _12_tet.wheelUp(), and wheelUp().
def _12a_poly.eps | ( | d | ) |
angular displacement as a function of the sign of a number of pixels.
Referenced by _12_tet.init().
def _12a_poly.exit | ( | event | ) |
Finishes this program.
Referenced by _15_julia.keyboard(), mplayerdvd.playdvd(), and data.readSheet().
def _12a_poly.getNormal | ( | poly | ) |
Polygon normal by Newell's method.
poly | a polygon vertex list. |
References vecAdd(), and vecSub().
Referenced by getNormalLine().
def _12a_poly.getNormal2 | ( | p | ) |
Face normal vector.
References vecSub().
def _12a_poly.getNormalLine | ( | p, | |
C, | |||
col | |||
) |
Return a line corresponding to a face normal.
The circulation of the face in relation to the centroid of the polyhedron is used to figure out the normal direction. Therefore, even if faces are not consistently oriented, the normal will be right.
p | face vertex list. |
C | centroid of the polyhedron. |
col | normal vector color. |
References centroid(), dotProd(), getNormal(), normalize(), vecAdd(), vecScale(), and vecSub().
Referenced by drawFace().
def _12a_poly.help | ( | event | ) |
Usage instructions.
def _12a_poly.init | ( | ) |
def _12a_poly.makeBox | ( | box | ) |
Make a bounding box.
box | lower left and upper right corners of the bounding box. |
Referenced by toggleObj().
def _12a_poly.matMul | ( | m1, | |
m2 | |||
) |
Return m1 x m2 (m1 multiplied by m2).
Referenced by cbMotion(), wheel(), wheelDown(), and wheelUp().
def _12a_poly.normalize | ( | p | ) |
def _12a_poly.resize | ( | event | ) |
Redraw the polyhedron, in case of a window change due to user resizing it.
References DrawObj().
Referenced by toggleObj().
def _12a_poly.ROT_X | ( | x | ) |
counter-clockwise rotation about the X axis
Referenced by cbMotion(), _12_tet.cbMottion(), and _12_tet.init().
def _12a_poly.ROT_Y | ( | y | ) |
counter-clockwise rotation about the Y axis
Referenced by cbMotion(), _12_tet.cbMottion(), and _12_tet.init().
def _12a_poly.ROT_Z | ( | z | ) |
counter-clockwise rotation about the Z axis
Referenced by _12_tet.init(), _12_tet.wheel(), wheel(), _12_tet.wheelDown(), wheelDown(), _12_tet.wheelUp(), and wheelUp().
def _12a_poly.toggleDebug | ( | event | ) |
Toggle debugging mode.
def _12a_poly.toggleFill | ( | event | ) |
Toggle outline mode.
References DrawObj().
def _12a_poly.toggleNormal | ( | event | ) |
Toggle normal mode.
References DrawObj().
def _12a_poly.toggleObj | ( | event | ) |
Toggle displayed object.
References bbox(), centroid(), makeBox(), resize(), translate(), transpose(), and vecScale().
Referenced by init(), and _12a_poly_interface.setSolid().
def _12a_poly.translate | ( | poly, | |
t | |||
) |
Translate a polyhedron.
poly | polyhedron. |
t | translation vector. |
References vecSub().
Referenced by toggleObj().
def _12a_poly.transpose | ( | M | ) |
Transpose a matrix.
Referenced by drawAxes(), drawBbox(), DrawObj(), and toggleObj().
def _12a_poly.vecAdd | ( | v1, | |
v2 | |||
) |
Return vector v2 + v1.
Referenced by getNormal(), and getNormalLine().
def _12a_poly.veclen | ( | p, | |
q | |||
) |
Length of vector from point p = (x1,y1,...,x1n) to q = (x,y,...,xn).
Referenced by normalize().
def _12a_poly.vecScale | ( | v, | |
s | |||
) |
Return vector v * s.
Referenced by getNormalLine(), and toggleObj().
def _12a_poly.vecSub | ( | v1, | |
v2 | |||
) |
Return vector v2 - v1.
Referenced by getNormal(), getNormal2(), getNormalLine(), and translate().
def _12a_poly.wheel | ( | event | ) |
def _12a_poly.wheelDown | ( | event | ) |