plotting

14
1 SIC / CoC / Georgia Tech MAGIC MAGIC Lab Lab http:// www.gvu.gatech.edu/ Jarek Rossignac Plotting Read/write files in processing Refine a sampled curve Plot curves Exaggerate the discrepancy between two curves Use keys to control view parameters Produce pulsating animation Form teams for Project 1 Investigate how to visualize plot discrepancies

Upload: fredericka-mclaughlin

Post on 31-Dec-2015

19 views

Category:

Documents


0 download

DESCRIPTION

Plotting. Read/write files in processing Refine a sampled curve Plot curves Exaggerate the discrepancy between two curves Use keys to control view parameters Produce pulsating animation Form teams for Project 1 Investigate how to visualize plot discrepancies. Write to a file. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Plotting

1SIC / CoC / Georgia TechMAGIC MAGIC LabLabMAGIC MAGIC LabLab

http://www.gvu.gatech.edu/~jarek

Jarek Rossignac

Plotting

Read/write files in processing Refine a sampled curve Plot curves Exaggerate the discrepancy between two

curves Use keys to control view parameters Produce pulsating animation Form teams for Project 1 Investigate how to visualize plot

discrepancies

Page 2: Plotting

2SIC / CoC / Georgia TechMAGIC MAGIC LabLabMAGIC MAGIC LabLab

http://www.gvu.gatech.edu/~jarek

Jarek Rossignac

Write to a file

float [] F = {200,240,250,210.1,160,150,170,200,209,240,250,220,200,150,110,100}; // array of values

int n=F.length; // number of entries in F

String [] SF = new String [n]; // allocate table of strings that will contain strings representing F[0], F[1]...F[n-1]

for (int i=0; i<n; i++) SF[i]=str(F[i]); // store string forms of F values in SF

saveStrings("F.val",SF);

// writes content of SF to a file named F.val created in

the sketch folder

Page 3: Plotting

3SIC / CoC / Georgia TechMAGIC MAGIC LabLabMAGIC MAGIC LabLab

http://www.gvu.gatech.edu/~jarek

Jarek Rossignac

Read a file

String [] SF = loadStrings("F.val"); // reads array of strings from a file named F.val in the sketch folder

int n=SF.length; // sets the number of values in the array

float [] F = new float [n]; // table of values that will be extracted from the strings

for (int i=0; i<n; i++) F[i] = float(SF[i]); // recovers float values from strings and stores in F

for (int i=0; i<n; i++) println(F[i]); // prints read values in the bottom pane of the Processing window

// does not work in applets

Page 4: Plotting

4SIC / CoC / Georgia TechMAGIC MAGIC LabLabMAGIC MAGIC LabLab

http://www.gvu.gatech.edu/~jarek

Jarek Rossignac

Interpolate

Write the expression for C in terms of A and B

AA C=C= BB

AA C=C= BB

dd dd

dd sdsd

Page 5: Plotting

5SIC / CoC / Georgia TechMAGIC MAGIC LabLabMAGIC MAGIC LabLab

http://www.gvu.gatech.edu/~jarek

Jarek Rossignac

Insert new sample

Insert a new sample along each edge: M=(B+D)/2

Displace it (bulge-out). By how much? Fit a cubit C=C(t) through A, B, D, and E

C(t)=at3+bt2+ct+d, and thus C(0)=dSet 4 constraints and solve for d:B=C(–1)= –a+b–c+d D=C( 1)= a+b+c+dA=C(–3)= –27a+9b–3c+d E=C( 3)= 27a+9b

C(0)

C(3)

M

A

B D

EC(-3)

C(-1) C(1)

M’bulge = bulge = M’M/8M’M/8

M’=(A+E)/M’=(A+E)/2=9b+d2=9b+d

M=(B+D)/M=(B+D)/2=b+d2=b+d

M’–9M=–8dM’–9M=–8d

C(0)=d=M+(M–M’)/8C(0)=d=M+(M–M’)/8

Page 6: Plotting

6SIC / CoC / Georgia TechMAGIC MAGIC LabLabMAGIC MAGIC LabLab

http://www.gvu.gatech.edu/~jarek

Jarek Rossignac

Boundary conditions

The bulge of an edge is computed from 2 neighbors on each side

What if you have only one neighbor on one side?– Add a dummy (missing) sample estimated from neighbors

C(0)

C(3)

M

A

B D

EC(-3)

C(-1) C(1)

M’

If A is unknown, estimate it as If A is unknown, estimate it as E+3(B–D) E+3(B–D)

Page 7: Plotting

7SIC / CoC / Georgia TechMAGIC MAGIC LabLabMAGIC MAGIC LabLab

http://www.gvu.gatech.edu/~jarek

Jarek Rossignac

Refine a sampling

String [] SF = loadStrings("F.val"); // reads array from F.valint n=SF.length; // sets the number of

values in the arrayfloat [] F = new float [n]; // table of values for (int i=0; i<n; i++) F[i]=float(SF[i]); // recover F values from stringsint r = 2*n-1; // number of values

in refined array float [] R = new float [r]; // refined array for (int i=0; i<n; i++) R[2*i]=F[i]; // copies F values into even

