Day 19
(3)

編み物のような交差パターン

#wave#weave#pattern#3d#curve#symmetry
編み物のような交差パターンのサムネイル

✅ Inputs

  • length: float – 曲線の長さ(X/Y方向)
  • amp: float – Z方向の波の振幅
  • wave_cycles: float – Sin波の繰り返し数
  • res: int – 曲線の分割数(滑らかさ)
  • radius: float – Pipeの半径

✅ Outputs

  • results: list of Brep – 編み目構造を構成するパイプ群

✅ Code

import Rhino.Geometry as rg
import math

# === 🔧 入力パラメータ例 ===
# length = 2000.0         # 曲線の長さ(X/Y方向)
# amp = 30.0              # Z方向の振幅
# wave_cycles = 10.0      # 波の繰り返し数
# res = 50                # 曲線分割数
# radius = 20.0           # Pipe半径

period = length / wave_cycles
spacing = period / 2
offset_shift = spacing / 2

num_x = int(length // spacing)
num_y = int(length // spacing)

freq = wave_cycles * math.pi * 2 / length

# === 📐 Sin波曲線生成
def create_wave_curve(axis='x', offset=0.0, reverse=False):
    phase = math.pi if reverse else 0.0
    points = []
    for i in range(res + 1):
        t = float(i) / res
        u = t * length
        z = math.sin(u * freq + phase) * amp
        pt = rg.Point3d(u, offset, z) if axis == 'x' else rg.Point3d(offset, u, z)
        points.append(pt)
    return rg.Curve.CreateInterpolatedCurve(points, 3)

# === 🔁 波を複製する共通関数
def generate_wave_family(axis, count, spacing, shift, start_reverse=True):
    curves = []
    for i in range(count):
        offset = i * spacing + shift
        reverse = (i % 2 == 1) if start_reverse else (i % 2 == 0)
        curves.append(create_wave_curve(axis, offset, reverse))
    return curves

# === 🔁 X/Y方向の波を生成
curves = []
curves.extend(generate_wave_family('x', num_y, spacing, offset_shift, start_reverse=True))
curves.extend(generate_wave_family('y', num_x, spacing, offset_shift, start_reverse=False))

# === 🧵 Pipe化
results = []
for c in curves:
    pipes = rg.Brep.CreatePipe(c, radius, False, rg.PipeCapMode.Round, True, 0.001, 0.001)
    if pipes:
        results.extend(pipes)