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.
Page Index Toggle Pages: 1
Graphs... (Read 1086 times)
Graphs...
Sep 19th, 2005, 11:43pm
 
Hi!
I'm up to make a little applet with processing, which displays some graph-stuff.. Its just about 10 Points.

At the moment, I have a matrix, where the Point-Connections are stored.. (like "arr[][]={{2,5}, {4,6}, {10},...")
Then the Script will generate Random numbers for the x and y Axis.

Everything works fine, but I dont like the unclearly way how it is displayed..

So I thought about arranging all the dots in an ellipse, but thats not what im going for...

My Question:
Would it be possible to arrange the 10 Dots, so that no (or less) lines are crossing each other?
Are there any example scripts for something like this available? Are there other better/easier possibilities to display the dots?


Heres my current Source-Code (I know, its a bit stupid - but that was the first time for me working with processing and i wanted to have a clear look):

Code:
int arrPos[][] = {{2,5}, {4,6}, {10}, {6,9,10}, {}, {7}, {}, {9}, {}, {}};

size(250, 250);
background(255);
int pntx[] = new int[10];
int pnty[] = new int[10];
int rndR = 200;
long tempX;
long tempY;

//##### 10 Points, Random X,Y;
// RANDOM 10 X, Y:
for (int i =0; i < 10; i++){
tempX = Math.round(rndR * Math.random());
tempY = Math.round(rndR * Math.random());
pntx[i] = toInt(tempX);
pnty[i] = toInt(tempY);
}

// DISPLAY POINTS:
beginShape(POINT);
for (int i =0; i < 10; i++){
vertex (pntx[i], pnty[i]);
} endShape();
//---------- ---------- ----------

//##### ellipse:
for (int i =0; i < 10; i++){
fill(180);
ellipse(pntx[i], pnty[i], 10, 10);
}

//##### LINES #####
for (int i =0; i < arrPos.length ; i++){
for(int x =0; x < arrPos[i].length ; x++){
line(pntx[i], pnty[i], pntx[arrPos[i][x] - 1], pnty[arrPos[i][x] - 1]);
}
}

// DISPLAY TEXT:
for (int i =0; i < 10; i++){
fill(255,0,255);
PFont eur = loadFont("sansserif-12.vlw");
textFont(eur);
text(i + 1, pntx[i], pnty[i]);
}


Thank you very much!
And sorry for my bad english Wink
Re: Graphs...
Reply #1 - Sep 20th, 2005, 12:56am
 
You might want to google 'convex hulls'. I've made an experiment on hulls with flash, it might be useful for you: http://www.arkitus.com/?id=1
Re: Graphs...
Reply #2 - Sep 20th, 2005, 1:20am
 
Very nice examples on your Homepage.
Thanks for sharing the Sourcecode.
I dont understand too mutch about ActionScript, but i will have a look on it Wink .

Found stuff like this via google:
http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html

This seems to be about connecting the extreme points, but how can I arrange points for displaying them clearly?
I mean, the lines/connections are given in my Script (see the first array), so i cant influence this...

Is this also possibly with the "convex hull" algorithm?
But i would have to turn yours up site down - right? Wink

Thanks,
fish
Re: Graphs...
Reply #3 - Sep 20th, 2005, 2:34pm
 
I'm not sure if this will work or not, but its worth a try.

If you take a look at the Graham's Scan algorithm for Convex Hulls, you will notice that it too starts with an array of points that are in no particular order. It then sorts the points so that they create 'no crossing lines', and then it removes the points that are not maxima from the array.

I think you should be able to skip that last part, so are you left with an array of points that if you draw a line from one to the next, the lines won't cross each other.
Re: Graphs...
Reply #4 - Sep 20th, 2005, 3:00pm
 
is this array about the line-connections or about the point-coordinates?
I will have a closer look on it .
thanks for your reply Cheesy
Re: Graphs...
Reply #5 - Sep 20th, 2005, 7:09pm
 
Basically the points coordinates stay the same, but the order in which they are placed in the array changes so that they form a polygon.
Page Index Toggle Pages: 1