summaryrefslogtreecommitdiff
path: root/vodaviz.pde
diff options
context:
space:
mode:
Diffstat (limited to 'vodaviz.pde')
-rw-r--r--vodaviz.pde250
1 files changed, 100 insertions, 150 deletions
diff --git a/vodaviz.pde b/vodaviz.pde
index 3590b93..ea103a3 100644
--- a/vodaviz.pde
+++ b/vodaviz.pde
@@ -79,9 +79,6 @@ The intermediate latitude and longitude is then given by:
import processing.pdf.*;
import geomerative.*;
-float log10 (float x) {
- return (log(x) / log(10));
-}
class pointNormalise {
//take pixel coords and turn into lat/lng radians
float xo,xs,yo,ys;
@@ -91,34 +88,38 @@ class pointNormalise {
yo=_yo;
ys=_ys;
}
- RPoint alise(RPoint p) {
- //normalise
- float px=(((p.x-xo)/xs)-0.5)*PI*2; //26)/736);
- float py=(((p.y-yo)/ys)-0.5)*PI; //90)/390);
+ RPoint alise(RPoint in) {
+ //formalise
+ float px=(((in.x-xo)/xs)*PI*2); //26)/736);
+ float py=((in.y-yo)/ys)*PI; //90)/390);
return new RPoint(px,py);
}
}
-class pointTransform {
-
- RPoint form(RPoint in) {
- //transform
- return new RPoint (((in.x*0.25)+(PI/2)),((in.y)*0.3)+(PI/2)); //front half of sphere
- }
-
-}
-
-class sphereMap {
+class pointMapper {
- RPoint per(RPoint p,float _r) {
+ RPoint map(float _x,float _y,float _r) {
+ //transform
+ float px=((_x-PI)*0.25)+(PI/2); //(((_x-0.5)*0.25)+.25); //front half of sphere
+ float py=((_y-(PI/2))*0.3)+(PI/2); //((_y-0.5)*0.3)+0.5;
- //map to 3D sphere
- float r=getHeight()*_r;
- float x=r*cos(p.x)*(sin(p.y)) *2;
- float z=r*sin(p.x)*(sin(p.y))-985;
- float y=r*cos(p.y)+(getHeight()*0.5)-210;
+ //map to 3D curve
+ float r=getHeight()*4*_r;
+ float x=r*cos(px)*(sin(py)) *2;
+ float z=r*sin(px)*(sin(py))-985;
+ float y=r*cos(py)+(getHeight()*0.5)-210;
+
+
+ /*
+ //map to small sphere
+ float r=getHeight()/2;
+ float x=r*cos(px)*(sin(py));
+ float z=r*sin(px)*(sin(py))-105;
+ float y=r*cos(py);
+ */
+
//camera at 0,0,0
//screen plane at 0,0,100
@@ -126,180 +127,129 @@ class sphereMap {
//(dy-ey)(ez/dz)
//rotate camera
-
- //transform into 2D plane @100
return new RPoint(x*(100/z),y*(100/z));
- }
-}
-
-RPoint screenMapper(RPoint p) {
- p.x=((p.x*getWidth())/(PI*2))+(getWidth()/2);
- p.y=((p.y*getHeight())/PI)+(getHeight()/2);
- return p;
-}
-
-RPoint plerp(RPoint s,RPoint e,float a) {
- return new RPoint(lerp(s.x,e.x,a),lerp(s.y,e.y,a));
-}
-
-float GSphereDist(RPoint p1,RPoint p2) {
- return acos(sin(p1.y)*sin(p2.y)+cos(p1.y)*cos(p2.y)*cos(p1.x-p2.x));
-}
-
-RPoint GCircFract(RPoint sp,RPoint ep,float f) {
- float d=GSphereDist(sp,ep);
- float A=sin((1-f)*d)/sin(d);
- float B=sin(f*d)/sin(d);
- float x = A*cos(sp.y)*cos(sp.x) + B*cos(ep.y)*cos(ep.x);
- float y = A*cos(sp.y)*sin(sp.x) + B*cos(ep.y)*sin(ep.x);
- float z = A*sin(sp.y) + B*sin(ep.y);
- return new RPoint(atan2(y,x),atan2(z,sqrt(pow(x,2)+pow(y,2))));
+ }
}
RShape shp;
pointNormalise pnorm;
-pointTransform ptrans;
-sphereMap smap;
+pointMapper shpmap;
String mode;
csvloader data;
calldata calls;
-bitmapcountry Ireland;
-
-PImage lightmap;
+country Ireland;
void setup(){
- println("vodaviz v0.21");
+ println("vodaviz v0.11");
RG.init(this);
- //mode="PDF";
- if (mode=="PDF") size(832,220,PDF, "vodaviz_test_080212.pdf"); //P3D); //832,220); //nb pdf is 800x600
- else size(832,220); //,PDF, "testoutput.pdf"); //P3D); //832,220); //nb pdf is 800x600
+ mode="PDF";
+ size(832,220,PDF, "testoutput0602.pdf"); //P3D); //832,220); //nb pdf is 800x600
smooth();
float m = millis();
shp = RG.loadShape("countries_named_mercator.svg"); //test_drawing.svg"); //world_countries_outlines_split.svg");
- pnorm = new pointNormalise(18.279,746.302,129.314,374.293);
- ptrans = new pointTransform();
- smap = new sphereMap();
-
- lightmap=loadImage("earthlights2_dmsp_big.jpg");
-
+ pnorm = new pointNormalise(26,736,90,390);
+ shpmap = new pointMapper();
RG.ignoreStyles();
println("loaded svg in "+((millis()-m)*.001)+" seconds");
- Ireland=new bitmapcountry("Ireland",0,0,shp.children[0]);
- Ireland.analyse(18.279,746.302,129.314,374.293);
+ Ireland=new country("Ireland",0,0,shp.children[0]);
data=new csvloader("calls.csv");
calls=new calldata(data.data,shp);
- background(255,255,255);
+ background(0,0,0);
noFill();
stroke(255);
strokeWeight(.02);
- if (false) { //check worked example http://williams.best.vwh.net/avform.htm#Example
- RPoint LAX=new RPoint(2.066470,0.592539);
- RPoint JFK=new RPoint(1.287762,0.709186);
- println("LAX to JFK:"+GSphereDist(LAX,JFK)+" radians");
- RPoint LmJ=GCircFract(LAX,JFK,0.4);
- println("40% of LAX to JFK:"+LmJ.y+","+LmJ.x+" radians");
- }
-
-
-
+ //pick a random colour
+ stroke(random(200)+50, random(200)+50,random(200)+50);
+ println("plotting "+calls.countries.get(0).name+": "+calls.countries.get(0).calls+" calls");
}
int i=0;
int j=0;
void draw() {
- //if (i==0) image(lightmap,0,0,getWidth(),getHeight());
-
- //pick a random colour
- stroke(random(150)+10,random(150)+10,random(150)+10);
-
- if (true) //draw globe
- {
- if (true) { //draw countries
- beginShape();
- for (int k=0;k<calls.getcountry(i).outline.paths[0].commands.length;k++) {
- RPoint sp=calls.getcountry(i).outline.paths[0].commands[k].startPoint;
- RPoint dp=smap.per(ptrans.form(pnorm.alise(sp)),4);
-
- vertex(dp.x+(getWidth()/2),dp.y+(getHeight()/2)); //,z); //z);
- }
- endShape();
- //println("drawing "+calls.getcountry(i).name+": "+calls.getcountry(i).outline.paths[0].commands.length+" points");
- }
+
+ //for (int i=0;i<calls.countries.size();i++) {
+
-
- if (true) {
- for (int j=0;j<calls.countries.get(i).calls*.001;j++) {
- RPoint s=calls.countries.get(i).getpoint();
- RPoint e=Ireland.getpoint();
- if (s.x>0&&e.x>0){ //point found
- RPoint sp=ptrans.form(pnorm.alise(s));
- RPoint ep=ptrans.form(pnorm.alise(e));
- RPoint Sp=smap.per(sp,4);
- RPoint Ep=smap.per(ep,4);
- RPoint Mp=smap.per(GCircFract(sp,ep,0.8),4.1);
- beginShape();
- line(Sp.x+(getWidth()/2),Sp.y+(getHeight()/2),Mp.x+(getWidth()/2),Mp.y+(getHeight()/2));
- line(Mp.x+(getWidth()/2),Mp.y+(getHeight()/2),Ep.x+(getWidth()/2),Ep.y+(getHeight()/2));
- endShape();
- }
- }
- //println("plotting "+calls.countries.get(i).name+": "+calls.countries.get(i).calls+" calls");
- }
+ //draw outlines
+
+
+ //stroke(255);
+ beginShape();
+ for (int k=0;k<calls.getcountry(i).outline.paths[0].commands.length;k++) {
+ RPoint sp=pnorm.alise(calls.getcountry(i).outline.paths[0].commands[k].startPoint);
+ RPoint dp=shpmap.map(sp.x,sp.y,1);
- }
- else //draw 2D
- {
- if (true) { //draw countries
- beginShape();
- for (int k=0;k<calls.getcountry(i).outline.paths[0].commands.length;k++) {
- RPoint sp=calls.getcountry(i).outline.paths[0].commands[k].startPoint;
- RPoint dp=screenMapper(pnorm.alise(sp));
+ vertex(dp.x+(getWidth()/2),dp.y+(getHeight()/2)); //,z); //z);
+ }
+ endShape();
+ //i++;
+
+ //OR
+
+
+
+
+ //pick a random colour
+ //stroke(random(100)+100, random(100)+100,random(100)+100);
+ //for (int j=0;j<calls.countries.get(i).calls;j++) {
+ RPoint sp=pnorm.alise(calls.countries.get(i).getpoint(100));
+ RPoint ep=pnorm.alise(Ireland.getpoint(100));
+ if (sp.x>0&&ep.x>0){ //point found
+ RPoint Sp=shpmap.map(sp.x,sp.y,1);
+ RPoint Ep=shpmap.map(ep.x,ep.y,1);
+
+ //find point along path
- vertex(dp.x,dp.y); //,z); //z);
+ float f=0.8; //fraction along path;
+ float d=acos(sin(sp.y)*sin(ep.y)+cos(sp.y)*cos(ep.y)*cos(sp.x-ep.x));
+ float A=sin((1-f)*d)/sin(d);
+ float B=sin(f*d)/sin(d);
+ float x = A*cos(sp.y)*cos(sp.x) + B*cos(ep.y)*cos(ep.x);
+ float y = A*cos(sp.y)*sin(sp.x) + B*cos(ep.y)*sin(ep.x);
+ float z = A*sin(sp.y) + B*sin(ep.y);
+ RPoint mp=new RPoint(atan2(y,x),atan2(z,sqrt(pow(x,2)+pow(y,2))));
+
+ RPoint Mp=shpmap.map(mp.x,mp.y,1.04);
+ RPoint B1=shpmap.map(sp.x,sp.y,1.04);
+ RPoint B2=shpmap.map(ep.x,ep.y,1.04);
+ beginShape();
+ //line(Sp.x+(getWidth()/2),Sp.y+(getHeight()/2),Mp.x+(getWidth()/2),Mp.y+(getHeight()/2));
+ //line(Mp.x+(getWidth()/2),Mp.y+(getHeight()/2),Ep.x+(getWidth()/2),Ep.y+(getHeight()/2));
+ vertex(Sp.x+(getWidth()/2),Sp.y+(getHeight()/2));
+ bezierVertex(Sp.x+(getWidth()/2),Sp.y+(getHeight()/2),B1.x+(getWidth()/2),B1.y+(getHeight()/2),Mp.x+(getWidth()/2),Mp.y+(getHeight()/2));
+ bezierVertex(B2.x+(getWidth()/2),B2.y+(getHeight()/2),Ep.x+(getWidth()/2),Ep.y+(getHeight()/2),Ep.x+(getWidth()/2),Ep.y+(getHeight()/2));
+ endShape();
}
- endShape();
- //println("drawing "+calls.getcountry(i).name+": "+calls.getcountry(i).outline.paths[0].commands.length+" points");
+
+ j=j+1;
+ if (j>(calls.countries.get(i).calls*.01)){
+ i++;
+ stroke(random(200)+50, random(200)+50,random(200)+50);
+ println("plotting "+calls.countries.get(i).name+": "+calls.countries.get(i).calls+" calls");
+ j=0;
}
- if (true) { //draw lines
- for (int j=0;j<log10(calls.countries.get(i).calls)*100;j++) {
- RPoint s=calls.countries.get(i).getpoint();
- RPoint e=Ireland.getpoint();
- if (s.x>0&&e.x>0){ //point found
- RPoint Sp=screenMapper(pnorm.alise(s));
- RPoint Ep=screenMapper(pnorm.alise(e));
- RPoint Mp=plerp(Sp,Ep,0.75);
- beginShape();
- //line(Sp.x+(getWidth()/2),Sp.y+(getHeight()/2),Mp.x+(getWidth()/2),Mp.y+(getHeight()/2));
- //line(Mp.x+(getWidth()/2),Mp.y+(getHeight()/2),Ep.x+(getWidth()/2),Ep.y+(getHeight()/2));
- bezier(Sp.x, Sp.y, Sp.x, Sp.y-((getHeight()-Sp.y)*.1), Ep.x, Ep.y-((getHeight()-Ep.y)*.1), Ep.x, Ep.y);
- endShape();
- }
- }
- //println("plotting "+calls.countries.get(i).name+": "+calls.countries.get(i).calls+" calls");
- }
- }
-
-
- i++;
+
+
//}
if (i==calls.countries.size()-1) {
- println("finished");
- noLoop();
- if (mode=="PDF") exit();
+ println("finished");
+ noLoop();
+ if (mode=="PDF") exit();
}
+
}
void mousePressed() {