def rotatevector2(v, amount): v1 = irit.normalizeVec(perpvector(v)) v2 = irit.normalizeVec(v1 ^ v) * math.sqrt(irit.FetchRealObject(v * v)) if (amount > 0): retval = v + v1 * irit.random(0, amount) + v2 * irit.random(0, amount) else: retval = v + v1 * irit.random(amount, 0) + v2 * irit.random(amount, 0) return retval
def evaloneflecnodalvecs(srf, pts, size): retval = irit.nil() dusrf = irit.sderive(srf, irit.COL) dvsrf = irit.sderive(srf, irit.ROW) i = 1 while (i <= irit.SizeOf(pts)): pt = irit.nth(pts, i) vec = irit.coerce( irit.seval( dusrf, irit.FetchRealObject(irit.coord( pt, 1 )), irit.FetchRealObject(irit.coord( pt, 2 )) ), irit.VECTOR_TYPE ) * \ irit.coord( pt, 3 ) + \ irit.coerce( irit.seval( dvsrf, irit.FetchRealObject(irit.coord( pt, 1 )), irit.FetchRealObject(irit.coord( pt, 2 )) ), irit.VECTOR_TYPE ) * \ irit.coord( pt, 4 ) vec = irit.normalizeVec(vec) * size pt = irit.seval(srf, irit.FetchRealObject(irit.coord(pt, 1)), irit.FetchRealObject(irit.coord(pt, 2))) irit.snoc( pt + irit.coerce(irit.coerce(pt, irit.POINT_TYPE) + vec, irit.E3), retval) i = i + 1 return retval
def perpvector(v): v1 = irit.vector(irit.FetchRealObject(irit.coord(v, 1)), irit.FetchRealObject(irit.coord(v, 2)), irit.FetchRealObject(irit.coord(v, 0))) retval = irit.normalizeVec(v1 ^ v) return retval
irit.interact(all) irit.save("puz2anm2", all) # ############################################################################ # # Prism's puzzle. # eps = 0.025 an = 71 ca = math.cos(an * math.pi / 180) sa = math.sin(an * math.pi / 180) vec1 = irit.vector(1, 0, 0) vec2 = irit.vector((-ca), sa, 0) vec3 = irit.coerce( irit.normalizeVec(irit.normalizeVec(vec1 + vec2) + irit.vector(0, 0, 1.4)) * 0.5, irit.VECTOR_TYPE) prism1 = irit.gbox((0, 0, 0), irit.Fetch3TupleObject(vec1), irit.Fetch3TupleObject(vec2), irit.Fetch3TupleObject(vec3)) rvec = vec2 ^ vec3 prism2 = prism1 * \ irit.rotvec( irit.Fetch3TupleObject(rvec), \ 180 * math.acos( irit.FetchRealObject(irit.normalizeVec( vec2 ) * irit.normalizeVec( vec3 )) )/ math.pi ) * \ irit.trans( irit.Fetch3TupleObject(-vec2 ) ) * \ irit.rotvec( irit.Fetch3TupleObject(vec2), (-60 ) ) * \ irit.trans( irit.Fetch3TupleObject((-vec1 ) + irit.normalizeVec( vec1 + vec2 )*0.6 + irit.vector( 0, 0, 0.81 )) ) item1 = prism1 ^ prism2 irit.color(item1, irit.RED)
save_res = irit.GetResolution() ed1 = irit.edge2d(0, 0, 1, 1) ed2 = irit.edge2d((-1), (-1), (-1), 2) ed3 = irit.edge3d(0, 0, 0, 1, 1, 1) ed4 = irit.edge3d((-1), 0, 1, 1, 2, (-1)) irit.interact(irit.list(irit.GetAxes(), ed1, ed2, ed3, ed4)) # printf( "%d) v3 = %19.16vf :: ", list( i, v3- v3*m ) ): i = 0 while (i <= 9): v1 = irit.vector(irit.random((-1), 1), irit.random((-1), 1), irit.random((-1), 1)) v1 = irit.normalizeVec(v1) v2 = irit.vector(irit.random((-1), 1), irit.random((-1), 1), irit.random((-1), 1)) v2 = irit.normalizeVec(v2) v3 = v1 ^ v2 v3 = irit.normalizeVec(v3) m = irit.rotv2v(irit.Fetch3TupleObject(v1), irit.Fetch3TupleObject(v2)) #irit.printf( "%d) v1 = %7.4vf v2 = %7.4vf :: ", irit.list( i, v1, v2 ) ) print str(i) + \ ") v1 = " + \ str(irit.Fetch3TupleObject(v1)) + \ ") v2 = " + \ str(irit.Fetch3TupleObject(v2)) if (v1 * m != v2 or v2 * (m ^ (-1)) != v1 or v3 != v3 * m): print "errror\n"
allitems = irit.list(item1, item2, item3, item4, item5, item6) irit.interact(allitems) irit.save("stckstrr", allitems) # ############################################################################ # Coupled prisms # eps = 0.025 an = 71 ca = math.cos(an * math.pi / 180) sa = math.sin(an * math.pi / 180) vec1 = irit.vector(1, 0, 0) vec2 = irit.vector((-ca), sa, 0) vec3 = irit.coerce( irit.normalizeVec(irit.normalizeVec(vec1 + vec2) + irit.vector(0, 0, 1.4)) * 0.5, irit.VECTOR_TYPE) prism1 = irit.gbox((0, 0, 0), irit.Fetch3TupleObject(vec1), irit.Fetch3TupleObject(vec2), irit.Fetch3TupleObject(vec3)) rvec = vec2 ^ vec3 prism2 = prism1 * \ irit.rotvec( irit.Fetch3TupleObject(rvec), \ 180 * \ math.acos( irit.FetchRealObject(irit.normalizeVec( vec2 ) * irit.normalizeVec( vec3 ) ) )/ \ math.pi ) * \ irit.trans( irit.Fetch3TupleObject(-vec2 ) ) * \ irit.rotvec( irit.Fetch3TupleObject(vec2), (-60 ) ) * \ irit.trans( irit.Fetch3TupleObject( (-vec1 ) + \ irit.normalizeVec( vec1 + vec2 )*0.6 + \
# save_res = irit.GetResolution() import teapot2 spout2 = teapot2.spout2 irit.SetResolution(10) spout2 = irit.gpolygon(spout2, 1) irit.color(spout2, irit.RED) # # Extract silhouettes. # pl1 = irit.ppropftch(spout2, 1, irit.list(irit.normalizeVec(irit.vector(1, 1, 1)), 90)) pl2 = irit.ppropftch(spout2, 1, irit.list(irit.normalizeVec(irit.vector(1, (-1), 1)), 90)) pl3 = irit.ppropftch(spout2, 1, irit.list(irit.normalizeVec(irit.vector(1, 0, 1)), 90)) irit.color(pl1, irit.WHITE) irit.color(pl2, irit.CYAN) irit.color(pl3, irit.GREEN) irit.adwidth(pl1, 3) irit.adwidth(pl2, 3) irit.adwidth(pl3, 3) view_mat2 = irit.GetViewMatrix() * irit.sc(0.5) * irit.ty(0.5) all = irit.list(spout2, pl1, pl2, pl3) irit.save("poly1prp", all) irit.interact(irit.list(view_mat2, irit.GetAxes(), all))
irit.ctlpt( irit.E3, 3.1, 0.4, 1.85 ), \ irit.ctlpt( irit.E3, 3.3, 1.3, 1.3 ), \ irit.ctlpt( irit.E3, 2.9, 2.1, 0.5 ), \ irit.ctlpt( irit.E3, 2.9, 3.5, 1.4 ), \ irit.ctlpt( irit.E3, 3, 4.6, 1.8 ) ), irit.list( \ irit.ctlpt( irit.E3, 4.1, 0.1, 1.85 ), \ irit.ctlpt( irit.E3, 4, 1.2, 1.75 ), \ irit.ctlpt( irit.E3, 4.3, 2, 1.65 ), \ irit.ctlpt( irit.E3, 3.9, 3.4, 1.95 ), \ irit.ctlpt( irit.E3, 4, 4.2, 1.85 ) ) ), irit.list( irit.list( irit.KV_OPEN ), irit.list( irit.KV_OPEN ) ) ) # # Compute a rotation matrix that rotates s2 so that its tangent plane at # the sampled point is the same as the tangent plane of s1 their # nrml1 = irit.normalizeVec( irit.coerce(irit.seval(irit.snrmlsrf(s1), 0.75, 0.3), 4)) tan1a = irit.normalizeVec( irit.coerce(irit.seval(irit.sderive(s1, irit.ROW), 0.75, 0.3), 4)) tan1b = tan1a ^ nrml1 rot1 = irit.homomat( irit.list( irit.list(irit.coord(tan1a, 0), irit.coord(tan1a, 1), irit.coord(tan1a, 2), 0), irit.list(irit.coord(tan1b, 0), irit.coord(tan1b, 1), irit.coord(tan1b, 2), 0), irit.list(irit.coord(nrml1, 0), irit.coord(nrml1, 1), irit.coord(nrml1, 2), 0), irit.list(0, 0, 0, 1))) irit.free(tan1a) irit.free(tan1b) irit.free(nrml1)
irit.free(n) irit.attrib(nrml, "dwidth", irit.GenRealObject(8)) irit.color(nrml, irit.RED) irit.interact(irit.list(c, nrml, p)) dc1 = irit.tsderive(c, irit.ROW) irit.color(dc1, irit.YELLOW) dc2 = irit.tsderive(c, irit.COL) irit.color(dc2, irit.MAGENTA) dc3 = irit.tsderive(c, irit.DEPTH) irit.color(dc3, irit.CYAN) v1 = irit.coerce(irit.tseval(dc1, 1 / 3.0, 1 / 3.0, 1 / 3.0), irit.VECTOR_TYPE) v2 = irit.coerce(irit.tseval(dc2, 1 / 3.0, 1 / 3.0, 1 / 3.0), irit.VECTOR_TYPE) n2 = irit.normalizeVec(v1 ^ v2) nrml2 = (irit.coerce(p, irit.E3) + irit.coerce(irit.coerce(p, irit.POINT_TYPE) + n2, irit.E3)) irit.free(v1) irit.free(v2) irit.free(n2) irit.attrib(nrml2, "dwidth", irit.GenRealObject(4)) irit.color(nrml2, irit.BLUE) irit.interact( irit.list( irit.GetAxes(), c, dc1, dc2, dc3, nrml,\ nrml2, p ) ) irit.free(dc1) irit.free(dc2) irit.free(dc3) irit.free(nrml) irit.free(nrml2)