Surface.TryGetCylinder()'s Cylinder's Center at wrong location

Axis and Radius are correct, but here is an example of TryGetCylinder()'s Cylinder’s Center at an incorrect location.

This also occurs in Rhino 5.

TryGetCylinder.3dm (8.6 KB)

import rhinoscriptsyntax as rs
import scriptcontext as sc

def main():
    idBrep = rs.GetObject("Select surface", rs.filter.surface, preselect=True)
    if idBrep is None: return
    
    face = rs.coercesurface(idBrep)
    
    b, cyl = face.TryGetCylinder(1.e-7)
    if not b: return
    
    s = 'cyl.IsValid'; print s+':',eval(s)
    sc.doc.Objects.AddPoint(cyl.Center)

    srf = cyl.ToRevSurface()
    if srf is not None: sc.doc.Objects.AddSurface(srf)

    sc.doc.Views.Redraw()

if __name__ == '__main__': main()

Thank you,
Steve

Hi Steve,

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 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.

Here is an example:

SampleCsCylinderTest.cs

Hope this helps.

– Dale

Hi Dale,

The issue isn’t concerning the height properties. For the surface I uploaded, the cylinder’s circle’s plane origin is not at the correct location. This image is viewing directly at the circle’s plane with the target surface on the right:

Sigh…got it. This will be fixed in next week’s WIP.

http://mcneel.myjetbrains.com/youtrack/issue/RH-35469