Class 5: Space

- vectors, transformations
* what is a vector * ops: length, normalization, scaling, addition/sub. * dot product * determinant, cross product * what is a matrix * ops: addition/subtraction, scaling, multiplication, inverse * xfmns: R, S, T Multiplication example: Let A be [ 1 2 3 4 ] and B be [ 5 6 7 8 ] To do A*B, multiply each *row* of A with each *column* of B: [ 1*5+2*7 1*6+2*8 3*5+4*7 3*6+4*8 ] which is [ 19 22 43 50 ] Note that this NOT achievable by multiplying each element of A with the corresponding one for B (such an operation is meaningless). Inverse example: Given A above, what is B such that A*B = [ 1 0 0 1 ] ? B is defined as transpose(adjoint(A))/deta(A). det(A) = 1*4-2*3 = -2 adjoint(A) = [ 4 -3 -2 1 ] Note the + - + - alternation. transpose(adjoint(A)) is [ 4 -2 -3 1 ] transpose(adjoint(A))/det(A) (our inverse!) is [ 4/-2 -2/-2 -3/-2 1/-2 ] which is [ -2 1 1.5 -0.5 ] To verify that this is the inverse, do A*B: [ 1*-2+2*1.5 1*1-2*0.5 3*-2+4*1.5 3*1-4*.5 ] which is [ 1 0 0 1 ] which is what we want (identity matrix).

- projection
Given a (Px,Py,Pz) in front of a projection plane, what is the screen coord (Sx,Sy)? f = .5*w/tan(.5*HFOV) g = .5*h/tan(.5*VFOV) Sx = Px*f/(f+Pz) + 0.5*w Sy = Py*g/(g+Pz) + 0.5*h ALL SORTS of other projections are possible by altering the equations for Sx and Sy. Eg. a non-linear projection is here: http://egl.math.umd.edu/gallery.html More notes/imgs: * http://vismod.media.mit.edu/tech-reports/TR-523/node6.html * Google image search: "perspective projection" equation

- lighting
Diffuse calculation: N.L Specular calculation: pow(R.V,n) or pow(H.N,n) [R = 2N(N.L) - L (why?)]

- Delaunay, Voronoi
Applet: http://www.personal.kent.edu/~rmuhamma/Compgeometry/MyCG/Voronoi/Incremental2/incremental2.htm Voronoi diagrams are COOL!!!!! www.voronoi.com - has a LOT of info. Art: http://www.mrl.nyu.edu/~ajsecord/npar2002/

Voronoi diagrams are quite useful in CG for art (stippling, ornamentation, mosaics etc.), crowds placement, creating pebbled roads, condensation water droplets, spider webs, cellular (leathery) wrinkles, bubbles and for brittle fracturing surfaces.

As an aside, here's what happens when spiders do drugs:

http://www.trinity.edu/jdunn/spiderdrugs.htm

http://www.psymon.com/psychedelia/images/spiders.html

Here is more info. on using Voronoi polygons for fracture:

http://www.smartcg.com/tech/cg/notes/Voronoi/fracture

- quadtrees, octrees
Ways to partition space, into hierarchical grids (squares, cubes) http://http.cs.berkeley.edu/~demmel/cs267/lecture26/lecture26.html Examples: http://www.embedinc.com/book/model.htm http://www.inf.ufsc.br/~visao/1998/harley/octree.htm

- barycentric coords
Google image search: "barycentric coordinate" The parametric or barycentric coordinates of a given 3D point P=(x,y,z) relative to a triangle T=V0V1V2 in the plane are calculated as follows. We start by setting u = V1-V0 and v = V2-V0, w = P-V0. Then we find the parametric coordinates (s,t) of P as the solution of the equation: w = su + tv. This solution exists and is unique when P lies in the plane of T. So what are s and t? s = ((u.v)(w.v)-(v.v)(w.u))/((u.v)(u.v)-(u.u)(v.v)) t = ((u.v)(w.u)-(u.u)(w.v))/((u.v)(u.v)-(u.u)(v.v)) Once we have s,t, we can calculate (b0,b1,b2) (or what we call ($u,$v,$w) below) as b0=(1-s-t), b1=s, b2=t (note that b0+b1+b2=1). The barycentric coordinates of P in terms of (V0V1V2) and (b0,b1,b2)are found from P = b0V0 + b1V1 + b2V2. Here's some MEL code to do this: // Given a triangle (p,q,r) and a barycentric weights (u,v,w), here is // the (x,y,z) for the barycentric weights float $x = $u*$p.x + $v*$q.x + $w*$r.x; float $y = $u*$p.y + $v*$q.y + $w*$r.y; float $z = $u*$p.z + $v*$q.z + $w*$r.z;

- color spaces
http://escience.anu.edu.au/lecture/cg/Color/printNotes.en.html http://www.cs.rit.edu/~ncs/color/t_convert.html

- inversion
Given a circle and a point, an inverse of the point is defined w.r.t the point's distance from the circle's center. * points near the center get inverted to 'very far away' * points far away get inverted to locations close to the circle center * points on the circumference stay put In essence, inversion turns regions inside-out w.r.t a circle! http://en.wikipedia.org/wiki/Inversive_geometry C++ (Maya plugin) code: // given a point 'pt', an inversion center (xcenter,ycenter,zcenter) // and an inversion radius 'sph_radius', here's how to compute the // inverted point for(;!iter.isDone();iter.next()) { MPoint pt = iter.position(); // get double dist = (pt.x-xcenter)*(pt.x-xcenter) + (pt.y-ycenter)*(pt.y-ycenter)+\ (pt.z-zcenter)*(pt.z-zcenter); if(dist!=0.0) { double inv = (sph_radius*sph_radius)/dist; //R*R/(x^2+y^2+z^2) // set pt.x *= inv; pt.y *= inv; pt.z *= inv; // set } } Examples: http://egl.math.umd.edu/gallery.html

- grid warping, anam warping, lens distortions
Google image search: "grid warp" http://computing.ee.ethz.ch/sepp/vtk-4.2.1-rs.SEPP/build/VTKData/Baseline/Hybrid/TestGridWarpCubic.png http://alumni.media.mit.edu/~sbeck/results/Distortion/distortion.html http://local.wasp.uwa.edu.au/~pbourke/projection/lensdistortion/ Google image searches: ["Escher" balcony] and ["Escher" "print gallery"]

- non-Euclidian (eg. hyperbolic) space
The internal angles of a triangle add up to 180 degrees only on a 'flat' (planar) triangle. What about "curved" triangles? Google image search: spherical geometry Google image search: hyperbolic geometry