def draw(self):
     p1 = rs.coerce3dpoint(self.center+self.sv1)
     p2 = rs.coerce3dpoint(self.center+self.sv2)
     perim = rh.Geometry.Ellipse(rs.coerce3dpoint(self.center), p1, p2)
     perim_id = sc.doc.Objects.AddEllipse(perim)
     perim_nrbs = perim.ToNurbsCurve()  
     srf = rh.Geometry.Brep.CreatePlanarBreps(perim_nrbs)[0]
     srf_id = sc.doc.Objects.AddBrep(srf)
 def draw(self):
     plane = rs.PlaneFromNormal(rs.coerce3dpoint(self.center), self.nv)
     p1 = rs.coerce3dpoint(self.center+self.sv1+self.sv2)
     p2 = rs.coerce3dpoint(self.center-self.sv1-self.sv2)
     p3 = rs.coerce3dpoint(self.center+self.sv1-self.sv2)
     p4 = rs.coerce3dpoint(self.center-self.sv1+self.sv2)
     pts = [p1,p4,p2,p3,p1]
     draw_rectangle(pts)
     for pt in pts[0:-1]:
         sc.doc.Objects.AddPoint(pt)
示例#3
0
def slopeCalc(p1,p2):
    
    pt1 = rs.coerce3dpoint(p1)
    pt2 = rs.coerce3dpoint(p2)
    
    h = pt2.Z-pt1.Z
    pt2.Z = pt1.Z
 
    dist = pt1.DistanceTo(pt2)
    #print dist
    slope = h*100/dist
    
    return slope
示例#4
0
def getSolarGeom(boundary,ht,lat,shourlst,ehourlst,day,north,long,timeZ,s_mth,e_mth):
    CH = ConvexHull2d()
    boundary_pts = rs.CurvePoints(boundary) # you'll need this later
    boundary_pts.pop(-1)
    bchullpts = CH.convex_hull(boundary_pts)
    centerPt = rs.CurveAreaCentroid(rs.AddCurve(bchullpts + [bchullpts[0]],1))[0]
    #centerPt = rs.CurveAreaCentroid(boundary)[0]
    boundary_plane = rs.PlaneFitFromPoints(boundary_pts)
    top_plane = get_plane(boundary,ht)

    # project curve to user_defined height
    sun_pts = get_sunpt(lat,centerPt,s_mth,day,shourlst,north_=north,lon=long,tZ=timeZ,scale_=100)
    sun_pts.extend(get_sunpt(lat,centerPt,e_mth,day,ehourlst,north_=north,lon=long,tZ=timeZ,scale_=100))

    top_lst = project_curve(sun_pts,centerPt,top_plane,boundary)
    top_curves = map(lambda x: rs.coercecurve(x),top_lst) # temp for viz
    top_lst = map(lambda x: rs.CurvePoints(x),top_lst)
    top_pts = map(lambda x: rs.coerce3dpoint(x),\
        reduce(lambda i,j:i+j,top_lst))

    # convex hull methods
    chull_pts = CH.convex_hull(top_pts)
    chull_crv = rs.AddCurve(chull_pts + [chull_pts[0]],1)
    #chull_centerPt = rs.CurveAreaCentroid(chull_crv)[0]
    # adjust curve directions
    #if not rs.CurveDirectionsMatch(boundary,chull_crv):
    #   rs.ReverseCurve(boundary)

    #b = rs.CurvePoints(boundary) + rs.CurvePoints(chull_crv)
    #c = rs.CurvePoints(chull_crv)
    return (boundary,chull_crv),top_curves
示例#5
0
def Flows(strSrf,step,iterations):
    
    global p3dDropsPos
    global p3dDropProj
    print "Longitud de la matriz de puntos proyectados: " + str(len(p3dDropProj))
    lines = []
    
    for i in range(0,len(p3dDropProj)):
        for j in range(iterations):
            p3dDummy0 = rs.coerce3dpoint(p3dDropProj[i])
            puvClosest0 = rs.SurfaceClosestPoint(strSrf,p3dDropProj[i])
            v3dNormal = rs.SurfaceNormal(strSrf,puvClosest0)
            v3dMovement = rs.VectorScale(rs.VectorUnitize((v3dNormal[0],v3dNormal[1],0)),step)
            p3dDropProj[i] = rs.PointAdd(p3dDummy0,v3dMovement)
            
            puvClosest1 = rs.SurfaceClosestPoint(strSrf,p3dDropProj[i])
            #print puvClosest1
            p3dDummy1 = rs.EvaluateSurface(strSrf,puvClosest1[0],puvClosest1[1])
            p3dDropProj[i] = p3dDummy1
            #print str(rs.coerce3dpoint(p3dDummy0)) + '|| ' + str(rs.coerce3dpoint(p3dDummy1))
            
            dblLenCheck = rs.Distance(p3dDummy0,p3dDummy1)
            strTrail = rs.AddLine(p3dDummy0,p3dDummy1)
            if dblLenCheck>0.01 and rs.IsCurve(strTrail):
                lines.append(strTrail)
            else:
                break
def checkInputs():
    #Set a default view resolution.
    if _viewResolution_ == None: viewRes = 1
    else: viewRes = _viewResolution_
    
    #Set a default parallel.
    if parallel_ == None: parallel = False
    else: parallel = parallel_
    
    #Check to to see if the connected _testPts are points or planes.
    checkData = True
    viewMethod = 0
    viewPoints = []
    viewPtNormals = []
    for point in _testPtsOrPlanes:
        try:
            #The user has connected planes.
            viewPoints.append(point.Origin)
            viewPtNormals.append(point.Normal)
            viewMethod = 1
        except:
            #The user has connected points.
            try:
                viewPoints.append(rc.Geometry.Point3d(point))
                if viewMethod ==  1: checkData = False
            except:
                viewPoints.append(rc.Geometry.Point3d(rs.coerce3dpoint(point)))
    
    if checkData == False:
        warning = "_testPtsOrPlanes can be either points or planes but not both."
        print warning
        ghenv.Component.AddRuntimeMessage(w, warning)
    
    return checkData, viewRes, viewMethod, viewPoints, viewPtNormals, parallel
示例#7
0
 def falls(self,strSrf):
     p3dProjectedPt = rs.ProjectPointToSurface(self.p3dLocation,strSrf,(0,0,-1))
     #print p3dProjectedPt
     #if p3dProjectedPt != None:
     self.p3dLocation = rs.coerce3dpoint(p3dProjectedPt[0])
     #print self.p3dLocation
     rs.AddPoint(self.p3dLocation)
def get_sunpt(lb_sunpath,lb_preparation,lat,cpt,month,day,hourlst,north_=0,lon=0,tZ=0,scale_=100):
    """modifed from Ladybug"""
    sunpt_lst = []
    for hour in hourlst:
        centerPt = rs.coerce3dpoint(cpt)
        northAngle_, northVector = lb_preparation.angle2north(north_)
        lb_sunpath.initTheClass(lat,northAngle=northAngle_,cenPt=centerPt,\
        scale=scale_,longtitude=lon, timeZone=tZ )
        lb_sunpath.solInitOutput(month,day,hour)
        sunpt_lst.append(lb_sunpath.sunPosPt()[2]) # basePoint.Location
        #return sunSphereMesh, sunVector, basePoint.Location
    return sunpt_lst
示例#9
0
def Falls(strSrf):
    
    global p3dDropsPos
    global p3dDropProj
    
    for i in range(len(p3dDropsPos)):
        p3dProjectedPt = rs.ProjectPointToSurface(p3dDropsPos[i],strSrf,(0,0,-1))
        #print p3dProjectedPt
        if len(p3dProjectedPt)>0:
            p3dDropProj.append(rs.AddPoint(rs.coerce3dpoint(p3dProjectedPt[0])))
    if not rs.IsLayer("Drops"):
        rs.AddLayer("Drops",(30,30,255))
    rs.ObjectLayer(p3dDropProj,"Drops")
