I’m kind of scratching my head right now on this problem so that is why I’m putting it out on the forum.

If one has a cylinder modeled (no specific modeling method per say) and it is a solid group or component how would one programmatically determine the radius or diameter of this solid?

Calculating the volume is a no brainer, but since the circular faces could be actual circles or exploded curves it seems to me that it is a bit more tricky trying to figure out the diameter of the cylinder.

I guess if the object has not had its ArcCurve’s exploded the problem is simple enough, but how do I work around this if the ArcCurve no longer exists?

Assuming the segments that were once an arc or circle haven’t been distorted or their lengths changed, then you can find a suspected segment and from its ends its plane, then you can find its mid-point, then strike a line through there on the plane; repeat for another suspected segment, the two lines should intersect. That intersection-point is the center of the former arc or circle…

Guessing. Could you use the area of the intact adjacent plane? A= π r2 right? so devide the plane area by pi and then square root for a radius? I guess the faceted nature of circles will make this slightly inaccurate.

I am finding with the follow me tool that sometimes a circle can be used to create the cylinder however if certain conditions are not met the resulting solid no longer has a circle definition but its edges are all exploded, hence the problem I have described. In other words you can’t guarantee that the curve or arccurve will exist.

Yes, follow me explodes circles, you can re-weld the resulting geometry but it becomes a curve. I feel like there was an extension that could find and re-make true circles including the meta data but I can’t remember it, perhaps I am wishful remembering, @TIG would know better than I.

When faced with this problem I generally draw a line or tape measure between nodes across the center as mentioned, or perpendicular to two segments center if only part of the arc is available. Clunky but it works.

Once one has determined which face constitutes the circle it probably wouldn’t be too hard to determine the number of segments in that face and then a little bit of math can be used to calculate the theoretical diameter (faceted circle).

I think the easiest way to determine the “circular” face would be just to assume that it has six or more edges. All other faces will generally have three or four. I’m sure this isn’t bullet proof but it seems sensible enough.

If the Follow Me geometry is all selected and “Welded” the circles become curves, which do not display radius info but DO display the number of facets in entity info. So after welding, the surface area, and number of segments in the edge are both available.

Each of the circle’s segments represents a chord drawn across the outside of the imaginary true circle.
A line of radius drawn from the center so it bisects the chord creates the adjacent side of a right triangle.
The opposite side of the triangle is formed by the right angle bisecting the chord (i.e., half the length of a segment.)
The hypotenuse of the triangle is one of two lines of radius drawn from the center to each vertex of the chord segment.
The angle between the two radius lines to the segment vertices is the included angle.
The line of radius which bisects the edge segment also bisects the included angle forming the angle AH for the triangle (opposite the half length of the edge chord segment.)

So, simple trigimometry … sin of angle = opposite length / hypotenuse length
We know the angle AH and the opposite length. We must find the hypotenuse length which is the radius.

segment = face.edges.first
num_segs = face.edges.count
included_angle = 360.0 / num_segs
half_included_angle = included_angle / 2.0
opposite_length = segment.length / 2.0
# sin of angle AH = opposite_length / hypotenuse_length
# Math.sin(half_included_angle.degrees) = opposite_length / hypotenuse_length
# Rearrange to:
hypotenuse_length = opposite_length / Math.sin(half_included_angle.degrees)
# The hypotenuse IS the circle radius

EDIT: The Math trig functions want radian arguments.

This was the little bit of math of which I spoke. Trigonometry is sure a useful tool. I suppose one doesn’t even need to bother finding the center of the circle. Maybe this problem is much simpler than I originally thought.

I also just had another potential idea on how to verify that the face is a circle. Since you know the hypotenuse and the number of sides one can easily calculate the area of the polygon and compare it with the actual area of the face. If they agree within a certain tolerance then you know the face is circular or at least a regular polygon representing a circle.

With regards to the API method that calculates the volume of a solid, does it calculate the actual faceted volume or the theoretical volume when you are dealing with arc curves?

Also the same question for the area of a face if the face is a circle/arccurve?

In your first sketchpad image, … h is not a hypotenuse (which might lead to confusion.)
I think you meant it to be the height of the triangle created by the included angle.

It is actually r that is the hypotenuse.

And yes, that sketch is exactly what I described above, i.e., the included angle and it’s bisector creating triangles.