寻找房间中心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个簇中心,按照最邻近原则把待分类样本点分到各个簇.然后按平均法重新计算各个簇的质心,从而确定新的簇心.一直迭代,直到簇 ...
随机推荐
- 多线程编程1 - NSThread
每个iOS应用程序都有个专门用来更新显示UI界面.处理用户的触摸事件的主线程,因此不能将其他太耗时的操作放在主线程中执行,不然会造成主线程堵塞(出现卡机现象),带来极坏的用户体验.一般的解决方案就是将 ...
- XStream xml to bean
<!-- pom.xml --> <dependency> <groupId>com.thoughtworks.xstream</groupId> &l ...
- 第四章 面向对象与IO操作
一.类(类中可以写字段.属性.方法.构造函数)1.定义一个类用关键字class,后面加类名,类名第一个字母用大写,可用private或public修饰符定义访问级别,类可定义在同一命名空间中,也可定义 ...
- Linux定时任务设定
使用crontab 命令进行设定. 详情可参见:http://blog.csdn.net/xiyuan1999/article/details/8160977. 共有6项构成,前5项为时间:分 时 天 ...
- hdu1212(大数取模)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 题意:给出两个数a, b,求a%b: 思路:(c+d)%e=c%e+d%e,(c*d)%e=(c ...
- 【stut 逆置正整数】
C语言实验——逆置正整数 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 输入一个三位正整数,将它反向输出. 输入 3位正整数. ...
- 如何在java中使用别人提供的jar包进行导入,编译,运行
一步一步往前走, 现在折分! JAR包即为上篇文章的东东. 测试JAVA文件. package com.security; import com.security.AESencrp; /** * 实现 ...
- poj 2503:Babelfish(字典树,经典题,字典翻译)
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 30816 Accepted: 13283 Descr ...
- AJax中post与get请求注意事项
在使用ajax提交表单时,一定要区分提交按钮的形式和数据表头的设置,实例如下: GET请求: HTML代码: <!doctype html> <html lang="en& ...
- WebRTC代码走读(十):rtp_rtcp模块分析,webrtcrtp_rtcp
转自:http://www.bkjia.com/Androidjc/1020017.html 1. 对外提供的主要流程接口 收包的调用接口RtpReceiverImpl::Incoming ...