示例#10
0
    def getpoints4lot(self,lots_,cpt_,value_ref_,actual_value_ref_):
        ## Loop through tree lots and add the point_nodes
        ## to each lot; returns lst of (listof points inside each lot)
        ## bpt_lst,lots: listof(listof(point data)
        debug = sc.sticky['debug']
        lst_bpt_lst_ = []
        lst_val_lst_ = []
        lst_val_lst_actual_ = []

        for j,lot in enumerate(lots_):
            boundary = lot.shape.bottom_crv
            neighbor = []
            neighbor_val= []
            neighbor_val_actual = []
            # look through all cpts from dpts and add to neighborlst
            for i,cp in enumerate(cpt_):

                movedist = abs(lot.shape.cpt[2]-cp[2])
                if abs(movedist-0.0)>0.1:
                    if lot.shape.cpt[2] < cp[2]:
                        movedist *= -1
                    vec = rc.Geometry.Vector3d(0,0,movedist)
                else:
                    vec = rc.Geometry.Vector3d(0,0,0)
                if not lot.shape.is_guid(cp):
                    cp = sc.doc.Objects.AddPoint(cp)
                copy_cp = rs.CopyObject(cp,vec)
                #copy_cp = rs.coerce3dpoint()

                #copy_cp = cp
                in_lot = 0
                try:
                    in_lot = int(rs.PointInPlanarClosedCurve(copy_cp,boundary,lot.shape.cplane))
                except:
                    pass
                #0 = point is outside of the curve
                #1 = point is inside of the curve
                #2 = point in on the curve
                if abs(float(in_lot) - 1.) <= 0.1:
                    cp = rs.coerce3dpoint(cp)
                    neighbor.append(cp)#,datalst[i]])
                    neighbor_val.append(value_ref_[i])
                    neighbor_val_actual.append(actual_value_ref_[i])
                    #d = rs.AddPoint(copy_cp[0], copy_cp[1],0)
                    #debug.append(d)
            lst_bpt_lst_.append(neighbor)
            lst_val_lst_.append(neighbor_val)
            lst_val_lst_actual_.append(neighbor_val_actual)
        return lst_bpt_lst_,lst_val_lst_,lst_val_lst_actual_
示例#11
0
def Flows(strSrf,step,iterations,p3dDropProj2,intCount):
    
    #New variable for setting a break point
    intCount = intCount+1
    
    #Setting lists    
    p3dDummy1 = []
    p3dUV = []
    v3dNormal = []
    v3dUni = []
    p3dDummy2 = []
    lineDummy = []
    lineProy = []
    p3dDropEnd = []
    p3dDrop = []
    lineProyTest = []
    
    #Tomamos los ptos proyectados y sacamos coordenadas
    for i in range (len(p3dDropProj2)):
        
        #obtenemos pto en srf #obtenemos su uv
        p3dDummy1.append(rs.coerce3dpoint(p3dDropProj2[i]))
        p3dUV.append(rs.SurfaceClosestPoint(strSrf,p3dDummy1[i]))
        
        #sacamos la normal en ese pto a la srf #hacemos unitario el vector #desplazamos el pto
        v3dNormal.append(rs.SurfaceNormal(strSrf,p3dUV[i]))
        v3dUni.append(rs.VectorUnitize(v3dNormal[i]))
        p3dDummy2.append(rs.PointAdd(p3dDummy1[i],v3dUni[i]))
        
        #anadimos linea #Proyectamos la linea sobre la superficie #borramos los pelos
        lineDummy.append(rs.AddLine(p3dDummy1[i],p3dDummy2[i]))
        lineProyTest.append(rs.ProjectCurveToSurface(lineDummy[i],strSrf,(0,0,-1)))
        rs.DeleteObjects(lineDummy[i])
        
        #Nueva lista eliminando los nones de la anterior (NEW! - USING FILTER)
        lineProy = filter(None,lineProyTest)
        
    for i in range (len(lineProy)):
        #Buscamos el pto final de las minicurvas para empezar a iterar
        p3dDropEnd.append(rs.CurveEndPoint(lineProy[i]))
        
    #set a Break Point
    if intCount<iterations:
        Flows(strSrf,step,iterations,p3dDropEnd,intCount)
