Any way to get the centre point of a rebar set?
Maybe. How do you define the center point on a set of pickup sticks though? Rebar sets need not be perfectly aligned and can diverge if memory serves…
Curve.PointAtParameter 0.5 assuming all curves are uniform.
If not uniform, Curve.PointAtSegmenetLength with a length of 1/2 the curve’s length.
But you have a rebar set so many polycurves, which means many points, which means no easy answer here still…
this node?
That will give you one polycurve for each of your rebar in the set, which can be used to get a single point for each rebar in the rebar set using a Curve.PointAtParameter as noted before. However you still have many points, not one, and I’m not sure how you want to define the ‘center’ of the set.
Hi, using the barycenter of an armature (Volume and L of the polycurve)
then sum for each armature (a track can be)
cordially
christian.stan
Could you get the bounding box of each element in the rebar set and use the average of the centroids?
Ask a silly question… go down a rabbit hole
Arcs and Lines (and Curves) Oh my! do not have bounding boxes, I would guess that is because they can be unbound, i.e. to infinity and beyond.
So if we get all the geometry and calculate all of the centroids of the lines and arcs and then average them out. Lines are easy - just the centre point of the line (assuming they are bound and have a length) however arc segments require a bit of maths
Code as follows:
Note - I am using α as the full arc, not the half arc as shown above
# Dynamo v.2.18.1
def centroid(geom):
geomtype = geom.ToString()
if "Arc" in geomtype:
r = geom.Radius
a = geom.Length / r # Sweep angle
_x = 4 * r * math.sin(a/2) ** 3 / 3 * (a - math.sin(a))
c = geom.Center
mp = geom.ComputeDerivatives(0.5, False).Origin
l = Line.CreateBound(c, mp)
ctr2cent = _x / l.Length
return l.ComputeDerivatives(ctr2cent, False).Origin
elif "Line" in geomtype:
return geom.ComputeDerivatives(0.5, False).Origin
def average_points(points):
number_of_points = len(points)
point = points.pop() #Start point
for next_point in points:
point = point.Add(next_point)
return point.Divide(number_of_points)
selection = UnwrapElement(IN[0])
geom = list(selection.GetFullGeometryForView(doc.ActiveView))
points = [centroid(g) for g in geom]
OUT = average_points(points)