Presentation is loading. Please wait.

Presentation is loading. Please wait.

Grafika Komputer dan Visualisasi Disusun oleh : Silvester Dian Handy Permana, S.T., M.T.I. Fakultas Telematika, Universitas Trilogi Pertemuan 12 : Realisme.

Similar presentations


Presentation on theme: "Grafika Komputer dan Visualisasi Disusun oleh : Silvester Dian Handy Permana, S.T., M.T.I. Fakultas Telematika, Universitas Trilogi Pertemuan 12 : Realisme."— Presentation transcript:

1 Grafika Komputer dan Visualisasi Disusun oleh : Silvester Dian Handy Permana, S.T., M.T.I. Fakultas Telematika, Universitas Trilogi Pertemuan 12 : Realisme Virtual

2 This Week Pendekatan – Fraktal dan Kesamaan Diri – Sistem Fungsi Iteratif (Iterative Function Systems) – Sistem Lindenmayer – Kurva – Citra alami (pohon, landscapes, dll) – Kompresi Fraktal – Set Mandelbrot dan set Julia – Fractal Landscapes

3 Introduction What is a Fractal? – A fractal is an image with self-similar properties produced by recursive or iterative algorithmic means. “anything which has a substantial measure of exact or statistical self-similarity” – Mandelbrot coined the term from the latin fractus meaning “fragmented” or “irregular”

4 Introduction Why use fractals in Computer Graphics? Most real world objects are inherently smooth. Most real world objects cannot be represented by simple prisms and ellipsoids. Most real world objects cannot best be described by fixed mathematical curves (e.g. sin, cos etc..)

5 Introduction Although curves can represent natural phenomena they can become very complex e.g. Trees, Mountains, Water, Clouds etc... Clouds are not spheres, coastlines are not circles, bark is not smooth, nor does lightning travel in straight lines. -Mandelbrot

6 Introduction Fractals are useful for representing natural shapes such as trees, coastlines, mountains, terrain and clouds. Magnification of these things review smaller self-similar copies of the entire image.

7 Branches are self-similar Roots are self-similar

8 Fractal Curve Refinement The Koch Snowflake Very complex curves can be fashioned recursively by repeatedly refining the curve. Koch Curve: subdivide each segment of Kn into three equal parts, and replace the middle part with a bump in the shape of an equilateral triangle.

9 Fractal Curve Refinement //dir - turtle angle //len - length of line segment //n - number of iterations void drawKoch(double dir, double len,int n) { double dirRad = 0.0174533 * dir; // in radians if(n == 0) cvs.forward(len,1); else{ n--;// reduce the order len /= 3;// and the length drawKoch(dir, len, n); dir += 60; putarKe(dir); drawKoch(dir, len, n); dir -= 120; putarKe(dir); drawKoch(dir, len, n); dir += 60; putarKe(dir); drawKoch(dir, len, n); }

10 Lindenmayer Systems An L-System works by giving the turtle a string sequence where each symbol in the sequence gives turtle instructions. ‘F’ -> go forward 1 step ‘+’ -> turn right by x degrees ‘-’ -> turn left by x degrees where x is set and predetermined.

11 Lindenmayer Systems The string F+F-F means go forward turn right, go forward, turn left and go forward.

12 Lindenmayer Systems L-Systems are produced based on a production rule. This rule is iteratively applied to the string. e.g. F -> “F+F” means that all ‘F’s in the string should be replaced with “F+F” therefore, F+F-F becomes: F+F+F+F-F+F

13 L-Systems Starting with: F+F+F+F and the production rule: F -> F+F-F-FF+F+F-F After one iteration the following string would result F+F-F-FF+F+F-F + F+F-F-FF+F+F-F + F+F-F- FF+F+F-F + F+F-F-FF+F+F-F

