import math
import sand3d as s3d
def adjustable_rail():
fixed_rail = fixed_rail_body()
sliding_rail = rail(fixed_rail, class="tok-string">"sliding_rail", x=-120.1, y=10, z=41.63, rx=90)
return s3d.assembly(class="tok-string">"adjustable_rail", fixed_rail, sliding_rail)
def rail(parent, name, x=0, y=0, z=0, rx=0, ry=0, rz=0):
frame = s3d.local(parent, x, y, z, rx, ry, rz)
sliding_rail = s3d.at(sliding_rail_body(name), on=frame)
slide_frame = s3d.local(parent, -120.1, 10, 41.63, 90, 0, 0)
s3d.joint(fclass="tok-string">"{name}_slide", sliding_rail, slide_frame, kind=class="tok-string">"prismatic", range=(-8, 8))
spin_frame = s3d.local(parent, -120.1, 10, 41.63, 90, 0, 0)
s3d.joint(fclass="tok-string">"{name}_spin", sliding_rail, spin_frame, kind=class="tok-string">"continuous")
return sliding_rail
def fixed_rail_body():
slotted_rail_1 = slotted_rail(class="tok-string">"slotted_rail_1")
slotted_rail_1 = s3d.transform(slotted_rail_1, z=60.38)
return s3d.group(class="tok-string">"fixed_rail", slotted_rail_1)
def sliding_rail_body(name):
piece = slotted_rail(fclass="tok-string">"{name}_piece")
piece = s3d.transform(piece, x=120.1, y=-18.75, z=10, rx=-90, rz=180)
return s3d.group(name, piece)
def slotted_rail(
name,
length=248.4,
width=80,
height=45.7,
wall=1.6,
end_x=117.6,
top_t=2,
bridge=6,
bore=25.12,
hinge_d=8.2,
hinge_bore=5,
hinge_length=26,
):
bottom = -height / 2 + hinge_d / 2
wall_h = height / 2 - bottom
side = s3d.at(s3d.extrude(name, s3d.rect(2 * end_x, wall), wall_h), y=-(width - wall) / 2, z=bottom)
other = s3d.transform(s3d.copy(side), mirror=class="tok-string">"y")
end = s3d.at(s3d.extrude(class="tok-string">"end", s3d.rect(wall, width - 2 * wall), wall_h), x=end_x - wall / 2, z=bottom)
twin = s3d.transform(s3d.copy(end), mirror=class="tok-string">"x")
body = s3d.join(side, other, end, twin)
body = end_bores(body, bore, 1.05)
top = s3d.at(s3d.extrude(class="tok-string">"lattice", s3d.rect(2 * end_x, width), top_t), z=height / 2 - top_t)
top = windows(top, end_x, width, bridge, wall)
body = s3d.join(body, top)
eye_x = (length - hinge_d) / 2
lug = hinge_eye(eye_x, end_x, bottom, hinge_d, hinge_bore, hinge_length, wall)
lug = s3d.at(lug, y=23)
second = s3d.transform(s3d.copy(lug), mirror=class="tok-string">"x", y=-31)
return s3d.join(body, lug, second)
def end_bores(ob, diameter, z):
return s3d.hole(ob, diameter, on=s3d.Frame((0, 0, z), normal=(1, 0, 0)))
def windows(ob, end_x, width, bridge, wall):
pitch = (2 * end_x - wall) / 4
opening = pitch - bridge
upper_depth = width / 2 - bridge / 2 - bridge
lower_depth = upper_depth - 8
s3d.pocket(
ob,
s3d.rect(opening, upper_depth),
on=s3d.grid(4, 1, pitch, on=ob.face(class="tok-string">"top")).move(y=bridge / 2 + upper_depth / 2),
)
s3d.pocket(
ob,
s3d.rect(opening, lower_depth),
on=s3d.grid(4, 1, pitch, on=ob.face(class="tok-string">"top")).move(y=-bridge / 2 - lower_depth / 2),
)
return ob
def hinge_eye(x, end_x, z, diameter, bore, length, wall):
eye = s3d.at(s3d.extrude(class="tok-string">"eye", s3d.circle(diameter), length, both=True), rx=90, x=x, z=z)
web = s3d.at(
s3d.extrude(
class="tok-string">"flap",
s3d.poly(
[(end_x - wall, z), (x + diameter / 2, z), (end_x, z + 3 * diameter), (end_x - wall, z + 3 * diameter)]
),
length,
both=True,
),
rx=90,
)
eye = s3d.join(eye, web)
return s3d.hole(eye, bore, on=s3d.Frame((x, 0, z), normal=(0, 1, 0)))