示例#12
0
 def convert_pts(self,pt):
     rc_pt = map(lambda p: rs.coerce3dpoint(p),pt)
     return map(lambda y: Vector(y[0],y[1],y[2]),rc_pt)
示例#13
0
'''
Created on 16/07/2014

@author: krnj
'''

import rhinoscriptsyntax as rs


if debug:
    import pydevd as py
    py.settrace()

def midPoint(p1,p2):
    #p3 = rs.MoveObject(p1, p1+p2)
    mPt = (p1+p2)/2
    return mPt

if pt1 and pt2:
    pt1 = rs.coerce3dpoint(pt1)
    pt2 = rs.coerce3dpoint(pt2)
    a = midPoint(pt1,pt2)
    
print pt1.__getattribute__(Guid)
def PlaneRemapToPlaneSpace(plane_guid, point):
    plane_obj = rs.coerceplane(plane_guid)
    (status, point) = plane_obj.RemapToPlaneSpace(rs.coerce3dpoint(point))
    return point
示例#15
0
----------------""" 
import copy
import scriptcontext as sc
import rhinoscriptsyntax as rs
import clr

clr.AddReference("Grasshopper")
from Grasshopper.Kernel.Data import GH_Path
from Grasshopper import DataTree

if run:    
    rule = DataTree[object]()
    rule_ = [\
    ['bula', True],\
    ['grammar_key','bula'],\
    ['bula_point_lst', map(lambda pt: rs.coerce3dpoint(pt), analysis_ref)],\
    ['bula_value_lst', value_ref],\
    ['end_rule']]
    
    for i, r in enumerate(rule_):
        rule.Add(r)

else:
    rule = []






示例#16
0
def convertToArrayPoint3d(points):
	pArray = System.Array.CreateInstance(Rhino.Geometry.Point3d, len(points))
	arrPoints = List[System.Array[Point3d]]([pArray])
	for i in range(len(points)):
		pArray[i] = rs.coerce3dpoint(points[i])
	return arrPoints
def checkTheInputs():
    # Set default scale.
    scale = 1
    if _scale_ != None:
        if _scale_ > 0: scale = _scale_
        else:
            warning = "_scale_ must be greater than 0."
            print warning
            ghenv.Component.AddRuntimeMessage(gh.GH_RuntimeMessageLevel.Warning, warning)
            return -1
    
    # Set default sky density.
    if _skyDensity_ != None:
        if _skyDensity_ >= 0:
            skyDensity = int(_skyDensity_*100)
        else:
            warning = "skyDensity_ must be greater than 0."
            print warning
            ghenv.Component.AddRuntimeMessage(gh.GH_RuntimeMessageLevel.Warning, warning)
            return -1
    else: skyDensity = 100
    
    # Check the view point or plane.
    viewMethod = 0
    viewPlane = None
    if _centerPtOrPlane_ == None:
        centerPt = rc.Geometry.Point3d.Origin
    else:
        try:
            #The user has connected planes.
            centerPt = _centerPtOrPlane_.Origin
            viewPlane = rc.Geometry.Plane(_centerPtOrPlane_)
            viewMethod = 1
        except:
            #The user has connected points.
            try:
                centerPt = rc.Geometry.Point3d(_centerPtOrPlane_)
            except:
                try:
                    centerPt = rc.Geometry.Point3d(rs.coerce3dpoint(_centerPtOrPlane_))
                except:
                    warning = "_centerPtOrPlane_ is neither a point or a plane."
                    print warning
                    ghenv.Component.AddRuntimeMessage(gh.GH_RuntimeMessageLevel.Warning, warning)
                    return -1
    
    # Check the orientation.
    if orientation_ != None:
        if orientation_.lower() == "north":
            orientVector = rc.Geometry.Vector3d(0,1,0)
        elif orientation_.lower() == "east":
            orientVector = rc.Geometry.Vector3d(1,0,0)
        elif orientation_.lower() == "south":
            orientVector = rc.Geometry.Vector3d(0,-1,0)
        elif orientation_.lower() == "west":
            orientVector = rc.Geometry.Vector3d(-1,0,0)
        else:
            try:
                orientAngle = float(orientation_)
                if orientAngle > 360 or orientAngle < 0:
                    warning = "orientation_ must be between 0 and 360."
                    print warning
                    ghenv.Component.AddRuntimeMessage(gh.GH_RuntimeMessageLevel.Warning, warning)
                    return -1
                orientVector = rc.Geometry.Vector3d(0,1,0)
                orientVector.Rotate(math.radians(-orientAngle), rc.Geometry.Vector3d.ZAxis)
            except:
                warning = "orientation_ input is not valid."
                print warning
                ghenv.Component.AddRuntimeMessage(gh.GH_RuntimeMessageLevel.Warning, warning)
                return -1
        viewMethod = 1
        viewPlane = rc.Geometry.Plane(centerPt, orientVector)
    
    # Check the overhang, left fin, and right fin projections.
    if overhangProject_ != None:
        if overhangProject_ < 0 or overhangProject_ > 90:
            warning = "overhangProject_ should be between 0 and 90."
            print warning
            ghenv.Component.AddRuntimeMessage(gh.GH_RuntimeMessageLevel.Warning, warning)
            return -1
    if leftFinProject_ != None:
        if leftFinProject_ < 0 or leftFinProject_ > 180:
            warning = "leftFinProject_ should be between 0 and 180."
            print warning
            ghenv.Component.AddRuntimeMessage(gh.GH_RuntimeMessageLevel.Warning, warning)
            return -1
    if rightFinProject_ != None:
        if rightFinProject_ < 0 or rightFinProject_ > 180:
            warning = "rightFinProject_ should be between 0 and 180."
            print warning
            ghenv.Component.AddRuntimeMessage(gh.GH_RuntimeMessageLevel.Warning, warning)
            return -1
    
    return viewMethod, centerPt, viewPlane, scale, skyDensity
示例#18
0
            pts = []
            for j in itertools.islice(lineConstrainedPoints.Branch(i),1,None):
                if j is not None: 
                    pts.append (j)
            parts = DynamicRelaxation.makeForceConstraintsFromList(ps,makePtsFromRhino(pts),makePtFromRhino(vect), False)
            allLineConstraints.append(parts)
    
    #### rail constrained points
    allRailConstraints = [] 
    for i in range(railConstrainedPoints.BranchCount):
        if len(railConstrainedPoints.Branch(i))>1 and railConstrainedPoints.Branch(i)[1] is not None:
            rail = CurveConstraint(rs.coercecurve(railConstrainedPoints.Branch(i)[0]))
            pts = []
            for j in itertools.islice(railConstrainedPoints.Branch(i),1,None):
                if j is not None: 
                    pts.append (rs.coerce3dpoint(j))
            parts, springs = DynamicRelaxation.makePositionSpringConstraintsFromList(ps, makePtsFromRhino(pts),rail.apply, 1000, 0)
            allRailConstraints.append(parts)

    #### plane constrained points
    allPlaneConstraintPoints = [] 
    for i in range(planeConstrainedPoints.BranchCount):
        if len(planeConstrainedPoints.Branch(i))>1:
            plVect = makePtFromRhino(planeConstrainedPoints.Branch(i)[0])
            pts = []
            for j in itertools.islice(planeConstrainedPoints.Branch(i),1,None):
                if j is not None: 
                    pts.append (j)
            parts = DynamicRelaxation.makeForceConstraintsFromList(ps,makePtsFromRhino(pts),plVect)
            allPlaneConstraintPoints.append(parts)