14 L-Systems After 2 iterations the string would be: F+ F-F-FF+ F+ F-F+ F+ F-F-FF+ F+ F-F-F+ F-F-FF+ F+ F-F-F+ F-F-FF+ F+ F-FF+ F-F-FF+ F+ F-F+ F+ F-F-FF+ F+ F-F+ F+ F- F-FF+ F+ F-F-F+ F-F-FF+ F+ F-F+ F+ F-F-FF+ F+ F-F+ F+ F-F- FF+ F+ F-F-F+ F-F-FF+ F+ F-F-F+ F-F-FF+ F+ F-FF+ F-F-FF+ F+ F-F+ F+ F-F-FF+ F+ F-F+ F+ F-F-FF+ F+ F-F-F+ F-F-FF+ F+ F-F+ F+ F-F-FF+ F+ F-F+ F+ F-F-FF+ F+ F-F-F+ F-F-FF+ F+ F-F-F+ F-F-FF+ F+ F-FF+ F-F-FF+ F+ F-F+ F+ F-F-FF+ F+ F-F+ F+ F-F-FF+ F+ F-F-F+ F-F-FF+ F+ F-F+ F+ F-F-FF+ F+ F- F+ F+ F-F-FF+ F+ F-F-F+ F-F-FF+ F+ F-F-F+ F-F-FF+ F+ F- FF+ F-F-FF+ F+ F-F+ F+ F-F-FF+ F+ F-F+ F+ F-F-FF+ F+ F-F- F+ F-F-FF+ F+ F-F

