how to get area of room

This topic has been viewed 7399 times and has 12 replies
Thread status: Active
Questions about extending features and developing plug-ins [img]http://www.sweethome3d.com/images/flags/en_small.gif[/img]
bandara
Posts: 13
Joined: Sat Dec 26, 2009 6:40 am

how to get area of room

Post by bandara »

Hi I saw this topic in earlier too, but our experts answer was get a tape and measure :)

But i really need to get the area of room to call in my plugin.
I know there is a method getArea() in Room class, but it got constructor of float [][].
i.e. Room(float[][] points)

I dont know what value should i pass into this, when create Room object before calling getArea()

Room r =new Room(s1);
float area=r.getArea();

What i should pass to s1.

Funny thing is, when we draw room, it shows area inside it, but i cant get it to my plugin. :)
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: how to get area of room

Post by Puybaret »

No need to create a new subject.
If you're a student and want to become a serious developer, you must learn how to use an API from its documentation or its source code when available.
The Javadoc of the Room class says its constructor takes an array of coordinates as parameter, it also proposes methods to modify the coordinates of a room.
If you don't know how to interpret the documentation of a method or a constructor, you can take profit of working with an open source program and search in its source code how it's used (for example at line 2033 of the PlanController class). If you don't know how to search in the code, learn Eclipse search menu items, it will save you hours of work.

Finally, from the source code you proposed, I repeat: "since when a line has an area?".
In case you didn't get it, this was a clue to help you fix your program.
Emmanuel Puybaret, Sweet Home 3D creator
bandara
Posts: 13
Joined: Sat Dec 26, 2009 6:40 am

Re: how to get area of room

Post by bandara »

I got ur point, to get a area we need more than 3 points.

But i need to get the area of room which i draw in sweethome3D.
I still couldnt get that area.
Can you please give a code to get the area of room. Please sir, with out that room area i can't continue my project.
bandara
Posts: 13
Joined: Sat Dec 26, 2009 6:40 am

Re: how to get area of room

Post by bandara »

float s1[][] = { { 0, 0 }, { 0, 4 }, { 4, 0 }, { 4, 4 } };
Room newRoom = new Room(s1);
float s2[][] = newRoom.getPoints();
Room r1=new Room(s2);
area=r1.getArea();
JOptionPane.showMessageDialog(null, area);

//this result 8.0 always, for all shapes of rooms (this 8 mean half area calculated from given s1),
But this is not what i need. I need to get the area of room which i draw in sweethome 3d.
If we have to parse values manually, what is the need of having getPoint and getArea method. Please help me in this.
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: how to get area of room

Post by Puybaret »

Room#getArea does work correctly.
float s1[][] = { { 0, 0 }, { 0, 4 }, { 4, 0 }, { 4, 4 } };
This shape has actually an area of 8.
float s1[][] = { { 0, 0 }, { 0, 4 }, { 4, 4 }, { 4, 0 } };
This square shape has an area of 16.
Emmanuel Puybaret, Sweet Home 3D creator
bandara
Posts: 13
Joined: Sat Dec 26, 2009 6:40 am

Re: how to get area of room

Post by bandara »

yep, tx on that sir,

But this not return the area of room that i draw in sweethome 3D, it return 16 always. Check this image link
http://www.image-share.com/ijpg-768-257.html

Although i draw 127.16 sized room, this return 16 only. I think when creating a object of room, the value we parse through constructor will effect on getArea method.
If so, how can i get that 127.16 (or actual drawn value)
Please sir, help me on this.
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: how to get area of room

Post by Puybaret »

You probably didn't request the area of the displayed room.
By the way that internal values are always expressed in centimeter.
Emmanuel Puybaret, Sweet Home 3D creator
bandara
Posts: 13
Joined: Sat Dec 26, 2009 6:40 am

Re: how to get area of room

Post by bandara »

Sir, do i have to use any actionListners to do it, or is there any other class/object that i have to create, before calling getArea.
I'm confusing, how that real values, come to method when calling it.
I "sout" getPoints using "for" loop, but it returned values which i call when create object of Room (i.e. float s1[][] = { { 0, 0 }, { 0, 4 }, { 4, 4 }, { 4, 0 } };)

So, can you please tell me how can i request the area of the displayed room.
bandara
Posts: 13
Joined: Sat Dec 26, 2009 6:40 am

Re: how to get area of room

Post by bandara »

Sir, can you tell me factory reference class for
getArea() -> to get the area of the room

Because my supervisor told me that, there should be a class which reference the value for Room class.

Thanx.
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: how to get area of room

Post by Puybaret »

Sorry, I don't know what you mean by "factory reference class".
Even Google wouldn't know!!!
Emmanuel Puybaret, Sweet Home 3D creator
Post Reply New Topic

Who is online

Users browsing this forum: No registered users and 2 guests