Hi there,
I’m looking into finding information about OpenNurbs access with python scripting on mac.
Basically what i’d have to do is this:
Given a curve A, i’d like to generate another curve B which is generated according to the following formula:
Curve B = Curve A + gradient(X,Y,Z) * constant
My current and idiotic script does the following:
It divides the curve in a lot of small points and offsets these points by the derivative,
but this gets computationally very messy and generates messy curves too.
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext
import System.Guid
class TanLines:
def __init__ (self, INcurve, INdivideBy, INradius):
self.curve = INcurve
self.divideBy = float(INdivideBy)
self.radius = int(INradius)
def tanPoints(self):
doms = rs.CurveDomain(self.curve)
minDom = doms[0]
maxDom = doms[1]
points = Rhino.Collections.Point3dList(30)
lengthCurve = rs.CurveLength(self.curve)
self.numOfDivs = (lengthCurve/self.divideBy)
for i in range(0, int(self.numOfDivs)):
if i > 1:
paramNext = ((maxDom-minDom)/self.numOfDivs) * (1+i)
if i == 1:
param = ((maxDom-minDom)/self.numOfDivs) * (i)
param = (maxDom-minDom)/self.numOfDivs * i
pt = rs.EvaluateCurve(self.curve, param)
tan = rs.CurveTangent(self.curve, param)
if i > 1:
tanNext = rs.CurveTangent(self.curve, paramNext)
if i == 0:
tan = rs.VectorScale(rs.CurveTangent(self.curve, param), -10)
elif i == self.numOfDivs-1:
tan = rs.VectorScale(rs.CurveTangent(self.curve, param), 10)
else:
tan = rs.VectorScale(rs.CurveTangent(self.curve, param), self.radius)
tanPt = rs.PointAdd(rs.PointAdd(tan, pt), (0,0,i*0.00))
#rs.AddLine(pt, tanPt)
if (i > 1):
if (rs.IsVectorParallelTo(tan, tanNext) == 1):
points.Add(tanPt)
else:
points.Add(tanPt)
nc = Rhino.Geometry.NurbsCurve.Create(False, 3, points)
rc = Rhino.Commands.Result.Failure
if nc and nc.IsValid:
if scriptcontext.doc.Objects.AddCurve(nc)!=System.Guid.Empty:
scriptcontext.doc.Views.Redraw()
rc = Rhino.Commands.Result.Success
return rc
curve = rs.GetObject("Select a curve")
obj = TanLines(curve, rs.GetReal("length", 1, 0, 10000), rs.GetReal("Radius", 200, 0, 10000))
obj.tanPoints()