From: Matthias Baas <mbaas@us...>  20060216 09:56:06

Update of /cvsroot/cgkit/cgkit2/cgkit In directory sc8prcvs1.sourceforge.net:/tmp/cvsserv29134/cgkit Modified Files: cmds.py Log Message: Added the fitCone() function Index: cmds.py =================================================================== RCS file: /cvsroot/cgkit/cgkit2/cgkit/cmds.py,v retrieving revision 1.10 retrieving revision 1.11 diff C2 d r1.10 r1.11 *** cmds.py 14 Feb 2006 19:25:54 0000 1.10  cmds.py 16 Feb 2006 09:55:54 0000 1.11 *************** *** 466,469 ****  466,548  return newgeom + # fitCone + def fitCone(pos, obj): + """Compute a cone that has its apex at pos and that includes obj. + + The generated cone is the minimal cone that entirely contains the + bounding box of obj (which must be a WorldObject). + pos is the apex of the cone given in world coordinates. + The return value is a tuple (n,w) where n is the axis direction of the + cone and w is the (full) angle in radians. + """ + W = obj.worldtransform + Winv = W.inverse() + p = Winv*pos + + bb = obj.boundingBox() + a,b,c,d,e,f,g,h = _bbCorners(bb) + a = (ap).normalize() + b = (bp).normalize() + c = (cp).normalize() + d = (dp).normalize() + e = (ep).normalize() + f = (fp).normalize() + g = (gp).normalize() + h = (hp).normalize() + n1,w1 = _cone(a,h) + n2,w2 = _cone(b,g) + n3,w3 = _cone(c,f) + n4,w4 = _cone(d,e) + w = max(w1,w2,w3,w4) + if w1==w: + n = n1 + elif w2==w: + n = n2 + elif w3==w: + n = n3 + else: + n = n4 + + n = W.getMat3()*n + return n,w + + # _cone + def _cone(a,b): + """Create a cone from two directions. + + a and b are two normalized directions that point along the generated + cone on two opposite directions, i.e. the returned cone is the minmal + cone that has the 'rays' a and b on its surface. + The return value is a tuple (n,w) where n is the cone axis and w + the (full) angle in radians. + + This is a helper function for the fitCone() function. + """ + n = (a+b).normalize() + w = a.angle(b) + return n,w + + + # _bbCorners + def _bbCorners(bb): + """Return the eight corners of a bounding box. + + bb is a BoundingBox object. The index of the returned points is + such that bit 0 determines if the point is minmal or maximal in x + direction. Bit 1 is the y direction and bit 2 the z + direction. This means point n is opposite to point (~n)&0x7. + + This is a helper function for the fitCone() function. + """ + a,h = bb.getBounds() + b = vec3(h.x, a.y, a.z) + c = vec3(a.x, h.y, a.z) + d = vec3(h.x, h.y, a.z) + e = vec3(a.x, a.y, h.z) + f = vec3(h.x, a.y, h.z) + g = vec3(a.x, h.y, h.z) + return a,b,c,d,e,f,g,h + + # delete def delete(objs): 