寻找房间中心zz
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的更多相关文章
- 配置中心 Spring Cloud config
配置管理工具包,让你可以把配置放到远程服务器,集中化管理集群配置,目前支持本地存储.Git以及Subversion. 1.服务端 创建spring boot 项目 主要依赖 <dependenc ...
- Hadoop Web项目--Friend Find系统
项目使用软件:Myeclipse10.0,JDK1.7,Hadoop2.6,MySQL5.6.EasyUI1.3.6.jQuery2.0,Spring4.1.3. Hibernate4.3.1,str ...
- PCA and kmeans MATLAB实现
MATLAB基础知识 l Imread: 读取图片信息: l axis:轴缩放:axis([xmin xmax ymin ymax zmin zmax cmin cmax]) 设置 x.y 和 ...
- k-means算法初识
基础知识: K-means聚类算法 聚类,简单地说就是把相似的东西分到一组.同 Classification (分类)不同,对于一个 classifier ,通常需要你告诉它“这个东西被分为某某类”. ...
- 单链表的回文判断(O(n)时间复杂度和O(1)的空间复杂度)
对于单链表来说,判断回文最简单的方法就是遍历链表,将链表中的元素复制到数组中,然后对数组进行判断是否是回文数组,但是这不符合O(1)的空间复杂度. 由于空间复杂度的要求,需要就地操作链表,不能开辟多余 ...
- 聚类算法:K-means 算法(k均值算法)
k-means算法: 第一步:选$K$个初始聚类中心,$z_1(1),z_2(1),\cdots,z_k(1)$,其中括号内的序号为寻找聚类中心的迭代运算的次序号. 聚类中心的向量值可任意设 ...
- MLlib 中的聚类和分类
聚类和分类是机器学习中两个常用的算法,聚类将数据分开为不同的集合,分类对新数据进行类别预测,下面将就两类算法进行介绍. 1. 聚类和分类(1)什么是聚类 聚类( Clustering)指将数据对象分组 ...
- opencv2对读书笔记——使用均值漂移算法查找物体
一些小概念 1.反投影直方图的结果是一个概率映射,体现了已知图像内容出如今图像中特定位置的概率. 2.概率映射能够找到最初的位置,从最初的位置開始而且迭代移动,便能够找到精确的位置,这就是均值漂移算法 ...
- Spark:聚类算法
Spark:聚类算法 Kmeans聚类 KMeans算法的基本思想是初始随机给定K个簇中心,按照最邻近原则把待分类样本点分到各个簇.然后按平均法重新计算各个簇的质心,从而确定新的簇心.一直迭代,直到簇 ...
随机推荐
- Oulipo(poj 3461)
题意:求b这个字符串在a中出现的次数 这里不用KMP,用hash #include<cstdio> #include<iostream> #include<cstring ...
- React Native实例之房产搜索APP
React Native 开发越来越火了,web app也是未来的潮流, 现在react native已经可以完成一些最基本的功能. 通过开发一些简单的应用, 可以更加熟练的掌握 RN 的知识. 在学 ...
- 使用drozer连接时提示:Could not find java. Please ensure that it is installed and on your path
在安装drozer后使用 drozer.bat console connect命令提示如下错误(实际上我已经安装了jdk并添加了path) 参考上面的链接已经它的提示解决方法如下: 建立名为 .dro ...
- VS2012/2013 停止调试后,无法刷新页面
- Faster-rnnlm代码分析2 - HSTree的构造
也就是构造一棵Huffman Tree,输入是按照词汇频次由高到低排序的 采用层次SoftMax的做法,是为了使得训练和预测时候的softmax输出加速,原有multinomal softmax,是和 ...
- android 5.1 WIFI图标上的感叹号及其解决办法
转自:http://blog.csdn.net/w6980112/article/details/45843129 第一次调试android5.1的 WIFI更改小功能 Wifi 源码的相关路径目录 ...
- SQL Server排序规则
在使用数据库的过程中,总会碰到一些特别的需求.有时候需要储存中文字符,区分大小写或者按照中文的比划顺序排序.这就涉及到了对数据库排列规则的选择. 我们一般可以选择数据库名称-->右键属性(Pro ...
- font-face使用备忘
@font-face { font-family: 'SingleMalta'; src: url('./font/SingleMalta.ttf'); } @font-face { font-fam ...
- JetBrains发布了IntelliJ IDEA 2016.1
JetBrains日前发布了IntelliJ IDEA 2016.1,即他们最受欢迎的IDE的最新版本.这个新版本应该是考虑了多语言开发者的需求,其在许多语言和技术都有很多的增强:然而最惹人注目的变化 ...
- 数据结构之图 Part2 - 2
邻接表 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ...