def doLcurves(key): """ """ the_filename = 'complex_Lcurvesurface#data_curves.txt' a, b = the_filename.split('#') the_filename = a + key + b with open(the_filename, 'r') as f: llist = [] ci = [] for line in f: if not 'new' in line: ci.append([float(el) for el in line.split(',')]) else: llist.append(ci) ci = [] the_filename = 'complex_Lcurvesurface#data_knots.txt' a, b = the_filename.split('#') the_filename = a + key + b with open(the_filename, 'r') as f: lknots = [] ci = [] for line in f: if not 'new' in line: ci.append([float(el) for el in line.split()]) else: lknots.append(ci[0]) ci = [] for verts, knots in zip(llist, lknots): rs.AddNurbsCurve(verts, knots, 3) return
def smoothcurve(curve_id, s): curve_points = rs.CurvePoints(curve_id) new_curve_points = [] for i in range(len(curve_points) - 1): vm = smoothingvector(curve_points[i], curve_points[i - 1], curve_points[i + 1], s) new_curve_points.append(rs.PointAdd(curve_points[i], vm)) knots = rs.CurveKnots(curve_id) degree = rs.CurveDegree(curve_id) weights = rs.CurveWeights(curve_id, 0) newcurve_id = rs.AddNurbsCurve(new_curve_points, knots, degree, weights) if newcurve_id: rs.DeleteObject(curve_id) return newcurve_id
degree = numPts - 1 elif numPts > 4: if degree < 3 or degree == None: degree = 3 elif degree >= numPts: degree = numPts - 1 knotsL = [0.0 for i in range(degree)] interN = (numPts + degree - 1) - (2 * degree) if interN > 0: interVstep = 1 / (interN + 1) interV = interVstep for i in range(interN): knotsL.append(interV) interV += interVstep for i in range(degree): knotsL.append(1.0) weightsL = [1.0 for i in range(numPts)] return knotsL, degree, weightsL degree = 5 # Rhino's "Curve" command default pts = rs.GetObjects("Pick up the control points to draw the Nurbs curve", 1, preselect=True) knots, degree, weights = knotsDegreeWeights(pts, degree) if knots: crvId = rs.AddNurbsCurve(pts, knots, degree, weights)
import rhinoscriptsyntax as rs import random as rd curve = rs.GetObject("Select a Curve", 4) if curve: points = rs.CurvePoints(curve) knots = rs.CurveKnots(curve) degree = rs.CurveDegree(curve) newpoints = [] for p in points: dx = rd.randrange(0, 10) dy = rd.randrange(0, 10) dz = rd.randrange(0, 10) d = [dx, dy, dz] q = rs.PointAdd(p, d) newpoints.append(q) newcurve = rs.AddNurbsCurve(newpoints, knots, degree)
G11y1mV = Array[float](G11y1m) G11x2mV = Array[float](G11x2m) G11y2mV = Array[float](G11y2m) AngErrorG12V = Array[int](AngErrorG12) G12x1mV = Array[float](G12x1m) G12y1mV = Array[float](G12y1m) G12x2mV = Array[float](G12x2m) G12y2mV = Array[float](G12y2m) ## Initial curve with four elastic curve segments kn = [0, 0, 0, 1 / 4, 1 / 4, 1 / 2, 1 / 2, 3 / 4, 3 / 4, 1, 1, 1] points = [[-6.0000, 0.0001, 0], [-5.0000, 0, 0], [-4.0000, 0.0001, 0], [-2.0000, 0, 0], [-1.000, 0, 0], [1.0000, 0.0001, 0], [2.000, 0, 0], [4.0000, 0.0001, 0], [5.00, 0, 0], [6, 0.0001, 0]] crv = rs.AddNurbsCurve(points, kn, 3) N = rs.CurvePointCount(crv) rs.EnableObjectGrips(crv) actvpt = rs.GetObjectGrip("Choose active point") actvpt0 = actvpt[0] actvpt = actvpt[1] + 1 # Interactive part while True: Cpxvec = [] Cpyvec = [] for i in range(0, N): Cpxvec.append(points[i][0]) Cpyvec.append(points[i][1]) Cpx = Array[float](Cpxvec)
#llist = [[[0.0, 20.0, 0.0], [0.0, 13.689426381477222, 4.0002890852673394], [0.0, 4.4540716700211611, 12.000058021539173], [0.0, -0.12339041728990097, 23.999363296711884], [0.0, 1.2434497875801753e-13, 35.998508463180791], [0.0, -1.4210854715202004e-14, 47.998850637893831], [0.0, 3.5527136788005009e-15, 60.000680135487023], [0.0, -1.7763568394002505e-14, 71.998882871644469], [0.0, 1.2079226507921703e-13, 83.994200801409534], [0.0, 4.403070469450812, 95.995107364541894], [0.0, 11.901331089896892, 108.0009263060668], [0.0, 17.294847143940022, 116.00110037614954], [0.0, 20.0, 120.0]], [[0.0, 12.782296528297564, 109.20027595204532], [0.0, 10.166632794000352, 105.26863838876216], [0.0, 5.5544826033856118, 96.739653293683176], [0.0, 2.0152947407214814, 85.695459612600644], [0.0, 0.40188409288902943, 76.191351813602296], [0.0, -0.026008863367496093, 68.603489780021377], [0.0, 0.010679750777248297, 60.853496390082739], [0.0, -0.024699444783581766, 52.44082292830722], [0.0, 0.53186512436347777, 44.925327051898797], [0.0, 3.5158773075366558, 31.020012017103671], [0.0, 8.7118548244920575, 13.33764852133919], [0.0, 8.88252339983109, 8.2465638775697432], [0.0, 6.0, 12.0]], [[0.0, 13.253342156760684, 109.92042453643717], [1.1696204298634565, 10.629375898547286, 106.05909408597117], [2.2524367640017209, 6.0780912386668664, 97.436471634682491], [1.9910919778084613, 2.6271979489524884, 85.974911983795579], [1.7087208664798026, 1.0612217179598029, 76.23350210166987], [1.6332774132738503, 0.6217349399692097, 68.576659420739261], [1.6384564012886202, 0.63660377031006665, 60.792005977972003], [1.6339099710999507, 0.6320294267305635, 52.340694402998416], [1.7013122731442962, 0.59067585926348498, 45.41107544570297], [2.0574362782148872, 0.44785331605566248, 35.265937038743878], [2.5344014901985101, 0.59906048508262844, 23.669417329198378], [1.387297115563308, 3.6961510455717033, 14.813466856106116], [0.0, 6.6143498051498382, 11.200034710680651]], [[0.0, 14.201242183016303, 111.36065998862654], [2.1324444816315542, 11.964216356249882, 107.43389483845246], [4.5905548435940622, 7.7323781372593317, 98.590623978016822], [5.0282268628208975, 4.0620111897341227, 86.577940456737764], [4.9809441964840104, 2.3726743100626777, 76.481264555949821], [4.9649922202567325, 1.9094920658330123, 68.608298411160902], [4.9634920180161632, 1.926239210688705, 60.708557407325074], [4.9662717222703643, 1.9191023774737419, 52.201383834028199], [4.9024419676795477, 1.9142830443241321, 45.009849813269071], [4.5887344908859333, 1.9599001875921604, 34.723873465625928], [3.7364159409196809, 2.4894020008903168, 22.860749659596181], [1.5995040032477479, 5.4238318895362383, 13.633992556344335], [0.0, 7.9667236818478209, 9.6000994903188221]], [[0.0, 15.637359659743261, 113.52081888053706], [2.8205543986359611, 14.36454333526579, 109.24369531074146], [6.5935025140575192, 10.411630845133509, 99.983203485385545], [8.206770294573646, 5.1930718042471451, 87.473814942009909], [8.6472179117254395, 2.5961814391930744, 77.033149797862848], [8.7571518049900909, 1.8998280587522878, 68.803653419574431], [8.7464008264773412, 1.9307920999025419, 60.690159648175765], [8.7581713422607592, 1.9098230146703132, 51.974492816592701], [8.531295122676827, 2.1330209317278341, 44.415521981057566], [7.4120923708027604, 3.3170519614332994, 33.913632923193767], [4.9362039602586387, 5.8924007123467028, 21.734323414019325], [1.7575409619167672, 8.8683030467974202, 11.89820056482916], [0.0, 10.373361756864881, 7.2001660980182454]], [[0.0, 17.084585703169132, 115.68077434948356], [3.3128469589363729, 16.567273050365557, 111.22111750751446], [7.4006310851267108, 13.838699461954194, 101.48318490780365], [8.6182890236713021, 9.3969079283500623, 88.113384459656828], [8.7325389813557432, 7.1364197563544645, 77.183098811369092], [8.7541110935239335, 6.549231460159036, 68.729261441874542], [8.7472877931006039, 6.5764087384816658, 60.537275424679464], [8.7567445562943469, 6.5560488491365119, 51.843304022912342], [8.5377674138667246, 6.8026696198796834, 43.946238433389595], [7.5122296882090023, 8.0349597864589146, 33.105611265695913], [5.108384519049145, 10.56151404143281, 20.208662711281342], [1.8815736485797194, 12.54281772755856, 9.8451322491253865], [0.0, 13.165131552627191, 4.8001855073714097]], [[0.0, 18.539761442649297, 117.84051725887558], [3.5690854418364624, 18.473775263013941, 113.19762643940783], [7.827754105314809, 17.115568553349874, 102.97653131449302], [8.846606408327288, 14.453000373822031, 88.745285644079956], [8.7780968841883205, 13.074730838402356, 77.320466277203408], [8.7525352999425543, 12.72843369078549, 68.65289341919285], [8.7477619457938687, 12.7449162812933, 60.365011370407132], [8.7560658242040414, 12.731544619495331, 51.702516743849372], [8.5311264508210716, 12.90872047515105, 43.446995722270174], [7.5260594702094652, 13.749500610322617, 32.216681301526748], [5.0834584103872764, 15.39619431837512, 18.511030328201286], [1.8778063410303365, 16.292302093735444, 7.6868863689541342], [0.0, 16.349087529909919, 2.4001410817898901]], [[0.0, 20.0, 0.0], [1.1325867907035676, 20.0, 3.977386459517219], [3.5623907983050782, 20.0, 11.890388260218085], [5.3143836429168765, 20.0, 24.417561399960874], [8.7499999999990141, 20.0, 36.506995969664388], [8.7500000000000409, 20.0, 48.063317560379645], [8.7499999999999822, 20.0, 59.960644560851044], [8.7500000000000302, 20.0, 72.06793515902838], [8.7499999999994422, 20.0, 83.889908203579537], [7.6527998044258565, 20.0, 95.88705923958797], [6.6290820075857217, 20.0, 108.0380957180401], [2.1588456728960956, 20.0, 115.98640383151447], [0.0, 20.0, 120.0]]] the_filename = 'longitudinal_curves.txt' with open(the_filename, 'r') as f: llist = [] ci = [] for line in f: if not 'new' in line: ci.append([float(el) for el in line.split(',')]) else: llist.append(ci) ci = [] #lknots = [[0.0, 0.0, 0.0, 0.10000000000000001, 0.20000000000000001, 0.30000000000000004, 0.40000000000000002, 0.5, 0.59999999999999998, 0.69999999999999996, 0.79999999999999993, 0.89999999999999991, 1.0, 1.0, 1.0], [0.0, 0.0, 0.0, 0.14285714285714285, 0.2857142857142857, 0.33837795250618891, 0.42857142857142855, 0.51305655578250131, 0.5714285714285714, 0.68383610822045959, 0.71428571428571419, 0.8571428571428571, 1.0, 1.0, 1.0], [0.0, 0.0, 0.0, 0.14285714285714285, 0.2857142857142857, 0.34060823072768948, 0.42857142857142855, 0.51176188992624783, 0.5714285714285714, 0.67936704956589422, 0.71428571428571419, 0.8571428571428571, 1.0, 1.0, 1.0], [0.0, 0.0, 0.0, 0.14285714285714285, 0.2857142857142857, 0.34521763397788252, 0.42857142857142855, 0.51015381099166945, 0.5714285714285714, 0.67227004530961754, 0.71428571428571419, 0.8571428571428571, 1.0, 1.0, 1.0], [0.0, 0.0, 0.0, 0.14285714285714285, 0.2857142857142857, 0.35181093811884318, 0.42857142857142855, 0.50934270625251088, 0.5714285714285714, 0.66450965349005953, 0.71428571428571419, 0.8571428571428571, 1.0, 1.0, 1.0], [0.0, 0.0, 0.0, 0.14285714285714285, 0.2857142857142857, 0.35679761418866107, 0.42857142857142855, 0.50703512196312517, 0.5714285714285714, 0.65632046414678002, 0.71428571428571419, 0.8571428571428571, 1.0, 1.0, 1.0], [0.0, 0.0, 0.0, 0.14285714285714285, 0.2857142857142857, 0.36102351019142437, 0.42857142857142855, 0.50462708048039073, 0.5714285714285714, 0.64841943090554166, 0.71428571428571419, 0.8571428571428571, 1.0, 1.0, 1.0], [0.0, 0.0, 0.0, 0.10000000000000001, 0.20000000000000001, 0.30000000000000004, 0.40000000000000002, 0.5, 0.59999999999999998, 0.69999999999999996, 0.79999999999999993, 0.89999999999999991, 1.0, 1.0, 1.0]] the_filename = 'longitudinal_knots.txt' with open(the_filename, 'r') as f: lknots = [] ci = [] for line in f: if not 'new' in line: ci.append([float(el) for el in line.split()]) else: lknots.append(ci[0]) ci = [] for verts, knots in zip(tlist, tknots): rs.AddNurbsCurve(verts, knots, 3) for verts, knots in zip(llist, lknots): rs.AddNurbsCurve(verts, knots, 3)