Find room center ZZ

Source: Internet
Author: User

Finding the centroid of a room Boundary

It's been a while since my last post and I'm sure most of you were like... "Where the hell is Don! "... It's OK! I'm still around. I'm ve been busy working on stuff I can't talk about. Don't worry though, I'm not a good secret keeper.
So this post is going to explain something that a bunch of folks have issues with that involves finding the actual centroid of a polygon, or in this case a room element. now let's be careful not to confuse a centroid with a pair of midpoints taken from the furthest X and Y planes... A centroid is more closely described as the center of mass within a polygon.

now this is done by taking a series of 2D points and running some tricky math on them and dividing the points by 6x the area of the polygon. so to make it simple for you guys, I 've taken the liberty of sharing a couple of functions that makes this all possible. the samples here are in revit 2011 format.
first you'll need a function that iterates through the Boundary segments of a room element and builds up a series of 2D points taken from either endpoints of each segment (no need to worry about curved segments since they usually wont effect the centroid too much, or you can add the midpoint of the curve arc to get it closer ).
this little function will return a list of 2D pointf from a boundary of a room element.

''' <Summary> ''' extract a list of 2D points from a room ''' </Summary> ''' <Param name = "p_room"> </param> ''' <remarks> </remarks> private sub extractboundarypointsfromroom (p_room as Room) 'The points list dim m_pts as new list (of pointf) 'the Z height dim m_z as double = 0' work with the boundary dim m_bsaa as Autodesk. revit. DB. architecture. boundarysegmentarrayarray = m_room.boundary 'segment array at floor level for each BSA as Autodesk. revit. DB. architecture. boundarysegmentarray in m_bsaa try for each BS as Autodesk. revit. DB. architecture. boundarysegment in BSA dim M_c as curve = BS. curve 'first endpoint dim m_endpoint1 as XYZ = m_c.endpoint (0) dim m_pointf1 as new pointf (m_endpoint1 (0), m_endpoint1 (1) m_pts.add (m_pointf1) 'Second endpoint dim m_endpoint2 as XYZ = m_c.endpoint (1) dim m_pointf2 as new pointf (m_endpoint2 (0), m_endpoint2 (1) m_pts.add (m_pointf2) the height m_z = m_endpoint1 (2) next catch ex as exception end try next 'Return the 2D centroid dim m_2dcentroid as pointf = findcentroid (m_pts.toarray, m_room.area) 'Add the floor level of boundary for Z elevation insertionpoint = new XYZ (m_2dcentroid.x, m_2dcentroid.y, m_z) end sub

The function below will take a list of points (first gathered from the segments array of a room) and convert them to a real life centroid in 2D format. the Z elevation is pretty easy to figure out for a room and what ever you're using this for is typically going to use 0 or a preset elevation for the result anyway.
''' <Summary> ''' find 2D centroid''' </Summary> ''' <Param name = "PTS"> collection of points describing the polygon </param> ''' <Param name = "p_rmarea"> the area of the polygon </param> ''' <returns> 2D point (pointf) </returns> ''' <remarks> This function kicks ass </remarks> private function findcentroid (byval PTS () as pointf, p_rmarea as Single) as pointf'add the first pt to the end of the array (Full Circulation) redim preserve PTS (PTS. length) PTS (PTS. length-1) = new pointf (PTS (0 ). x, PTS (0 ). y) 'Get the centroid dim X as single = 0 dim y as single = 0 dim m_sf as single 'This is where the magic happens for I as integer = 0 to PTS. length-2 m_sf = PTS (I ). x * PTS (I + 1 ). y-PTS (I + 1 ). x * PTS (I ). Y x + = (PTS (I ). X + PTS (I + 1 ). x) * m_sf y + = (PTS (I ). Y + PTS (I + 1 ). y) * m_sf next I 'divide by 6x the are of the polygon x/= (6 * p_rmarea) y/= (6 * p_rmarea) 'This is the final result return New pointf (x, y) end Function

That's all until next time...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.