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'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's Boundary
''' </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...

寻找房间中心zz的更多相关文章

  1. 配置中心 Spring Cloud config

    配置管理工具包,让你可以把配置放到远程服务器,集中化管理集群配置,目前支持本地存储.Git以及Subversion. 1.服务端 创建spring boot 项目 主要依赖 <dependenc ...

  2. Hadoop Web项目--Friend Find系统

    项目使用软件:Myeclipse10.0,JDK1.7,Hadoop2.6,MySQL5.6.EasyUI1.3.6.jQuery2.0,Spring4.1.3. Hibernate4.3.1,str ...

  3. PCA and kmeans MATLAB实现

    MATLAB基础知识 l  Imread:  读取图片信息: l  axis:轴缩放:axis([xmin xmax ymin ymax zmin zmax cmin cmax]) 设置 x.y 和  ...

  4. k-means算法初识

    基础知识: K-means聚类算法 聚类,简单地说就是把相似的东西分到一组.同 Classification (分类)不同,对于一个 classifier ,通常需要你告诉它“这个东西被分为某某类”. ...

  5. 单链表的回文判断(O(n)时间复杂度和O(1)的空间复杂度)

    对于单链表来说,判断回文最简单的方法就是遍历链表,将链表中的元素复制到数组中,然后对数组进行判断是否是回文数组,但是这不符合O(1)的空间复杂度. 由于空间复杂度的要求,需要就地操作链表,不能开辟多余 ...

  6. 聚类算法:K-means 算法(k均值算法)

    k-means算法:      第一步:选$K$个初始聚类中心,$z_1(1),z_2(1),\cdots,z_k(1)$,其中括号内的序号为寻找聚类中心的迭代运算的次序号. 聚类中心的向量值可任意设 ...

  7. MLlib 中的聚类和分类

    聚类和分类是机器学习中两个常用的算法,聚类将数据分开为不同的集合,分类对新数据进行类别预测,下面将就两类算法进行介绍. 1. 聚类和分类(1)什么是聚类 聚类( Clustering)指将数据对象分组 ...

  8. opencv2对读书笔记——使用均值漂移算法查找物体

    一些小概念 1.反投影直方图的结果是一个概率映射,体现了已知图像内容出如今图像中特定位置的概率. 2.概率映射能够找到最初的位置,从最初的位置開始而且迭代移动,便能够找到精确的位置,这就是均值漂移算法 ...

  9. Spark:聚类算法

    Spark:聚类算法 Kmeans聚类 KMeans算法的基本思想是初始随机给定K个簇中心,按照最邻近原则把待分类样本点分到各个簇.然后按平均法重新计算各个簇的质心,从而确定新的簇心.一直迭代,直到簇 ...

随机推荐

  1. 数对的个数(cogs610)

    Description出题是一件痛苦的事情!题目看多了也有审美疲劳,于是我舍弃了大家所熟悉的A+B Problem,改用A-B了哈哈! 好吧,题目是这样的:给出一串数以及一个数字C,要求计算出所有A- ...

  2. VAssistX的VA Snippet Editor的类注释和函数注释

    title:类注释shortcut:=== /******************************************************** [DateTime]:$YEAR$.$M ...

  3. PullToRefreshScrollView嵌套SwipeMenuListView冲突问题解决

    参考: http://blog.csdn.net/u012255016/article/details/46048797 public class NoScrollSwipeMenuListView ...

  4. 20145206邹京儒《Java程序设计》第6周学习总结

    20145206 <Java程序设计>第6周学习总结 教材学习内容总结 第十章 输入/输出 Java将输入/输出抽象化为串流,数据有来源及目的地,衔接两者的是串流对象. 从应用程序角度来看 ...

  5. elk深度解析

    上面的两张图是elk的一个架构 下面是对logstash分析:如下图 可以看出 logstash的一个角色shipper,(是通过配置文件来决定logstash是shipper还是indexer)注意 ...

  6. (转)ORA-12519: TNS:no appropriate service handler found 的问题处理。

    很多时候出现:ORA-12519: TNS:no appropriate service handler found 都是由于当前的连接数已经超出他能够处理的最大值了. 处理方法如下:摘自网上. se ...

  7. MSMQ创建消息队列出现“工作组安装计算机不支持该操作”

    [sceislqzw]:你在创建公有队列,而你的机器不属于任何域.一般工作组安装的计算机只能创建私有队列. System.Messaging.MessageQueue QueueReceive = n ...

  8. Power BI for Office 365介绍

    微软在七月份发布了一个新产品,它建立在微软的云的第一个数据平台- Power BI for Office 365.Satya Nadella,服务器和工具业务总裁,在当天的上午在微软的年度全球合作伙伴 ...

  9. 在 Android Studio中恢复已经被移除的Module

    假设名为app的Module已经被移除,则他的图标上小手机图标将会消失.此时如下图编辑settings.gradle,然后点击如图按钮Sync Project with Gradle Files即可. ...

  10. nexus私有仓库搭建

    步骤: 下载安装JDK(注意可用版本) .查看CentOS自带JDK是否已安装,输入: yum list installed |grep java 一般来说,如果是新装CentOS系统的话,不会有JD ...