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.
IndexDiscussionExhibition › Is this possible in processing
Page Index Toggle Pages: 1
Is this possible in processing (Read 649 times)
Is this possible in processing
Dec 21st, 2008, 3:41am
 
Hello I hope this the right forum to ask this question
I'm a  little familiar with java but quit new on this forum and with the program processing.  I came upon this on a software magazine. I was wondering if the following can be done in processing. I'm looking quit a while now for a program were I can do this. Ofcourse there are programs available but with a very high learning curve and that is what I don't need or want...because it is a pure visualisation of data....

I just tell the "story" and any feedback I would appreciate....
1-The user can create a "livingroom" based on numbers for each "wall" size.  Look at this image to see what I mean
www.tilesoft.nl/ts/1.jpg. Size a, b, c etc. are converted to scaled lines. After this I want the program to do some math and calculate the area within (eg. in m²)....so far the basics.. Or the user import the lines settings from a text file into the program....
2-After this I want to create in the area a pattern based on squares and rectangles (so far I could look into this website this wouldn't be such a problem in processing)
3-After this is done each rectangele and square needs to visualise a image from te harddisk, this image the user point the path to...
4-After this the user must have the option to rotate the patterns with in the area........(harder to do I think...)
The livingroom can be zoomed in or out by the user ........

I really hope this can be done because the program looks very easy to learn.....

Anyhow thank you for responding and best regards

Jim
Re: Is this possible in processing
Reply #1 - Dec 21st, 2008, 4:40am
 
Ah, I remember this type of problem from the first programming course I took.  It's a snap to do it now - people nowadays are so lucky Smiley

Well, the simple answer is yes - the problem is what algorithm you want to apply to it and that is not language specific.  But Processing definitely makes it even easier.

Before it can begin, your first point must be clarified.  

Quote:
1-The user can create a "livingroom" based on numbers for each "wall" size.  Look at this image to see what I mean www.tilesoft.nl/ts/1.jpg. Size a, b, c etc. are converted to scaled lines. After this I want the program to do some math and calculate the area within (eg. in m²)....so far the basics.. Or the user import the lines settings from a text file into the program....


The picture cannot be constructed purely from a set of wall lengths.  Let's say we have a set [a,b,c,d,e,...], one can only infer the order in which these walls are arranged and not the shape, as the angles between the adjacent walls are missing, of which infinite number of arrangements are possible in many cases (unless it's a triangle), so you can't determine the area until that information is clear.


But, I think I can get you started with a quick sketch that can be easily drawn, like this:

Code:


ArrayList walls;
Integer pX, pY;
Wall wallSelect = null;

void setup(){
 size(500,500);
 smooth();

 walls = new ArrayList();
 float[] wl = {
   200, 50, 150, 200, 250, 100   };
 for(int i = 0; i < wl.length; i++){
   walls.add(new Wall(wl[i], 1.0f));
 }

}

void draw(){
 background(130);


 pushMatrix();
 translate(100,100);
 Wall wall = null;

 for(int i = 0; i < walls.size(); i++){
   wall = (Wall)walls.get(i);
   wall.draw();
 }

 popMatrix();
 line(100,100, wall.jointX, wall.jointY);
}


void mouseClicked(){
 evalClick();

}

void evalClick(){
 pX = mouseX;
 pY = mouseY;
 for(int i = 0; i < walls.size(); i++){
   Wall wall = (Wall)walls.get(i);
   if ( wall.evaluateClick(pX, pY)){
     wallSelect = wall;
   }
 }
}

void mouseReleased(){
 wallSelect = null;
}


void mouseDragged(){
 if(wallSelect != null){
   wallSelect.nextAngle = (float)(dist(pX,pY, mouseX, mouseY) / 10);
 }
 else{
   evalClick();
 }
}

class Wall{
 Wall nextWall = null;
 Float wallLength = 0f;
 Float nextAngle = 0f;
 Float jointX = 0f;
 Float jointY = 0f;

 Wall(Float wallLength, Float nextAngle){
   this.wallLength = wallLength;
   this.nextAngle = nextAngle;
 }
 void draw(){
   line(0,0, wallLength, 0);
   translate(wallLength,0);
   fill(130);
   if(this == wallSelect){
     fill(250);
   }
   ellipse(0,0,10,10);
   updateJointPosition(screenX(0,0), screenY(0,0));
   rotate(nextAngle);

 }

 void updateJointPosition(Float x, Float y){
   jointX = x;
   jointY = y;
 }

 Boolean evaluateClick(Integer x, Integer y){
   if(dist(x,y, jointX, jointY) < 30){
     return true;
   }
   return false;
 }


}


(I'll probably be fired on the spot if I present this UI, but I'm covered here because it's just an example Wink )

So, all you need to do is use the polygon library from Java to eval all the points to get the area. So you don't even need to deal with the geometric algorithm! 

Here's the library:

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Polygon.html

Simple combinations of Polygon class and Processing PApplet's screenX/Y/Z will take care of the majority of the problems mentioned above.
Re: Is this possible in processing
Reply #2 - Dec 21st, 2008, 1:04pm
 
Hi sw01
First of all thank you for such a quick reply. It is sunday here and I have the whole day to look and study your answer I come back with some reviews shortly.

Again thank you

Jim

Re: Is this possible in processing
Reply #3 - Dec 21st, 2008, 3:12pm
 
I was reading similar posts recently and polygon may not be the best answer for determination of area. For example:

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1229783040;start=2#2

Has a neat hackish way of determining area.

or,

According to (p. 37, Leen Ammeraal, Computer Graphics for Java Programmers, ISBN 0-471-98142-7):

(pseudocode)
2 Area(P0...Pn-1) = sum(0, n-1, (X[i]*Y[i+1] - Y[i]*X[i+1]))

So you can give these two a shot when implementing your code.
Page Index Toggle Pages: 1