diff options
Diffstat (limited to 'gpsviewer.pde')
| -rw-r--r-- | gpsviewer.pde | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/gpsviewer.pde b/gpsviewer.pde index da614b2..715c79f 100644 --- a/gpsviewer.pde +++ b/gpsviewer.pde @@ -13,7 +13,7 @@ class p3d { p3d max=new p3d(-1000,-1000,-1000); p3d min=new p3d(1000,1000,1000); -float xo,yo,sc; +float xOffset,yOffset,spanDegrees; void addPoint(String[] coord) { p3d p; @@ -31,7 +31,7 @@ void addPoint(String[] coord) { } void setup() { - size(200, 200); + size(512,512); kml = new XMLElement(this, "tim-openpaths.kml").getChild("Document"); //kml = new XMLElement(this, "everytrip-demo.kml").getChild("Document"); int num = kml.getChildCount(); @@ -53,38 +53,33 @@ void setup() { //work out offsets if (max.x-min.x>max.y-min.y) { //scale to X - xo=0; - yo=(height/2)-((height*((max.y-min.y)/(max.x-min.x))*0.5)); - println("ratio: "+str((max.y-min.y)/(max.x-min.x))); + xOffset=0; + yOffset=(height/2)-((height*((max.y-min.y)/(max.x-min.x))*0.5)); // } else { //scale to Y - xo=(width/2)-((width*((max.x-min.x)/(max.y-min.y))*0.5)); + xOffset=(width/2)-((width*((max.x-min.x)/(max.y-min.y))*0.5)); println("ratio: "+str((max.x-min.x)/(max.y-min.y))); - yo=0; + yOffset=0; } - size(512,512); + background(0); stroke(255); } void draw() { - println(str(min.x)+","+str(min.y)+" to "+str(max.x)+","+str(max.y)); - println("offset: "+str(xo)+","+str(yo)); - sc=max(max.x-min.x,max.y-min.y); - if (sc==0.0) println("no movement!"); + spanDegrees=max(max.x-min.x,max.y-min.y); + if (spanDegrees==0.0) println("no movement!"); else { - float psc; //pixels per degree - if (max.x-min.x>max.y-min.y) psc=width/sc; //maximum span of latitude/longitude - else psc=height/sc; - //println("scale: "+str(sc)+" :"+str(width/sc)+" pixels/degree"); + float pixelsPerDegree; + if (max.x-min.x>max.y-min.y) pixelsPerDegree=width/spanDegrees; //maximum span of latitude/longitude + else pixelsPerDegree=height/spanDegrees; for (int i=0;i<points.size()-1;i++) { - float x1=((((p3d)points.get(i)).x-min.x)*psc)+xo; - float y1=((((p3d)points.get(i)).y-min.y)*psc)+yo; - float x2=((((p3d)points.get(i+1)).x-min.x)*psc)+xo; - float y2=((((p3d)points.get(i+1)).y-min.y)*psc)+yo; - //println(str(x1)+","+str(y1)+" to "+str(x2)+","+str(y2)); + float x1=((((p3d)points.get(i)).x-min.x)*pixelsPerDegree)+xOffset; + float y1=(height-((((p3d)points.get(i)).y-min.y)*pixelsPerDegree))-yOffset; + float x2=((((p3d)points.get(i+1)).x-min.x)*pixelsPerDegree)+xOffset; + float y2=(height-((((p3d)points.get(i+1)).y-min.y)*pixelsPerDegree))-yOffset; line(x1,y1,x2,y2); } } |
