Rotate group of plotted points

edited October 2014 in Questions about Code

Hello,

I have a number of .GPX files plotted in a sketch, but for some reason they seem to be rotated 90 degrees so north = the right hand edge of the sketch. Is there a way of rotating the group of points as I can't figure out why they are plotting rotated.

The Code is:

import processing.pdf.*; import tomc.gpx.*; GPX gpx;

String numbers[] = {
  "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21"
}; //For loading files.

float x;
float y;

String stageName;

void setup() {
  size(2480, 2480, PDF, "tdfMountains8.pdf");
  background(30, 39, 40);
  noLoop();
}

void draw() {
  // rotate(radians(0)); //Rotate ploted routes so that North = North
  plotPoints();
  exit();
}


void plotPoints() {

  for (int q = 0; q<= 20; q++) {
    gpx = new GPX(this);
    gpx.parse("stage"+ numbers[q] +".gpx");

    for (int i = 0; i < gpx.getTrackCount(); i++) {
      GPXTrack trk = gpx.getTrack(i);

      for (int j = 0; j < trk.size(); j++) {
        GPXTrackSeg trkseg = trk.getTrackSeg(j);

        for (int k = 0; k < trkseg.size(); k++) {
          GPXPoint pt = trkseg.getPoint(k);

          double correctedLat = pt.lat;
          double correctedLon = pt.lon; 

          x = new Float(correctedLat * (width/50)); 
          y = new Float(correctedLon * (height/50)); 

          println("y= "+y + "/ x= "+x);

          stroke(255);
          strokeWeight(0.7);

          x = map(x, 2050, 2400, -100, (width/2)+100);
          y = map(y, 0, 300, 900, height/1.5);

          point(x, y);
        }
      }


      fill(255, 50, 2, 140);
      text("Stage " + numbers[q], x, y);
    }
  }
}

The output looks like this:

Image and video hosting by TinyPic

Thank you!

Tagged:

Answers

  • Answer ✓

    Lines 41 and 42. You assign lat to x when it should be y. Lat is north /south, x is east/west

Sign In or Register to comment.