We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Pages: 1 2 
3d points/map (Read 2970 times)
3d points/map
Sep 12th, 2009, 10:49pm
 
Hello experts,

I've been messing around with processing for a little while now, and I'd like to take the next step and do some 3D stuff.  I've got a file with thousands of coordinates (x,y,z) corresponding to a virtual map, and I'd like to be able to plot them in space (and eventual explore them by looking at it from different angles, but first things first).  I suppose it is possible to do this, and I am looking for some assistance on where to start with plotting these in 3d.  Any assistance is greatly appreciated, this forum has been very helfpul in the past.

Thanks!
Re: 3d points/map
Reply #1 - Sep 12th, 2009, 11:20pm
 
Hey,
You're probably going to need loadStrings("yourFile.txt"), String.substring(int firstChar, int lastChar), split(String inputString, char token), and String.parseFloat.
That should get you started.  Sorry, I had just written a full explanation of each command and accidentally drag-selected and deleted the whole dang thing.
--Ben
Re: 3d points/map
Reply #2 - Sep 13th, 2009, 6:50am
 
Quote:
PVector[] Coords;

void loadCoordinates(){
  String[] StrAy = loadStrings("myfile.txt"); // in /data
  Coords = new PVector[StrAy.length];
  for (int i=0;i<StrAy.length;i++){
    // first knock off ( ) marks (assuming 1st + last char)
    StrAy[i]=StrAy[i].substring(1,StrAy[i].length()-1);
    // then split the coordinates apart at the "," characters
    String[] tempAy = split(StrAy[i],',');
    // and plug the coordinates into the PVector array
    Coords[i]=new PVector();
    Coords[i].x = Float.parseFloat(tempAy[0]);
    Coords[i].y = Float.parseFloat(tempAy[1]);
    Coords[i].z = Float.parseFloat(tempAy[2]);
  }
}
Re: 3d points/map
Reply #3 - Sep 13th, 2009, 12:59pm
 
Thanks Ben, that is helpful.  I believe my biggest issue, though, is representing the relative placement of positions in 3D using transform (at least I suspect this will be the difficult part). Any suggestions or pointers?

Thanks again!
Re: 3d points/map
Reply #4 - Sep 13th, 2009, 1:05pm
 
Not sure I understand...why not use point(x,y,z) for all the coordinates?
Re: 3d points/map
Reply #5 - Sep 13th, 2009, 1:46pm
 
if i understand you correctly, you can easily use map() to adjust and place your points correctly in 3d space.

Re: 3d points/map
Reply #6 - Sep 13th, 2009, 10:18pm
 
here's the code that gets me most of the way there. the only drawback is that using points doesn't scale the size of the points in the distance, and it appears that i have too many coordinates (over 5000) to use spheres. this makes it a little difficult to get perspective on the data.  thanks for all you help guys!  

import de.bezier.data.*;
XlsReader reader;
import peasy.*;

PeasyCam cam;

float [] xpos = new float[7000];
float [] ypos = new float [7000];
float [] zpos = new float [7000];

void setup() {
 size(1300, 1000, P3D);
 smooth();

 cam = new PeasyCam(this, 100);
 cam.setMinimumDistance(10);
 cam.setMaximumDistance(200);

 reader = new XlsReader( this, "blah.xls" );

 float xmax = getColMax(6);
 float xmin = getColMin(6);
 float ymax = getColMax(7);
 float ymin = getColMin(7);
 float zmax = getColMax(8);
 float zmin = getColMin(8);

 for (int d = 1; d < reader.getLastRowNum(); d++){
   xpos[d]= map(reader.getFloat(d, 6),xmax,xmin,0,abs(xmax-xmin));
   ypos[d]= map(reader.getFloat(d, 7),ymax,ymin,0,abs(ymax-ymin));
   zpos[d]= map(reader.getFloat(d, 8),zmax,zmin,0,abs(zmax-zmin));
 }
}

void draw() {
 background(0);
 stroke(250,250,25);
 strokeWeight(2);
 point(xpos[0], ypos[0], zpos[0]);

 for (int g = 1; g <5000; g++){
   point(xpos[g], ypos[g], zpos[g]);
 }

 for (int h = 0; h < 100; h++){//draw x axis
   stroke(255,h*5,0);
   point(h,0,0);
 }

 for (int h = 0; h < 100; h++){// draw y axis
   stroke(h*5,255,0);
   point(0,h,0);
 }

 for (int h = 0; h < 100; h++){// draw z axis
   strokeWeight(3);
   stroke(0,255,h*5);
   point(0,0,h);
 }
}
Re: 3d points/map
Reply #7 - Sep 14th, 2009, 2:18am
 
would you upload the xml file somewhere
Re: 3d points/map
Reply #8 - Sep 14th, 2009, 7:39am
 
Cedric,

I'd like to be able to share the actual data with you, but in this case I I can't, at least not now.  Sorry.
Re: 3d points/map
Reply #9 - Sep 14th, 2009, 8:17am
 
maybe just a short excerpt with 30-40 points ? or maybe random ones so i can test it.
Re: 3d points/map
Reply #10 - Sep 14th, 2009, 8:53am
 
Cedric, create an xls (excel) file with 9 columns. put random x coordinates in column 7, y coordinates in column 8, z coordinates in column 9. each row is therefore a set of x.y,z coordinates. save it as blah.xls in your data file.  sorry about not being able to share the data, especially when i get so much help on these forums.
Re: 3d points/map
Reply #11 - Sep 14th, 2009, 10:22am
 
hmm ok. are you sure its not 6 7 8 cause thats what it says in your code. anyway i can not start it. im missing import de.bezier.data.*;
what library is that ?
Re: 3d points/map
Reply #12 - Sep 14th, 2009, 10:27am
 
oh and whats the range of your coordinates in the xls file ?i just put in numbers between 0-9 but could be anything...
Re: 3d points/map
Reply #13 - Sep 14th, 2009, 10:32am
 
you're right, the columns are 6,7,8

the library is xlsreader, http://florianjenett.de/processing/libs/xls/

the range is large, but a sample would be x: -130 to -160, y: 0 to 10 z: 0-10

Re: 3d points/map
Reply #14 - Sep 14th, 2009, 12:06pm
 
hmm still having problems,
now i get the error message :

the fuction getColMax(int) doesnt exist.
the library examples work though
Do i miss something?
Pages: 1 2