+ Reply to Thread
Results 1 to 7 of 7

Thread: [rhino python] precision problem in using AddSrfContourCrvs

  1. #1

    [rhino python] precision problem in using AddSrfContourCrvs

    Hi,

    I am working on the script, which generates orthogonal grids based on a given surface.
    The script simply finds the bounding box points of the surface, generates base grid points from them and makes contouring lines based on the base grid points with world ZX or YZ plane.



    My problem here is that the results of the script are unpredictable because the script frequently misses the first or the last contouring lines. It seems that the position or domain ranges of the given surface matters.

    How can I make sure that the script always includes both ends using AddSrfContourCrvs?

    In advance, thank for your help!







    Code:
    import rhinoscriptsyntax as rs
    
    def contourPointsPlane(srf, pts, plane=rs.WorldYZPlane()):
    
    "returns the list of the crvs list, divided by grid points"
        listCrvs = list()
        for i in range(0, len(pts)):
            tempPlane = rs.MovePlane(plane, pts[i])
    
            tempCrvs = [rs.AddSrfContourCrvs( srf, tempPlane)]
    
            listCrvs.extend ( tempCrvs )
    
        return  listCrvs 
    
    def getIntervalPts(startPt, endPt, num):
    
    "returns the list of dividing points"
        vecDir = rs.VectorUnitize(rs.VectorCreate( endPt ,startPt ) )
    
        dblDist = rs.Distance(endPt, startPt)
    
        distance = dblDist/num
    
        maxIndex = dblDist / distance
    
    vecDir = rs.VectorScale(vecDir, distance )
        ptList = [startPt] #assign the start point to the first 
    
        for i in range( 1, int(maxIndex)):
    
            ptList.append( rs.PointAdd( ptList[i-1], vecDir ) )
    
        ptList.append(endPt) #assign the end point to the last 
    
    return ptList
    
    if __name__== "__main__":
    
    srf = rs.GetObject("select the surface")
    
    bBox = rs.BoundingBox(srf)
        ptsX = getIntervalPts(bBox[0], bBox[1], 10) 
    
        ptsY = getIntervalPts(bBox[0], bBox[3], 10) 
    
        crvTopXListList = (contourPointsPlane( srf, ptsX, rs.WorldYZPlane() ) )
    
        crvTopYListList = (contourPointsPlane( srf, ptsY, rs.WorldZXPlane()) )
    Attached Files
    Last edited by noclew; 03-20-2012 at 05:11 AM.

  2. #2
    Hi,

    if I understand this correctly, this script can be simplified to this:
    Python Code:
      import rhinoscriptsyntax as rs
       
      if __name__== "__main__":
       
          srf = rs.GetObject("please select the surface")
         
          bBox = rs.BoundingBox(srf)
          crvTopXListList = rs.AddSrfContourCrvs(srf, (bBox[0], bBox[3]), 10.0)
          crvTopYListList = rs.AddSrfContourCrvs(srf, (bBox[1], bBox[4]), 10.0)

    Does this help?
    Please have a look at the documentation of the AddSrfCountourCrvs funcion to see the two ways to call it. In reality, also the other longer method should have in theory worked. I do not know, though, if it was an error in the longer script or in the command itself.
    Thanks,
    - Giulio
    _________________
    giulio@mcneel.com
    Attached Files

  3. #3
    Thx a lot Giulio!!
    now I have someone to ask! :]
    I think I need to learn how to write simple...

    I simplified my nasty code and uploaded it so that you can see it. My initial intention was to make a script that generates contour lines in two ways; the first way is to make contour lines with specified 'distance', just as you mentioned, which is like "rs.AddSrfContourCrvs ( srf, (Start_point, End_point), distance)." And the other way should contour a given surface with a user-specified 'number' of contour lines. (for example, if user input 10, the second way should make 10*10 grid no matter how big the given surface is.)

    Anyway, I tested your script, which performs in the first way, but it has the same errors. This is what I tested;




    I made a square surface which is 100*100 inch and copied it to several random positions. When I run the script, it works on the one at the (0,0,0) position, but didn't work on the other 4 surfaces. As you can see in the capture img, it misses either one or two contour lines at the end position of the surface. I think it can be a Double-Precision, but I am not sure...

    Could you please let me know how to fix this problem?
    Attached Images
    Attached Files
    Last edited by noclew; 03-22-2012 at 12:56 AM.

  4. #4
    Hi Woong,
    I am at an event so it will be difficult for me to further look into this. I've asked if somebody else can try to help you further.

    Please note that there is an underlying ambiguity between the bounding-box and the geometry that is being contoured, so it might be that this is the correct behavior. One thing you might consider is always shrinking the line so that you do not start at the very corner of the bounded geometry.

    Thanks,
    - Giulio
    ________________
    giulio@mcneel.com

  5. #5

    Thx!

    Hi, Giulio
    Thank you a lot!
    you comments are always of big help.
    I will try to figure out!

    I hope your event goes well!

  6. #6
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,463
    Blog Entries
    19
    I just wanted to let you know that I am still looking into this. You aren't being ignored
    Thanks,
    -Steve

  7. #7
    Sure Steve,
    I am really appreciate it.
    Thanks for the kind reply!
    I will also try to figure out the way that works!

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts