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
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
)
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.