Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
General coding help
#1
Hello everyone,
I am going through the following piece if code :
Inputs:
initP: Starting point
dir: vector in the UV directions
L: desired length between the points
bSrf: the surface the points are mapped to
UVi: Optional, may be used to restrict number of points along the vectors
Output:
UV: Number of points in the UV direction
pUV: List of points in the UV direction """

__author__ = "Tim Chen"
__version__ = "2018.05.10"
import ghpythonlib.treehelpers as th
import rhinoscriptsyntax as rs
import math

        
def linearMap(initP, dir1, dir2, L):
            
    pList=[]
    pList.append(initP)
    prevP=initP
    
    first=True
    
    while True:
        
        cirPlane=rs.PlaneFromNormal(prevP,dir2) # Create a plane orthogonal to dir2
        cirCrv=rs.AddCircle(cirPlane,L) # Create a circle on that plane
        intP=rs.CurveBrepIntersect(cirCrv,bSrf)[1] # Comput the intersection between the circle and the surface
        
        if first==True: # The first circle may have two equidistant intersection points
            first=False
            testP=rs.CopyObject(initP,dir1*2) # Create a test point in the positive dir1 direction
                
            if len(intP)>1: # if there are two intersections, that means there's a point on either side of the initP
                if rs.Distance(testP,intP[0])<rs.Distance(testP,intP[1]): # The one that's closer to the test point is retained
                    tempP=intP[0]
                else:
                    tempP=intP[1]
            elif len(intP)==1: # if there's one point then pick that point, this happens when the initP is close to the edge of the surface
                if rs.Distance(testP,intP[0])<rs.Distance(initP,intP[0]):
                    tempP=intP[0]
                else:
                    break
            else: # else there is no intersection
                break
        else: # subsequent circles
            if len(intP)>1: # If there are two intersecting points, so it hasn't fallen off the surface
                if rs.Distance(pList[-2],intP[0])>rs.Distance(pList[-2],intP[1]): # retain the point that's not already on the list
                    tempP=intP[0]
                else:
                    tempP=intP[1]
            else:
                break
                
        prevP=tempP
        pList.append(tempP)       
    return pList
Here on line 18 what is being done? why [1] being added a the end, I am confused,plz help.
Thankyou.
Reply
#2
rs.CurveBrepIntersect(cirCrv,bSrf) will return list - https://developer.rhino3d.com/api/RhinoS...pIntersect

by [1] you get the elemnt with index 1 from that list
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  General Coding Help biswajitmaity 2 1,769 Aug-25-2021, 03:04 PM
Last Post: jefsummers
  General coding Ellimann 2 2,387 Aug-25-2020, 05:43 AM
Last Post: buran
  general coding error karai 1 2,542 Mar-21-2018, 06:36 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020