I am working on placing outlets around a room and currently doing it by a certain number of outlets per wall. This works great in most cases but I am running into issues where it reads the room boundary curve as being split, usually be an intersecting wall. I’d like to join the curves that have common start/end points and are in the same direction but can’t determine a way to do this so far. I tried grouping by a key which was the vector direction but then can’t figure out how to combine that with checking common start/end points.
Look at this:
Hello, I tried that node and it just returned the same number of curves so the simplification did not happen for some reason. I tried another method yesterday where I am getting the faces of the room, filtered to the bottom face and go the perimeter curves and this did give me the full wall lines that I was needing. Maybe a work around but is working for my needs so far.
Save lines with Data.Remember node and share the dynamo file. We’ll find out the problem.
Hello,
Please try to use the python code below:
import math
from Autodesk.DesignScript.Geometry import Vector, Line
curves = IN[0]
def _isLine(c):
return math.fabs(c.Length - c.StartPoint.DistanceTo(c.EndPoint)) <= 0.0001
def _isParal(a, b):
v1 = Vector.ByTwoPoints(a.StartPoint, a.EndPoint).Normalized()
v2 = Vector.ByTwoPoints(b.StartPoint, b.EndPoint).Normalized()
return math.fabs(v1.Dot(v2)) >= 0.9999
def _shiftIndices(x, i):
return x[i:] + x[:i]
def simplified(curves):
i = 0
j = 0
len1 = len(curves) - 1
outp = []
isClosed = curves[-1].EndPoint.IsAlmostEqualTo(curves[0].StartPoint)
# Find a corner
if isClosed:
shift = 0
for k in range(len(curves)):
if not _isParal(curves[k - 1], curves[k]):
break
shift -= 1
curves = _shiftIndices(curves, shift)
# Skip initial non-lines
while not _isLine(curves[i]) and i < len1:
outp.append(curves[i])
j += 1
i += 1
# Merge collinear lines
while i < len1:
sP = curves[i].StartPoint
eP = None
while _isLine(curves[i + 1]) and _isParal(curves[i], curves[i + 1]):
eP = curves[i + 1].EndPoint
i += 1
if eP is None:
outp.append(curves[i])
else:
outp.append(Line.ByStartPointEndPoint(sP, eP))
i += 1
j += 1
if i == len1:
outp.append(curves[-1])
return outp
OUT = curves
Hi @Cezmi you could try polycurve simplify from sparrrow or some simplify nodes from synthezise could probably work as well
2 Likes
Hi @sovitek,
Sure that works too.
1 Like