entries of Rfor (int i=3; i<r-3; i=i+2) R[i]=((-R[i-3]+9*R[i-1]+9*R[i+1]-R[i+3])/16); // computes intermediate odd values through cubit

interpolationR[1]=(3*R[0]+6*R[2]-R[4])/8; R[r-2]=(3*R[r-1]+6*R[r-3]-R[r-5])/8; // computes first and last odd value using estimated

dummy

String [] SR = new String [r]; // allocate table of strings for (int i=0; i<r; i++) SR[i]=str(R[i]); // store string forms of R values

in SRsaveStrings("F.val",SR); // overwrite F.val with

refeined values

Page 8: Plotting

8SIC / CoC / Georgia TechMAGIC MAGIC LabLabMAGIC MAGIC LabLab

http://www.gvu.gatech.edu/~jarek

Jarek Rossignac

Exaggerate discrepancy

Write the expression for C in terms of A and B

AA BB C C ==

AA BB C C ==

dd dd

dd sdsd

Page 9: Plotting

9SIC / CoC / Georgia TechMAGIC MAGIC LabLabMAGIC MAGIC LabLab

http://www.gvu.gatech.edu/~jarek

Jarek Rossignac

Exaggerate discrepancy of two plots

void exaggerate (float s) { for (int i = 0; i<n; i++) { EF[i]=(s+1.)*F[i]-s*G[i]; EG[i]=(s+1.)*G[i]-s*F[i]; }; }

What happens when s=0?What happens when s=0?

What happens when s=1?What happens when s=1?

Page 10: Plotting

10SIC / CoC / Georgia TechMAGIC MAGIC LabLabMAGIC MAGIC LabLab

http://www.gvu.gatech.edu/~jarek

Jarek Rossignac

Plot: Global variables

color red; …. // declare colors but do not assign values yet

// because we want to use the HSB color modeint n=1000; // cap on the number of values

float [] F = new float [n]; // table F float [] G = new float [n]; // table Gfloat [] EF = new float [n]; // table of exaggerated F

float [] EG = new float [n]; // table of exaggerated G

float s=1.0; // exaggeration factor

boolean showExaggerated=false; // toggle normal/exaggerate mode

boolean pulsing=false; // toggle pulsing mode

Page 11: Plotting

11SIC / CoC / Georgia TechMAGIC MAGIC LabLabMAGIC MAGIC LabLab

http://www.gvu.gatech.edu/~jarek

Jarek Rossignac

Plot: setup (initialization code)

void setup() { size(500, 400); // open graphic window (size in

pixels) smooth(); strokeJoin(ROUND); strokeCap(ROUND); // want nice

polylines colorMode(HSB,121); // color mode: Hue, Saturation, Brightness

in [0..120] red = color(0, 120, 120); // …saturated, bright red String [] SF = loadStrings("F.val"); // reads array of

strings from F.val n=SF.length; //

sets the number of values in array for (int i=0; i<n; i++) F[i]=float(SF[i]); // store string

forms of F values String [] SG = loadStrings("G.val"); // reads array of

strings from G.val for (int i=0; i<n; i++) G[i]=float(SG[i]); // store string

forms of G values exaggerate(s); // computes EF and EG exaggerating differences

by factor s }

Page 12: Plotting

12SIC / CoC / Georgia TechMAGIC MAGIC LabLabMAGIC MAGIC LabLab

http://www.gvu.gatech.edu/~jarek

Jarek Rossignac

Draw (redisplay loop)

void draw() { background(50); // erase window using gray color strokeWeight(2); // set line width to 2 noFill(); // do not fill the interior of shapes if (pulsing) exaggerate(s*(2-cos(millis()/100.))); // if pulsing, exaggerate by a factor in [ 0 , 2s ] // computed using the current time in hundredths of

milliseconds if (showExaggerated) {stroke(red); plot(EF);

stroke(green); plot(EG);} else {stroke(orange); plot(F);

stroke(cyan); plot(G); }; }

void plot (float [] F) { // plot through n samples with values in F

beginShape(); for (int i = 0; i<n; i++) vertex(i,height-F[i]); endShape();

} // y axis goes down, so we use height-F[i]

Page 13: Plotting

13SIC / CoC / Georgia TechMAGIC MAGIC LabLabMAGIC MAGIC LabLab

http://www.gvu.gatech.edu/~jarek

Jarek Rossignac

User Interface (keyboard)

void keyPressed() { // executed when a key is pressed

if (key==' ') showExaggerated=!showExaggerated; // toggle normal/exagerated display mode

if (key=='/') {pulsing=!pulsing;}; // toggle pulsing

if (key=='.') s*=2; if (key==',') s/=2; // double / half the exaggeration factor

if (key=='1') s=1; // resets s to 1 (mild exaggeration)

exaggerate(s); // re-computes the exaggerated values

};

Page 14: Plotting

14SIC / CoC / Georgia TechMAGIC MAGIC LabLabMAGIC MAGIC LabLab

http://www.gvu.gatech.edu/~jarek

Jarek Rossignac

Results

s=1s=1 s=16s=16