28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
import math
|
|
from build123d import Circle, Helix, Plane
|
|
from build123d import sweep as _sweep
|
|
|
|
|
|
def validate(context, target, params):
|
|
errors = []
|
|
if params["profile_radius"] >= params["coil_radius"]:
|
|
errors.append("PROFILE_TOO_LARGE: 截面半径过大,会与螺旋轴线自相交")
|
|
pitch, radius = params["pitch"], params["coil_radius"]
|
|
turn_spacing = pitch / math.sqrt(1 + (pitch / (2 * math.pi * radius)) ** 2)
|
|
if params["height"] > pitch and 2 * params["profile_radius"] >= turn_spacing * .98:
|
|
errors.append("SELF_INTERSECTION: 相邻螺旋圈相交或相切;减小线径。公制牙型请使用 metric_thread,禁止加粗线圈模拟螺纹")
|
|
if params["height"] / pitch > 200:
|
|
errors.append("COMPLEXITY_LIMIT: 单次螺旋不得超过200圈")
|
|
return errors
|
|
|
|
|
|
def run(context, target, params):
|
|
path = Helix(
|
|
pitch=params["pitch"],
|
|
height=params["height"],
|
|
radius=params["coil_radius"],
|
|
lefthand=params["lefthand"],
|
|
)
|
|
profile = Plane(origin=path.position_at(0), z_dir=path.tangent_at(0)) * Circle(params["profile_radius"])
|
|
return _sweep(profile, path=path)
|