Forgot password?

Create an account!

Forum

« back

RhinoScript – distances points

Messages

Please log in to write a message.

  • 3. pradeep (Apr 06, 2011 12.01):

    Kindly send me the script of finding maximum and minimum poits on the curve

  • 2. Hanno (Feb 11, 2010 19.18):

    Hi moodo,

    I did not look at the script, but from what you describe:
    You have two sets of points and want to check for each point in set A if it is closer to any point in set B than a certain distance. If so, you want to delete the point. Right?

    There is a function called pointarrayclosestpoint. You simply have to loop through your set A, and for each point find the closest point of set B using this function, measure the distance, and if too small, delete the point.

    Hope that helps!

    Hanno

  • 1. moodo (Feb 09, 2010 11.07):

    Hello All,

    I have some problems with the following script.
    the script generates (if layer =1), a polysurface,surface and curve. On the curve there will be placed some points with an equal distances between. On the surface there will be placed some random points. This is no problem, but the next step is to find the distance between the edgepoints(each) and all the surfacepoints
    and if the distance<150 then delete the surfacepoint. how can I write this?
    Im completely stuck


    thank you!
    gr.
    moodo

    Option Explicit
    'Script written by <dominicus>
    'Script copyrighted by <>
    'Script version maandag 8 februari 2010 17:49:30

    Call Main()
    Sub Main()
            Dim amount_planes,arrpoint1,arrpoint2,arrpoint3,arrpoint4,curveA
            Dim curveB,polysurface,polysurface_moved,surface_points,path,surface_points2
            Dim edgepoints,edgepoints_bottom,edgepoints_top,intnumbers,srfpoints
            Dim closestpoint
           
            amount_planes=Rhino.GetReal ("how many layers",2 , 1 , 2)
            If amount_planes = 1 Then
                    arrpoint1=Array(0,0,0)
                    arrpoint2=Array(1000,0,0)
                    arrpoint3=Array(1000,1000,0)
                    arrpoint4=Array(0,1000,0)
                    CurveA=Rhino.AddCurve (Array(arrpoint1,arrpoint2,arrpoint3,arrpoint4,arrpoint1),1)
                   
                    path=Rhino.addline(Array(0,0,0),Array(0,0,100))
                    surface_points=Rhino.AddPlanarSrf (Array(CurveA))
                    polysurface=Rhino.ExtrudeSurface (surface_points(0), path)
                    polysurface_moved=Rhino.MoveObject (polysurface, Array(0,0,0), Array(0,0,-50))
                   
                    edgepoints=curvepoints(CurveA,150)
                    intnumbers=Rhino.getinteger("how many points", 25,10,50)
                    srfpoints=surfacepoints(intnumbers,surface_points(0))
                    closestpoint=checkclosestpoint(edgepoints,srfpoints)

            End If
            If amount_planes = 2 Then
                    arrpoint1=Array(0,0,0)
                    arrpoint2=Array(1000,0,0)
                    arrpoint3=Array(1000,1000,0)
                    arrpoint4=Array(0,1000,0)
                    CurveA=Rhino.AddCurve (Array(arrpoint1,arrpoint2,arrpoint3,arrpoint4,arrpoint1),1)     
                    CurveB=Rhino.CopyObject (curveA , Array(0,0,0) ,Array(0,0,100))
                   
                    path=Rhino.AddLine(Array(0,0,0),Array(0,0,200))
                    surface_points=Rhino.addplanarsrf(Array(curveA))
                    surface_points2=Rhino.addplanarsrf(Array(curveB))
                    polysurface=Rhino.extrudeSurface(surface_points(0),path)
                    polysurface_moved=Rhino.MoveObject (polysurface, Array(0,0,0), Array(0,0,-50))
                   
                    edgepoints_bottom=curvepoints(CurveA,150)
                    edgepoints_top=curvepoints(CurveB,150)
                   
            End If
           
    End Sub
    Function curvepoints(curve,distance)
            Dim arrpoints,i,point,edgepoints2(),edgepoints
            arrpoints=Rhino.dividecurveequidistant(curve,distance)
            For i=0 To UBound(arrpoints)
                    point=Rhino.AddPoint(arrpoints(i))
                    ReDim Preserve edgepoints2(i)
                    edgepoints2(i)=point
            Next
            curvepoints=edgepoints2
    End Function
    Function surfacepoints(points,surface)
            Dim xmax,xmin,ymax,ymin,zmax,zmin,i
            Dim arrpoints,points2,points_temp()
            xmax=1000
            xmin=0
            ymax=1000
            ymin=0
            zmax=0
            zmin=0
           
            ReDim arrpoints(points)
            For i=LBound(arrpoints) To UBound(arrpoints)
                    Dim x:x=((xmax-xmin+1)*Rnd+1)
                    Dim y:y=((ymax-ymin+1)*Rnd+1)
                    Dim z:z=0
                    arrpoints(i)=Array(x,y,z)
                    If Rhino.IsPointOnSurface(surface,arrpoints(i)) Then
                            points2=Rhino.addpoint(arrpoints(i))
                            ReDim Preserve points_temp(i)
                            points_temp(i)=points2
                    End If
            Next
            surfacepoints=points_temp
    End Function
    'calculate the distances between the points on the curve and the
    'point on the surface. If distance<150 then delete the surfacepoint
    Function checkclosestpoint(epoints,spoints)
            Dim i,delete,distancex,arrpttest(),arrpttest2(),j
            Dim dbldistclosest
            Dim pointsToDelete(spoints)
            dbldistclosest=99999999999
           
            For i=0 To UBound(epoints)
                    ReDim Preserve arrpttest(i)
                    arrpttest(i)=Rhino.PointCoordinates(epoints(i))
                   
                    For j=0 To UBound(spoints)
                            ReDim Preserve arrpttest2(j)
                            arrpttest2(j)=Rhino.pointcoordinates(spoints(j))
                            'calculate the distance epoints(edgepoints) and spoints(surfacepoints)
                            'if distance < 150 delete surfacepoint
                           
                           
                            distancex=Rhino.distance(arrpttest(i),arrpttest2(j))
                            If distancex<150 Then
                                    'delete=        rhino.deleteobject(spoints(j))
                                    numberOfPointsToDelete = numberOfPointsToDelete + 1
                                    poinsToDelete(numberOfPointsToDelete) = j
                                    'i=i+1
                            End If
                    Next
            Next
           
            For i = 0 To NUmberOfPointsToDelete
                    delete = Rhino.DeleteObjects(spoints(pointstodelete(i)))
            Next
            Next
    End Function
Recommend

Why are these buttons gray?