Hi there, was just trying the TryGetCylinder method in a VB.Net component in GH and came across an issue where the cylinder doesn’t align with the original. See attached grasshoper script, the code looks like this:
Dim container As Cylinder
A = container
Not sure if this is a grasshopper issue or if perhaps I’m using the wrong tool for the job?
A 2nd question is: why is there no Radius property for Cylinders in RhinoCommon? Do I have to use the CircleAt method and then interrogate the radius? This is quite verbose.
If Surface.TryGetCylinder is successful, it returns an infinite cylinder. This is by design. When a surface has a cylindrical shape, even if its ends are not circles on the cylinder, it returns the axis and radius. That’s what the “portion” means in the function comments.
Note, you can detect infinite cylinders using Cylinder.IsFinite in the Rhino WIP, or by verifying that Cylinder.Height1 and Cylinder.Height2 are equal.
If you are trying to reverse engineer a cylinder, then after calling Surface.TryGetCylinder to verify the surface looks like a cylinder, then just calculate a plane-aligned bounding box to obtain the cylinder’s height.
I guess what’s confusing is that in this case, TryGetCylinder correctly returns the heights as 0 & 3.4mm, implying that it is a finite cylinder. The centre point is also exactly half the height further along the axis than the original, implying that it could be aligned properly. Just think it’s strange that if you convert a cylinder to a surface and then back again you don’t end up in the same place you started. Anyway, I’ll give the TryGetFiniteCylinder method a go when I get to a computer with the WIP installed.
Regarding the radius, it would be great if you could add a GetRadius method to the Cylinder structure. I guess the idea is that Cylinder should be as light-weight as possible?