Wednesday, October 15, 2014

vector surface attractor | rhinoscript python

http://www-personal.umich.edu/%7Egwil/gendescom/post049/vector_srf_points.mp4
In this tutorial I utilize a surface domain script, vectors, and an attractor point to manipulate the directionality of simple geometry. Code available here. Total Length: 14.30

2 comments:

Unknown said...


Hurrah, that's what I was searching for, what a information! existing here at this weblog, thanks admin of this website. gmail email login

Unknown said...

Very helpful, but how do you get objects to start responding to the attractor point? for example, I am trying to get surfaces in my script to start turning/responding to the sun (the attractor point). Below is my current script. I want to get the triangle aggregation to start responding to sun conditions, but I'm not sure how to go about it.

import scriptcontext
import rhinoscriptsyntax as rs
import random as rd
from math import atan2, degrees


SrfList = []

#define the function

def DivideTriangleSrf(srf,delete,scaleFactor):

#duplicate the border and return a list

surfaceBorderlist = rs.DuplicateSurfaceBorder(srf, 1)
if len(surfaceBorderlist)>0:
Border = (surfaceBorderlist[0])

#get line segments from the border as individual curves

linesegments = rs.ExplodeCurves(Border)

linesegment1 = linesegments[0]

linesegment2 = linesegments[1]

linesegment3 = linesegments[2]


curvelenght = (rs.CurveLength(linesegment1))


#calculate the middle points

midPoint1 = rs.CurveMidPoint(linesegment1)

midPoint2 = rs.CurveMidPoint(linesegment2)

midPoint3 = rs.CurveMidPoint(linesegment3)



#calculate the vertex

vertexPoints = rs.CurvePoints(Border)

point1 = vertexPoints[0]

point2 = vertexPoints[1]

point3 = vertexPoints[2]



#calculate the vectors

normalVectors = rs.SurfaceNormal(srf,(0,0))

normalVectors = rs.VectorScale(normalVectors,curvelenght*scaleFactor)


#since normal vector is by default 0-based, I add it to the midPoints

midPoint1N = rs.VectorAdd(normalVectors,midPoint1)

midPoint2N = rs.VectorAdd(normalVectors,midPoint2)

midPoint3N = rs.VectorAdd(normalVectors,midPoint3)

#add surfaces

baseSrf = rs.AddSrfPt((midPoint1N,midPoint2N,midPoint3N))

triangleSrf1 = rs.AddSrfPt((point1,midPoint1N,midPoint3N))

triangleSrf2 = rs.AddSrfPt((point2,midPoint2N,midPoint1N))

triangleSrf3 = rs.AddSrfPt((point3,midPoint3N,midPoint2N))


#For further subdivision

if(curvelenght>4):

DivideTriangleSrf(baseSrf,delete,scaleFactor)

DivideTriangleSrf(triangleSrf1,delete,scaleFactor)

DivideTriangleSrf(triangleSrf2,delete,scaleFactor)

DivideTriangleSrf(triangleSrf3,delete,scaleFactor)


SrfList.append(baseSrf)

SrfList.append(triangleSrf1)

SrfList.append(triangleSrf2)

SrfList.append(triangleSrf3)



if(delete):

rs.DeleteObjects((baseSrf,triangleSrf1,triangleSrf2,triangleSrf3))

rs.DeleteObject(Border)




#define variables

theSurface = rs.GetObjects("selectsurface that is defined by at least 3 points",8)

chooseDelete = rs.GetString("Do you want to delete the surfaces?",None)

scaleFactor = rs.GetReal("Enter scale factor",0.25,0.1,4)


#Call the function
for i in theSurface:
DivideTriangleSrf(i,chooseDelete,scaleFactor)

rs.DeleteObjects(theSurface)



#def FacetheSun():