15 L-Systems produceString(char *rule, int iterations) { FILE *ifp, *ofp; for(int i = 0; i < iterations; i++) { if( (ifp = fopen("ldata.txt","r")) == NULL || (ofp = fopen("ltemp.txt","w")) == NULL ) exit(-1); //cannot open files int ch; while((ch = fgetc(ifp)) != -1) { switch(ch) { case 'F': fprintf(ofp,"%s",rule); break; default: fprintf(ofp,"%c",ch); break; } fclose(ifp); fclose(ofp); remove("ldata.txt"); rename("ltemp.txt", "ldata.txt"); }

16 L-Systems drawString(int len, float angle) { FILE *ifp; if( (ifp = fopen("ldata.txt","r")) == NULL ) exit(-1); //cannot open files int ch; while( (ch = fgetc(ifp)) != -1) { switch(ch) { case 'F': terusKe(len, 1); break; case '+': putarKe(-angle); break; case '-': putarKe(angle); break; }

17 Programming L-Systems void myDisplay(void) { cvs.clearScreen(); glLineWidth(3); pindahKe(-50.0,0.0); produceString("F-F++F-F", 3); drawString(20,60); glFlush(); }

18 L-Systems Programming L- Systems – The more iterations you do, the bigger the curve will get.. – Therefore you need to modify the length of the sides depending on the number of iterations. 1 iteration 3 iterations

19 L-Systems There is a limit to the number of shapes that can be drawn with just and ‘F’ directive. L-Systems need to be restricted to just F, you can use however many replacement letters and strings you like.

20 L-Systems For example, F, X and Y: F -> ‘F’ X -> ‘X+YF+’ Y -> ‘-FX-Y’ atom = “X” (starting string) But the turtle only draws with F – This of course is no rule, you could make X and Y draw as well… it is up to you!!!

21 L-Systems The Dragon Curve F -> ‘F’ X -> ‘X+YF+’ Y -> ‘-FX-Y’ atom = “X” 12 iterations

22 L-Systems Koch Island F -> ‘F+F-F-FF+F+F-F’ X -> ‘’ Y -> ‘’ atom = “F+F+F+F” 5 iterations

23 L-Systems If you look at a tree you will notice that it is made up of smaller copies of itself. e.g. A tree branch is just a smaller version of a tree. Being self-similar doesn’t mean each smaller version has to be EXACTLY the same.

24 L-Systems Lets look at a tree F F F F F -> F+F-F But that can’t be right?

25 L-Systems Lets look at a tree F F F F F -> F+F-F start here return here

26 L-Systems Lets look at a tree F F F F F -> F[+F]-F start here return here

27 L-Systems Lets look at a tree F -> F[+F][-F] push the turtle locationpop the turtle location

28 L-Systems Lets look at a tree F -> F[+F][-F] atom “F”

29 L-Systems Lets look at a tree F -> FF-[-F+F+F]+[+F-F-F] atom “F”

30 L-Systems Lets look at a tree Some L-System trees can look a little ‘calculated’, therefore random angles and lengths can be introduced. This is the same tree (above) and below with random lengths and angles.

31 L-Systems …or you can modify the thickness or length of the branch (lines) depending on the level at which it appears in the tree.

32 Affine Transformations For example, take these: original image (1x1) What will it look like after the transformations??

33 Affine Transformations For example, take these:

34 Affine Transformations

35 An my personal favourite: Affine Transformations: T {a,b,c,d,e,f} T1 {0,0,0,0,0.16,0} T2 {0.2,-0.26,0,0.23,0.22,1.6} T3 {-0.15,0.28,0,0.26,0.24,0.44} T4 {0.75,0.04,0,-0.04,0.85,1.6}

36 Affine Transformations An my personal favourite:

37 Affine Transformations An my personal favourite:

38 Affine Transformations An my personal favourite:

39 Iterative Function Systems An iterative function system (IFS) takes a set of affine transformations and transforms a point through them based on a random selection of the transformation. An IFS is a collection of N affine transformations T i, for I = 1,2,…,N

40 Iterative Function Systems Generating an IFS – Chaos Game select a random point do { select a random transformation run point through transformation plot new point set old point to new point }while (!bored)

41 Iterative Function Systems Generating an IFS – Chaos Game select a random point do { select a random transformation run point through transformation plot new point set old point to new point }while (!bored)

42 Iterative Function Systems The idea: All points on the attractor (final image) are reachable by applying a long sequence of affine transformations. The random selection of transformations is invoked to ensure the system is “fully exercised”

43

44 Fractal Compression Looking for self-similar sections of an image and using them to reconstruct the whole image. Affine Mappings are used to reconstruct the image.

45 Fractal Compression

46 The Mandelbrot Set Julia and Mandelbrot sets arise from iteration theory. Iteration Theory: – What happens when a function is iterated endlessly? Mandelbrot used computer graphics to perform essential experiments.

47 The Mandelbrot Set The Mandelbrot set uses the IFS: f(z) = z 2 + c – where c is some constant. The system produces each “output” by squaring its “input” and adding c. The ORBIT of the input determines how a value is plotted.

48 The Mandelbrot Set An orbit is the set of values “output” as the function is iterated. For example: f(z) = z 2 + 2 with starting value 0 the sequence of output is: 2, 6, 38, 1 446, 2 090 918, … This orbit is said to be infinite as its values are approaching infinity (called a infinite orbit).

49 The Mandelbrot Set A finite orbit is one where the output values settle down around a single value. For example: f(z) = z 2 - 1 with starting value 0 the sequence of output is: 0, -1, 0, -1, 0, -1 These values cycles endlessly and are considered finite!

50 The Mandelbrot Set Definition: The Mandelbrot set, M, is the set of all complex numbers, c, that produce a finite orbit of 0. This means that with a starting value of 0, which values for c (using complex numbers) produce finite sequences of outputs.

51 The Mandelbrot Set The first few values would be: 0, c, c 2 +c, (c 2 +c)+c, … where c = x + yi A plot of the values for c reveals the Mandelbrot set.

52 The Mandelbrot Set If you plot the orbits for values of c inside the set you will see the orbits forming. For points with c outside the set, the plots reveal lines going off into infinity. -mandelbrot_orbit.exe

53 Julia Sets Julia sets are extremely complicated sets of points in the complex plane. There is a different Julia set for each value of c. One version is the Filled Julia Set: – the set of all starting points whose orbits are finite.

54 Julia Sets c = -0.5+0.58i

55 Julia Sets c = -0.76+0.147i

56 Julia Sets c = 0.32019+0.25694i

57 Julia Sets c = -0.74+0.14i

58 Fractal Landscapes

59 Divide and Perturb

60 Fractal Landscape

61

62

63

64

65 Fractal Landscapes Brownian Motion – divide and lift – randomly cut a line in two, randomly lift that point, then smooth surrounding area.

66 Fractal Landscapes Step One: Randomly select a spot on a mesh and raise height by a random amount.

67 Fractal Landscapes Step Two: Slope from tip of adjusted height to edge of map.

68 Fractal Landscapes Step Three: Do this for all edges of the map.

69 Fractal Landscapes Step Four: Smooth sharp ridges by raising surrounding surface to an even slope.

70 Fractal Landscapes Step Five: Do this for all four ridges.

71 Fractal Landscapes Step Six: Perform the lifting and smooth procedure as many times as you like.

72 Fractal Landscapes Step Seven: Now decide on a maximum height and chop the highest peaks off. You can also do this for low points to create areas for water.

73 Fractal Landscapes Step Eight: Smooth peak caps by averaging the height with the neighbouring vertices.

74 Fractal Landscapes Step Eight: Colour as you see fit.

75 QA


Download ppt "Grafika Komputer dan Visualisasi Disusun oleh : Silvester Dian Handy Permana, S.T., M.T.I. Fakultas Telematika, Universitas Trilogi Pertemuan 12 : Realisme."

Similar presentations


Ads by Google