by Tuğrul Yazar | October 14, 2021 21:37
This is the continuation of the previous post[1] on parametric curve equations. In this new version, the script picks a NURBS curve from the user. Then, it analyses the curve’s degree and control points. Unfortunately, only the curves with degree+1 number of control points can be processed. In the future, I hope that I will be able to extend this script to include multi-span curves with more than degree +1 control points. Finally, the script creates the three functions for the x, y, and z axes. This part is the same as the previous post[2]. In this version, I tried to add a simplification method. That method is actually a string replacement method for the expressions like “+0, -0, *1, **1, etc.”. However, I decided not to include it yet.
I think the most important limitation of Rhino Python is still waiting for a solution: The Iron Python support, which has no ability to use external modules such as numpy. I still hope that one day this limitation will be over. Until then, we will have to use the native Python and develop our own methods for even the simplest tasks. I must admit that this limitation gives an opportunity for a better educational environment, but limits its effective utilization a lot. In this script, we revisited the curve equations and their user interaction. In the future, this and similar scripts can be combined into a “Lunchbox”-like a small add-on in Rhino.
I still believe that text-based programming will continue to be the fundamental skill in design computing. You can copy and test the below code in Rhino 6 or 7, by typing the “EditPythonScript” command and then, running the code by hitting F5.
import rhinoscriptsyntax as rs
from math import *
f = g = h = ""
curve = rs.GetObject("Pick the curve")
if not rs.IsCurve(curve):
print("Sorry, this is not a curve")
else:
d = rs.CurveDegree(curve)
print("This is a degree-"+str(d)+" curve")
p = rs.CurvePoints(curve)
print("It has "+str(len(p))+" control points")
if len(p) != d + 1:
print("Unfortunately the control points must be degree + 1 to run this script")
else:
for i in range(d + 1):
c = factorial(d)/(factorial(i)*(factorial(d-i)))
f += "("+str(c)+"*((1-t)**("+str(d)+"-"+str(i)+"))*(t**"+str(i)+")*"+str(p[i][0])+")+"
g += "("+str(c)+"*((1-t)**("+str(d)+"-"+str(i)+"))*(t**"+str(i)+")*"+str(p[i][1])+")+"
h += "("+str(c)+"*((1-t)**("+str(d)+"-"+str(i)+"))*(t**"+str(i)+")*"+str(p[i][2])+")+"
f += "0"; g += "0"; h += "0"
print("These are the parametric equations of the curve")
print("f = "+f)
print("g = "+g)
print("h = "+h)
print("Now, testing the curve by plotting the equations within the domain (0,1)")
for i in range(0,100):
t = i / 100
point = [eval(f), eval(g), eval(h)]
rs.AddPoint(point)
Source URL: https://www.designcoding.net/curve-equations-revisited/
Copyright ©2024 designcoding unless otherwise noted.