9 Contains positions of faces and associated vertices
12 """Construct a Dodecahedron
14 @param[in] withFacesOnPoles: if True center a face on each pole, else put a vertex on each pole
22 g = (1.0 + math.sqrt(5.0)) / 2.0
39 self.
vertexVecList = [numpy.dot(rotMat, unrotVertexVec)
for unrotVertexVec
in unrotVertexVecList]
40 unsortedFaceList = [numpy.dot(rotMat, unrotFaceVec)
for unrotFaceVec
in unrotFaceVecList]
44 """Return a list of face centers
46 @return a list of face centers (in index order); each a unit vector (numpy array)
51 """Return the center of the specified face
53 @param[in] ind: face index
54 @return face center as a unit vector (numpy array)
59 """Return the vertices for a given face
61 @param[in] ind: face index
62 @return a list of vertices, each a unit vector (numpy array)
68 sortedVertexList = [vertexList[0]]
69 vertexList = list(vertexList[1:])
70 while len(vertexList) != 0:
71 nearVertexList, nearInd =
_findCloseList(vertexList, sortedVertexList[-1])
72 sortedVertexList.append(nearVertexList[0])
73 vertexList.pop(nearInd[0])
74 return sortedVertexList
77 """Return the index of the face containing the cartesian vector
79 @param[in] vec: cartesian vector (length is ignored)
80 @return index of face containing vec
82 return numpy.argmax(numpy.dot(self.
faceVecList, vec))
85 """Get withFacesOnPoles parameter
90 """Return a 3D rotation matrix for rotation by a specified amount around a specified axis
93 - angle: amount of rotation (rad)
94 - axis: axis of rotation; one of 0, 1 or 2 for x, y or z
96 cosAng = math.cos(angle)
97 sinAng = math.sin(angle)
98 rotMat = numpy.zeros((3,3), dtype=float)
99 rotMat[axis, axis] = 1
100 rotMat[(axis + 1) % 3, (axis + 1) % 3] = cosAng
101 rotMat[(axis + 2) % 3, (axis + 1) % 3] = sinAng
102 rotMat[(axis + 1) % 3, (axis + 2) % 3] = -sinAng
103 rotMat[(axis + 2) % 3, (axis + 2) % 3] = cosAng
107 """Compute a rotation matrix that puts vec0 along z and vec1 along +x in the xz plane
112 - vec1NegativeX: if True then vec1 is rotated to face negative x
115 xAng = math.atan2(vec0[1], vec0[2])
119 vec0RotX = numpy.dot(xRotMat, vec0)
120 yAng = -math.atan2(vec0RotX[0], vec0RotX[2])
122 xyRotMat = numpy.dot(yRotMat, xRotMat)
125 vec1RotXY = numpy.dot(xyRotMat, vec1)
129 zAng = -math.atan2(vec1RotXY[1], xVal)
131 xyzRotMat = numpy.dot(zRotMat, xyRotMat)
135 """Given a vector of face positions of a Dodecahedron compute the vertices
139 for i
in range(len(faceVecList)):
141 if len(closeIndSet) != 5:
142 raise RuntimeError(
"Found %s vertices instead of 5 near %s: %s" % \
143 (len(closeIndSet), faceVecList[i], closeIndSet))
144 closeIndSetList.append(closeIndSet)
145 for i, iCloseIndSet
in enumerate(closeIndSetList):
146 for j
in iCloseIndSet:
147 jCloseIndSet = closeIndSetList[j]
148 sharedCloseIndSet = iCloseIndSet.intersection(jCloseIndSet)
149 if len(sharedCloseIndSet) != 2:
150 raise RuntimeError(
"Found %s vertices instead of 2 near %s and %s: %s" % \
151 (len(sharedCloseIndSet), faceVecList[i], faceVecList[j], sharedCloseIndSet))
152 for k
in sharedCloseIndSet:
153 key = frozenset((i, j, k))
154 if key
in vertexDict:
156 vertexVec = faceVecList[i] + faceVecList[j] + faceVecList[k]
157 vertexVec /= numpy.sqrt(numpy.sum(vertexVec**2))
158 vertexDict[key] = vertexVec
159 return vertexDict.values()
162 """Given a collection of basis vectors, compute all permutations with both signs of all nonzero values
164 For example: [(0, 1, 2)] -> [(0, 1, 2), (0, -1, 2), (0, 1, -2), (0, -1, -2)]
167 for basisVec
in basisSet:
168 vecLen = math.sqrt(numpy.sum(numpy.array(basisVec)**2))
170 for basisValue
in basisVec:
172 valueList.append((0,))
174 valueList.append((basisValue, -basisValue))
175 fullSet += list(numpy.array((x, y, z))/vecLen
176 for z
in valueList[2]
177 for y
in valueList[1]
178 for x
in valueList[0]
183 """Given a list of cartesian vectors, return a set of indices of those closest to one of them
185 This is intended for regular grids where distances are quantized
188 - vecList: list of cartesian vectors
189 - ind: index of vector to be nearest
191 dotProductList = numpy.round(numpy.dot(vecList, vecList[ind]), 2)
192 dotProductList[ind] = -9e99
193 minDist = numpy.max(dotProductList)
194 indList = numpy.arange(len(dotProductList))[dotProductList==minDist]
198 """Given a list of cartesian vectors, return all those closest to a specified position
200 This is intended for regular grids where distances are quantized
203 - vecList: list of cartesian vectors
204 - vec: vector to be near
207 - list of closest vectors
208 - list if indices of those vectors
210 dotProductList = numpy.round(numpy.dot(vecList, vec), 2)
211 minDist = numpy.max(dotProductList)
212 indList = numpy.arange(len(dotProductList))[dotProductList==minDist]
213 retList = numpy.take(vecList, indList, 0)
214 return retList, indList
217 """Given a list of cartesian vectors and an index, return the vector and one of its closest neighbors
220 - vecList: list of cartesian vectors
221 - ind: index of first vector
224 otherVecList = vecList[0:ind] + vecList[ind+1:]
225 ind1 = numpy.argmax(numpy.dot(otherVecList, vec))
226 return vec, otherVecList[ind1]
229 """Return a list of cartesian vectors sorted by decreasing latitude and increasing longitude
232 ang = round(math.atan2(vec[1], vec[0]), 2)
235 return (-round(vec[2], 1), ang, vec)
237 decoratedList = [vecToSort(v)
for v
in vecList]
239 return [d[2]
for d
in decoratedList]
241 if __name__ ==
"__main__":
242 numpy.set_printoptions(precision=2, suppress=
True, linewidth=120)
246 print "Dodecahedron with vertices on poles"
249 faceVec = vertexDodec.getFaceCtr(i)
250 print "Face %2d: %s" % (i, faceVec)
def computeRotationMatrix
def _computeDodecahedronVertices
def _computeCoordTransform