Anda di halaman 1dari 3

CCA Maths 308 : Advanced Geometry : Spring 2011

April 12 : Lecture 11 : T iling / Random Walk


Tiling / Random Walk: Overview. The follow ing 3 images are random w alks of triangular tiles. Each picture has 1000 equilateral triangles.

converted by Web2PDFConvert.com

The below code generated each of the 3 pictures above. 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 from Rhino.Geometry import Point3d, Mesh import random import math def makeNewRandomTri(t, z): r = random.random() if (r > 0.5): adjEdge = [t[1], t[2]] remainingPt = t[0] else : adjEdge = [t[2], t[0]] remainingPt = t[1] midPt = (adjEdge[0] + adjEdge[1]) / 2 newPt = midPt + (midPt - remainingPt) newPt[2] = z return [adjEdge[1], adjEdge[0], newPt] rawTris = [[Point3d(0, 0, 0), Point3d(1, 0, 0), Point3d(0.5, math.sqrt(3) / 2, 0)]] for i in range(1000): newTri = makeNewRandomTri(rawTris[i], i / 50) rawTris.append(newTri) finalMesh = Mesh() for i in range(len(rawTris)): finalMesh.Vertices.Add(rawTris[i][0]) finalMesh.Vertices.Add(rawTris[i][1]) finalMesh.Vertices.Add(rawTris[i][2]) finalMesh.Faces.AddFace(3 * i, 3 * i + 1, 3 * i + 2) finalMesh.Normals.ComputeNormals() finalMesh.Compact() Py_Res = [finalMesh]

HW Lec. 11 Prob. 1: In line 2 of the code w e 'import random'. W here do w e use random in this program? Describe the values of the random numbers that are generated. How many random numbers of w e generate in total? Describe w hat these random numbers are used for. HW Lec. 11 Prob. 2: Describe w hat the function makeNew RandomTri does. W hat does it take as input? W hat does it give as output? HW Lec. 11 Prob. 3: Describe geometrically how new Pt in line 14 is being computed. W hat is midPt in line 13? HW Lec. 11 Prob. 4: Describe w hat the purpose of the list raw Tris is. W hat does raw Tris contain by the end of the program? HW Lec. 11 Prob. 5: Describe w hat is happening in lines 26 through 31. HW Lec. 11 Prob. 6: If w e change line 15 from 'new Pt[2] = z' to 'new Pt[2] = remainingPt[2] + random.random()/25', how is the final mesh affected? How is this change different from 'new Pt[2] = random.random()/25'? HW Lec. 11 Prob. 7: If w e use a different the initial triangle for the 0th element in raw Tris (line 19), how does that affect the program. See w hat happens w hen the 0th element of raw Tris is [Point3d(0, 0, 0), Point3d(1, 0, 0), Point3d(1, 1.5, 0)].

converted by Web2PDFConvert.com

Walter Kim : 2011

converted by Web2PDFConvert.com

Anda mungkin juga menyukai