Sure.
Here the Method which returns the List of pairs of vertices which are 'nearby'.
Note: This only works when the corridor width is around 1500mm (which is design standard in my firm). For larger width, we can vary the 'tolerance' variable. Also, the length of a single branch/ junction is not less than 2550mm. Otherwise it'll return additional pairs. Which is more or less fine as the center points of those pairs will also lie on the Medial Axis (corridor centerline)
public List<List<XYZ>> ReturnVertexPairs (Room corridorRoom)
{
SpatialElementBoundaryOptions opt = new SpatialElementBoundaryOptions
{
SpatialElementBoundaryLocation =
SpatialElementBoundaryLocation.Finish
};
IList<IList<BoundarySegment>> loops = corridorRoom.GetBoundarySegments(opt);
List<XYZ> roomVertices = new List<XYZ>(); //List of all room vertices
foreach (IList<BoundarySegment> loop in loops)
{
//TaskDialog.Show("Revit", "Total Segments = " + loop.Count().ToString());
XYZ p0 = null; //previous segment start point
XYZ p = null; // segment start point
XYZ q = null; // segment end point
foreach (BoundarySegment seg in loop)
{
q = seg.GetCurve().GetEndPoint(1);
if (p == null)
{
roomVertices.Add(seg.GetCurve().GetEndPoint(0));
p = seg.GetCurve().GetEndPoint(0);
p0 = p;
continue;
}
p = seg.GetCurve().GetEndPoint(0);
if (p != null && p0 != null)
{
if (AreCollinear(p0, p, q))//skipping the segments that are collinear
{
p0 = p;
continue;
}
else
{
roomVertices.Add(p);
}
}
p0 = p;
}
}
double tolerance = 2550; //Distance between two Points (in mm) should be less than this number
List<List<XYZ>> nearbyPairs = new List<List<XYZ>>(); //List of Pairs of nearby points
for (int i = 0; i < roomVertices.Count() - 1; i++)
{
for (int j = i + 1; j < roomVertices.Count(); j++)
{
double dist = roomVertices[i].DistanceTo(roomVertices[j]) * 304.8;
if (dist < tolerance) //checking whether two points are nearby based on tolerance
{
nearbyPairs.Add(new List<XYZ> { roomVertices[i], roomVertices[j] });
}
}
}
//TaskDialog.Show("Revit", "Total points = " + roomVertices.Count().ToString()
// + Environment.NewLine + "Total Pairs = " + nearbyPairs.Count());
return nearbyPairs;
}
Helper method to check whether points are collinear (to skip the boundary segments which are colinear)
static bool AreCollinear (XYZ p1, XYZ p2, XYZ p3)
{
bool collinear = false;
double area = 0.5*Math.Abs(p1.X * (p2.Y - p3.Y)
+ p2.X * (p3.Y - p1.Y)
+ p3.X * (p1.Y - p2.Y));
//sometimes area is not exactly zero but is very small number
if (area < 0.1)
{
collinear = true;
}
return collinear;
}