Using SymPy with BricsCAD
SymPy is a Python library for symbolic mathematics.
A useless, but cool example
import sympy as sp
from pyrx import Ap, Db, Ge
@Ap.Command()
def drawknot():
db = Db.curDb()
t = sp.Symbol("t")
R = 40.0 # Major radius
r = 12.0 # Minor radius
p = 3 # Wraps around central hole
q = 7 # Wraps around tube
pipe_radius = 3.0 # Radius of the solid pipe tube
# 3D Parametric Equations for the Torus Knot
x_expr = (R + r * sp.cos(q * t)) * sp.cos(p * t)
y_expr = (R + r * sp.cos(q * t)) * sp.sin(p * t)
z_expr = r * sp.sin(q * t)
# Lambdify the symbolic math for rapid point plotting
x_func = sp.lambdify(t, x_expr, "math")
y_func = sp.lambdify(t, y_expr, "math")
z_func = sp.lambdify(t, z_expr, "math")
# Populate 3D Point Array
points = Ge.Point3dArray()
steps = 400
max_t = 2 * sp.pi.evalf()
for i in range(steps):
t_val = (i / steps) * float(max_t)
x = x_func(t_val)
y = y_func(t_val)
z = z_func(t_val)
points.append(Ge.Point3d(x, y, z))
# Create Polyline
raw_polyline = Db.Polyline3d(Db.Poly3dType.k3dSimplePoly, points, True)
# Create a Circle Profile
normal_vec = points[-1] - points[0]
profile_circle = Db.Circle(points[0], normal_vec, pipe_radius)
# Perform the 3D Sweep Operation ---
solid_pipe = Db.Solid3d()
sweep_opts = Db.SweepOptions()
sweep_opts.setAlign(Db.SweepAlignOption.kAlignSweepEntityToPath)
sweep_opts.setCheckIntersections(False)
solid_pipe.createSweptSolid(profile_circle, raw_polyline, sweep_opts)
db.addToModelspace(solid_pipe)
0

