def positioncurvature(srf, u, v): eps = 1e-012 c = irit.circle((0, 0, 0), 1) k = irit.scrvtreval(srf, u, v, 1) r1 = irit.max( irit.min(1.0 / (irit.FetchRealObject(irit.nth(k, 1)) + eps), 1000), (-1000)) r2 = irit.max( irit.min(1.0 / (irit.FetchRealObject(irit.nth(k, 3)) + eps), 1000), (-1000)) v1 = irit.nth(k, 2) v2 = irit.nth(k, 4) p = irit.seval(srf, u, v) n = irit.snormal(srf, u, v) d1 = v1 ^ n d2 = v2 ^ n c1 = c * \ irit.sc( r1 ) * \ irit.rotz2v( irit.Fetch3TupleObject(d1) ) * \ irit.trans( irit.Fetch3TupleObject(irit.coerce( p, irit.VECTOR_TYPE ) + n * r1 )) c2 = c * \ irit.sc( r2 ) * \ irit.rotz2v( irit.Fetch3TupleObject(d2) ) * \ irit.trans( irit.Fetch3TupleObject(irit.coerce( p, irit.VECTOR_TYPE ) + n * r2) ) retval = irit.list( p, c1, c2, p + irit.coerce(irit.coerce(p, irit.POINT_TYPE) + v1, irit.E3), p + irit.coerce(irit.coerce(p, irit.POINT_TYPE) + v2, irit.E3), positionasymptotes(srf, u, v)) irit.adwidth(retval, 2) irit.color(retval, irit.YELLOW) return retval
def virttree3(pos, dir, size, blevel, level): retval = irit.nil() newpos = (pos + dir) if (level > 0): tr = treebranch(pos, newpos, size) if (level >= blevel): irit.color(tr, bcolor) irit.attrib(tr, "ptexture", irit.GenStrObject("trunk.rle")) irit.attrib(tr, "rgb", irit.GenStrObject(brgb)) else: irit.color(tr, lcolor) irit.attrib(tr, "rgb", irit.GenStrObject(lrgb)) irit.attrib(tr, "ptexture", irit.GenStrObject("leaves.rle")) irit.snoc(tr, retval) if (level > 1): tr1 = virttree3(newpos, rotatevector2(dir, rfactor) * lfactor, size * wfactor, blevel, level - 1) tr2 = virttree3( newpos, rotatevector2(dir, rfactor * irit.random((-1), 1)) * lfactor, size * wfactor, blevel, level - 1) tr3 = virttree3(newpos, rotatevector2(dir, (-rfactor)) * lfactor, size * wfactor, blevel, level - 1) retval = retval + tr1 + tr2 + tr3 return retval
def plotfunc3d(minx, maxx, miny, maxy, n, m): pl = plotfunc3d2poly(minx, maxx, miny, maxy, n, m) irit.color(pl, irit.YELLOW) irit.attrib(pl, "width", irit.GenRealObject(0.05)) minz = 1e+006 maxz = (-1e+006) i = 0 while (i <= irit.SizeOf(pl) - 1): p = irit.coord(pl, i) j = 0 while (j <= irit.SizeOf(p) - 1): v = irit.coord(p, i) if (irit.FetchRealObject(irit.coord(v, 2)) > maxz): maxz = irit.FetchRealObject(irit.coord(v, 2)) if (irit.FetchRealObject(irit.coord(v, 2)) < minz): minz = irit.FetchRealObject(irit.coord(v, 2)) j = j + 1 i = i + 1 ax = (irit.poly( irit.list((irit.min(minx, 0), 0, 0), (irit.max(maxx, 0), 0, 0)), 1) + irit.poly( irit.list((0, irit.min(miny, 0), 0), (0, irit.max(maxy, 0), 0)), 1) + irit.poly( irit.list((0, 0, irit.min(minz, 0)), (0, 0, irit.max(maxz, 0))), 1)) irit.color(ax, irit.RED) irit.attrib(ax, "width", irit.GenRealObject(0.02)) retval = irit.list(pl, ax) irit.viewobj(retval) irit.printf( "xdomain = [%lf %lf], ydomain = [%lf %lf], zdomain = [%lf %lf]\n", irit.list(minx, maxx, miny, maxy, minz, maxz)) return retval
def evalantipodalptsonsrf( srf ): aps = irit.antipodal( srf, 0.001, (-1e-012 ) ) irit.printf( "%d antipodal points detected\n", irit.list( irit.SizeOf( aps ) ) ) retval = irit.nil( ) diam = 0 i = 1 while ( i <= irit.SizeOf( aps ) ): ap = irit.nth( aps, i ) u1 = irit.coord( ap, 1 ) v1 = irit.coord( ap, 2 ) u2 = irit.coord( ap, 3 ) v2 = irit.coord( ap, 4 ) pt1 = irit.seval( srf, irit.FetchRealObject(u1), irit.FetchRealObject(v1) ) pt2 = irit.seval( srf, irit.FetchRealObject(u2), irit.FetchRealObject(v2) ) if ( irit.dstptpt( irit.coerce( pt1, irit.POINT_TYPE ), irit.coerce( pt2, irit.POINT_TYPE ) ) > diam ): diam = irit.dstptpt( irit.coerce( pt1, irit.POINT_TYPE ), irit.coerce( pt2, irit.POINT_TYPE ) ) diamline = pt1 + pt2 irit.snoc( irit.list( pt1 + pt2, pt1 * irit.tx( 0 ), pt2 * irit.tx( 0 ) ), retval ) i = i + 1 irit.color( retval, irit.YELLOW ) irit.color( diamline, irit.CYAN ) irit.adwidth( diamline, 3 ) irit.snoc( irit.list( diamline ), retval ) return retval
def srflineinter( srf, pt1, pt2, dir, param, numsegs,\ tol ): pta = irit.srinter(srf, irit.Fetch3TupleObject(pt1), dir, tol) ptb = irit.srinter( srf, irit.Fetch3TupleObject( ppblend(irit.Fetch3TupleObject(pt1), irit.Fetch3TupleObject(pt2), 2 / 3.0)), dir, tol) ptc = irit.srinter( srf, irit.Fetch3TupleObject( ppblend(irit.Fetch3TupleObject(pt1), irit.Fetch3TupleObject(pt2), 1 / 3.0)), dir, tol) ptd = irit.srinter(srf, irit.Fetch3TupleObject(pt2), dir, tol) crv = irit.bsp2bzr( irit.cinterp(irit.list(pta, ptb, ptc, ptd), 4, 4, irit.GenRealObject(param), 0)) crvs = irit.nil() i = 1 while (i <= numsegs): c = irit.cregion(crv, (i - 1) / float(numsegs), i / float(numsegs)) irit.color(c, i) irit.snoc(c, crvs) i = i + 1 retval = crvs return retval
def colorcirc(crc, cw): if (cw): irit.color(crc, irit.GREEN) else: irit.color(crc, irit.RED) retval = crc return retval
def snakepiece(clr, xrot, ypos, zpos): retval = (irit.box((0, 0, (-0.1)), 1, 1.1, 1.1) - irit.box( (0, (-1), (-2)), 2, 3, 2) * irit.rx(45) * irit.tx((-0.5))) retval = retval * irit.sc(1.0 / math.sqrt(2)) * irit.rx( (-225)) * irit.trans(((-1) / (2.0 * math.sqrt(2)), 1, 0.5)) retval = retval * irit.rx(xrot) * irit.ty(ypos) * irit.tz(zpos) irit.color(retval, clr) return retval
def drawtritangencies(srfs, orient, subtol, numtol, savename): tritans = irit.srf3tans(srfs, orient, subtol, numtol) tritansedges = evaltritangency(srfs, tritans) irit.color(tritansedges, irit.YELLOW) irit.color(srfs, irit.CYAN) if (irit.SizeOf(irit.GenStrObject(savename)) > 0): irit.save(savename, irit.list(srfs, tritansedges)) irit.interact(irit.list(srfs, tritansedges))
def drawbitangencies( srfs, orient, subtol, numtol, mergetol, merged,\ savename ): bitans = irit.srf2tans(srfs, orient, subtol, numtol, mergetol) bitansedges = evalbitangency(srfs, bitans, merged) irit.color(bitansedges, irit.YELLOW) irit.color(srfs, irit.CYAN) if (irit.SizeOf(irit.GenStrObject(savename)) > 0): irit.save(savename, irit.list(srfs, bitansedges)) irit.interact(irit.list(srfs, bitansedges))
def linetancirccirc(x0, y0, r0, x1, y1, r1): circs = irit.list(irit.circle((x0, y0, 0), r0), irit.circle((x1, y1, 0), r1)) irit.color(circs, irit.RED) retval = (circs + linetancirccircaux(x0, y0, r0, x1, y1, r1) + linetancirccircaux(x0, y0, r0, x1, y1, (-r1)) + linetancirccircaux(x0, y0, (-r0), x1, y1, (-r1)) + linetancirccircaux(x0, y0, (-r0), x1, y1, r1)) return retval
def randomcrvs(numcrvs, crvdeg, crvlen, size): l = irit.nil() i = 1 while (i <= numcrvs): irit.snoc(genrandomcrv(crvdeg, crvlen, size), l) i = i + 1 retval = l irit.color(retval, irit.RED) irit.adwidth(retval, 3) return retval
def genanimationorthomatchcrvpts(ppl, crv, scl): pt1 = irit.point(0, 0, 0) pt2 = irit.point(0, 0, 0) vec1 = ( irit.ctlpt( irit.E2, 0, 0 ) + \ irit.ctlpt( irit.E2, 0, scl ) ) irit.color(vec1, irit.YELLOW) vec2 = ( \ irit.ctlpt( irit.E2, 0, 0 ) + \ irit.ctlpt( irit.E2, 0, scl ) ) irit.color(vec2, irit.CYAN) pos1 = irit.nil() pos2 = irit.nil() rot1 = irit.nil() rot2 = irit.nil() i = 0 while (i <= irit.SizeOf(ppl) - 1): pl = irit.coord(ppl, i) j = 0 while (j <= irit.SizeOf(pl) - 1): pt = irit.coord(pl, j) t1 = irit.coord(pt, 0) t2 = irit.coord(pt, 1) if (t1 > t2): irit.snoc( irit.coerce(irit.ceval(crv, irit.FetchRealObject(t1)), irit.POINT_TYPE), pos1) irit.snoc( irit.coerce(irit.ceval(crv, irit.FetchRealObject(t2)), irit.POINT_TYPE), pos2) n1 = irit.cnormal(crv, irit.FetchRealObject(t1)) n2 = irit.cnormal(crv, irit.FetchRealObject(t2)) irit.snoc( irit.vector( math.atan2(irit.FetchRealObject(irit.coord(n1, 0)), irit.FetchRealObject(irit.coord(n1, 1))) * 180 / math.pi, 0, 0), rot1) irit.snoc( irit.vector( math.atan2(irit.FetchRealObject(irit.coord(n2, 0)), irit.FetchRealObject(irit.coord(n2, 1))) * 180 / math.pi, 0, 0), rot2) j = j + 1 if (t1 > t2): irit.snoc(irit.vector(10000, 0, 0), pos1) irit.snoc(irit.vector(10000, 0, 0), pos2) irit.snoc(irit.vector(0, 0, 0), rot1) irit.snoc(irit.vector(0, 0, 0), rot2) i = i + 1 irit.attrib(pt1, "animation", makerottransanimobj(irit.nil(), pos1)) irit.attrib(pt2, "animation", makerottransanimobj(irit.nil(), pos2)) irit.attrib(vec1, "animation", makerottransanimobj(rot1, pos1)) irit.attrib(vec2, "animation", makerottransanimobj(rot2, pos2)) retval = irit.list(pt1, pt2, vec1, vec2) return retval
def cntrpolys( pls, zmin, dz, zmax ): retval = irit.nil( ) intrcrv = irit.iritstate( "intercrv", irit.GenIntObject(1 )) z = zmin while ( z <= zmax ): p = irit.circpoly( ( 0, 0, 1 ), ( 0, 0, z ), 6 ) irit.snoc( pls * p, retval ) z = z + dz intrcrv = irit.iritstate( "intercrv", intrcrv ) irit.color( retval, irit.YELLOW ) return retval
def evaluvtoe3(srf, uvs, clr): retval = irit.nil() i = 1 while (i <= irit.SizeOf(uvs)): uv = irit.nth(uvs, i) irit.snoc( irit.seval(srf, irit.FetchRealObject(irit.coord(uv, 1)), irit.FetchRealObject(irit.coord(uv, 2))), retval) i = i + 1 irit.color(retval, clr) return retval
def randompts2(n): retval = irit.nil() i = 1 while (i <= n): r = irit.random((-1), 1) t = irit.random(0, 2 * math.pi) irit.snoc((math.cos(t) * r, math.sin(t) * r, 0), retval) i = i + 1 irit.color(retval, irit.RED) irit.adwidth(retval, 5) return retval
def display2(c1, c2, bisrf, iso, pt): irit.color(c1, irit.WHITE) irit.adwidth(c1, 3) irit.color(c2, irit.YELLOW) irit.adwidth(c2, 3) irit.color(iso, irit.RED) irit.adwidth(iso, 3) irit.color(pt, irit.CYAN) irit.adwidth(pt, 6) irit.color(bisrf, irit.MAGENTA) irit.view(irit.list(c1, c2, bisrf, iso, pt), irit.ON)
def randomvecs(n): l = irit.nil() i = 1 while (i <= n): r = irit.random((-1), 1) t = irit.random(0, 2 * math.pi) irit.snoc(irit.vector(math.cos(t) * r, 2, math.sin(t) * r), l) i = i + 1 retval = l irit.color(retval, irit.RED) irit.adwidth(retval, 3) return retval
def randompts3d(n): l = irit.nil() i = 1 while (i <= n): irit.snoc( irit.point(irit.random((-1), 1), irit.random((-1), 1), irit.random((-1), 1)), l) i = i + 1 retval = l irit.color(retval, irit.GREEN) irit.adwidth(retval, 5) return retval
def randompts(n): l = irit.nil() i = 1 while (i <= n): r = irit.random((-1), 1) t = irit.random(0, 2 * math.pi) irit.snoc(irit.vector(math.cos(t) * r, math.sin(t) * r, 0), l) i = i + 1 retval = irit.poly(l, irit.FALSE) irit.color(retval, irit.RED) irit.adwidth(retval, 5) return retval
def positionasymptotes(srf, u, v): retval = irit.nil() p = irit.seval(srf, u, v) k = irit.sasympeval(srf, u, v, 1) i = 1 while (i <= irit.SizeOf(k)): irit.snoc( p + irit.coerce( irit.coerce(p, irit.POINT_TYPE) + irit.nth(k, i), irit.E3), retval) i = i + 1 irit.adwidth(retval, 2) irit.color(retval, irit.GREEN) return retval
def makealpha( a, clr ): aa = ( 2 * a - 1 )/float(a * a) alp = irit.quadric( irit.list( aa, 1, 1, 0, 0, 0,\ (-2 ), 0, 0, 1 ) ) if ( a < 0.5 ): alp1 = irit.sregion( irit.sregion( alp, irit.ROW, 0, 1 ), irit.COL, 0,\ 0.7 ) alp1 = irit.smoebius( irit.smoebius( alp1, 0, irit.COL ), 0, irit.ROW ) else: alp1 = alp * irit.tx( 0 ) retval = irit.list( alp1, alp1 * irit.rx( 90 ), alp1 * irit.rx( 180 ), alp1 * irit.rx( 270 ) ) irit.color( retval, clr ) irit.adwidth( retval, 3 ) return retval
def displayobjobjmdres(o1, o2, eps): global glbltransx mdres = irit.mindist2ff(o1, o2, eps) dist = irit.nth(mdres, 1) param1 = irit.nth(mdres, 2) param2 = irit.nth(mdres, 3) if (irit.SizeOf(param1) == 0): pt1 = irit.coerce(o1, irit.E3) else: prm = irit.nth(param1, 1) if (irit.ThisObject(prm) == irit.NUMERIC_TYPE): i = 1 while (i <= irit.SizeOf(param1)): t = irit.nth(param1, i) irit.printf("min distance %f detected at t1 = %f\n", irit.list(dist, t)) i = i + 1 pt1 = irit.ceval(o1, irit.FetchRealObject(t)) else: i = 1 while (i <= irit.SizeOf(param1)): uv = irit.nth(param1, i) irit.printf("min distance %f detected at uv1 = %f %f\n", irit.list(dist, irit.nth(uv, 1), irit.nth(uv, 2))) i = i + 1 pt1 = irit.seval( o1, irit.FetchRealObject(irit.nth(irit.nth(param1, 1), 1)), irit.FetchRealObject(irit.nth(irit.nth(param1, 1), 2))) if (irit.SizeOf(param2) == 0): pt2 = irit.coerce(o2, irit.E3) else: prm = irit.nth(param2, 1) if (irit.ThisObject(prm) == irit.NUMERIC_TYPE): i = 1 while (i <= irit.SizeOf(param2)): t = irit.nth(param2, i) irit.printf("min distance %f detected at t2 = %f\n", irit.list(dist, t)) i = i + 1 pt2 = irit.ceval(o2, irit.FetchRealObject(t)) else: i = 1 while (i <= irit.SizeOf(param2)): uv = irit.nth(param2, i) irit.printf("min distance %f detected at uv2 = %f %f\n", irit.list(dist, irit.nth(uv, 1), irit.nth(uv, 2))) i = i + 1 pt2 = irit.seval( o2, irit.FetchRealObject(irit.nth(irit.nth(param2, 1), 1)), irit.FetchRealObject(irit.nth(irit.nth(param2, 1), 2))) irit.color(pt1, irit.MAGENTA) irit.color(o1, irit.MAGENTA) irit.color(pt2, irit.YELLOW) irit.color(o2, irit.YELLOW) l = (pt1 + pt2) all = irit.list(o1, o2, pt1, pt2, l) irit.snoc(all * irit.tx(glbltransx), glblres) glbltransx = (glbltransx + 0.5) irit.interact(all)
def makealpha( a, clr ): aa = ( 2 * a - 1 )/float(a * a) bb = (-irit.sqr( ( 1 - a )/float(a) ) ) alp = irit.quadric( irit.list( aa, bb, 1, 0, 0, 0,\ (-2 ), 0, 0, 1 ) ) alp1 = irit.sregion( irit.sregion( alp, irit.ROW, (-5 ), 0.45 ), irit.COL, 0,\ 200 ) alp1 = irit.smoebius( irit.smoebius( alp1, 0, irit.COL ), 0, irit.ROW ) alp2 = irit.sregion( irit.sregion( alp, irit.ROW, (-5 ), 0.45 ), irit.COL, (-200 ),\ 0 ) alp2 = irit.smoebius( irit.smoebius( alp2, 0, irit.COL ), 0, irit.ROW ) retval = irit.list( alp1, alp2 ) irit.color( retval, clr ) irit.adwidth( retval, 3 ) return retval
def computesphericalcrv(theta1, theta2, phi1, phi2): ptlist = irit.nil() t = 0 while (t <= 100): theta = (theta2 * t + theta1 * (100 - t)) * math.pi / (180 * 100) phi = (phi2 * t + phi1 * (100 - t)) * math.pi / (180 * 100) irit.snoc( irit.point( math.cos(theta) * math.cos(phi), math.cos(theta) * math.sin(phi), math.sin(theta)), ptlist) t = t + 1 retval = irit.cbspline(2, ptlist, irit.list(irit.KV_OPEN)) irit.attrib(retval, "dwidth", irit.GenRealObject(3)) irit.color(retval, irit.RED) return retval
def randomctlpt3(n): l = irit.nil() i = 1 while (i <= n): r = irit.random((-0.5), 0.5) t = irit.random(0, 2 * math.pi) irit.snoc( irit.ctlpt(irit.E3, math.cos(t) * r, irit.random(0.5, 1.5), math.sin(t) * r), l) i = i + 1 retval = l irit.color(retval, irit.GREEN) irit.adwidth(retval, 3) return retval
def crveqlparamsegmarkers(c): crvswsegs = irit.nil() crvsbsegs = irit.nil() numsegs = 10 i = 1 while (i <= numsegs): irit.snoc(irit.cregion(c, (i - 1) / numsegs, (i - 0.5) / numsegs), crvswsegs) irit.snoc(irit.cregion(c, (i - 0.5) / numsegs, (i - 0) / numsegs), crvsbsegs) i = i + 1 irit.color(crvswsegs, irit.RED) irit.color(crvsbsegs, irit.YELLOW) retval = irit.list(crvswsegs, crvsbsegs) return retval
def evaloneflecnodalpts(srf, pts): if (irit.ThisObject(pts) == irit.CTLPT_TYPE): retval = irit.seval(srf, irit.FetchRealObject(irit.coord(pts, 1)), irit.FetchRealObject(irit.coord(pts, 2))) irit.color(retval, irit.BLUE) else: retval = irit.nil() i = 1 while (i <= irit.SizeOf(pts)): pt = irit.nth(pts, i) irit.snoc( irit.seval(srf, irit.FetchRealObject(irit.coord(pt, 1)), irit.FetchRealObject(irit.coord(pt, 2))), retval) i = i + 1 return retval
def computeorthovector(theta1, theta2, phi1, phi2): theta1d = theta1 * math.pi / 180 theta2d = theta2 * math.pi / 180 phi1d = phi1 * math.pi / 180 phi2d = phi2 * math.pi / 180 pt1 = irit.point( math.cos(theta1d) * math.cos(phi1d), math.cos(theta1d) * math.sin(phi1d), math.sin(theta1d)) pt2 = irit.point( math.cos(theta2d) * math.cos(phi2d), math.cos(theta2d) * math.sin(phi2d), math.sin(theta2d)) retval = irit.coerce(irit.normalizePt(pt1 ^ pt2), irit.VECTOR_TYPE) irit.attrib(retval, "dwidth", irit.GenRealObject(3)) irit.color(retval, irit.GREEN) return retval
def evaltoeuclidean(srf, paramumb): retval = irit.nil() i = 1 while (i <= irit.SizeOf(paramumb)): umb = irit.nth(paramumb, i) crvtr = irit.scrvtreval(srf, irit.FetchRealObject(irit.coord(umb, 0)), irit.FetchRealObject(irit.coord(umb, 1)), 1) irit.printf( "principal curvatures at (u, v) = (%f, %f) equal %.9f and %.9f\n", irit.list(irit.coord(umb, 0), irit.coord(umb, 1), irit.nth(crvtr, 1), irit.nth(crvtr, 3))) irit.snoc( irit.seval(srf, irit.FetchRealObject(irit.coord(umb, 0)), irit.FetchRealObject(irit.coord(umb, 1))), retval) i = i + 1 irit.color(retval, irit.YELLOW) return retval
def randomcrvs(numcrvs, crvdeg, crvlen, size, dwidth): l = irit.nil() i = 1 while (i <= numcrvs): irit.snoc(genrandomcrv(crvdeg, crvlen, size), l) irit.attrib(irit.nref(l, i), "gray", irit.GenRealObject(irit.random(0.01, 0.7))) i = i + 1 i = 1 while (i <= numcrvs): irit.attrib(irit.nref(l, i), "rgb", irit.GenStrObject(getrandrgb())) i = i + 1 retval = l irit.color(retval, irit.RED) irit.awidth(retval, 0.01) irit.adwidth(retval, dwidth) return retval