SCAD 将槽移至框架中心

问题描述 投票:0回答:1

frame

在上图中,您可以看到一个矩形框架和一侧的小槽。我想把那个槽放在那一边的中心,但我的代码没有这样做。

这是我的插槽代码:

// Create the top cutout for the headband in the middle of the shorter side
        translate([outer_length / 2 - slot_width / 2, -outer_width / 2, -border_height]) {
            cube([slot_width, border_height + 1, slot_depth]);
        }
    }

在我看来,如果我/2 应该这样做,但不确定发生了什么。有什么想法吗?

我尝试将outer_length与Outer_width交换,并在前面添加0,但没有成功。

这是整个框架的代码,包括插槽的代码:

// Parameters for the rectangular frame
outer_length = 85;       // Outer length of the frame (in mm)
outer_width = 65;        // Outer width of the frame (in mm)
border_thickness = 2;    // Thickness of the raised border (in mm)
border_height = 10;      // Height of the raised border (in mm)
inner_length = outer_length - 2 * border_thickness;  // Inner length of the frame (in mm)
inner_width = outer_width - 2 * border_thickness;    // Inner width of the frame (in mm)
bottom_thickness = 1;    // Thickness of the thin opaque bottom layer (in mm)
corner_radius = 5;       // Radius for rounded corners (in mm)
slot_width = 10;         // Width for headband slots (in mm)
slot_depth = 5;          // Depth for headband slots (in mm)

// Function to create a rectangular frame with rounded corners, a hollow interior, and a thin opaque bottom layer
module rec_frame() {
    difference() {
        // Create the outer shell with rounded corners and raised border
        translate([0, 0, -border_height])
        linear_extrude(height = border_height + bottom_thickness) {
            offset(r = corner_radius) {
                square([outer_length, outer_width], center = true);
            }
        }

        // Create the inner hollow part with rounded corners
        translate([0, 0, -border_height])
        linear_extrude(height = border_height + bottom_thickness) {
            offset(r = corner_radius - 1) {
                square([inner_length, inner_width], center = true);
            }
        }

        // Create the thin opaque bottom layer
        translate([0, 0, -bottom_thickness])
        square([outer_length, outer_width], center = true);
        
        // Create the top cutout for the headband in the middle of the shorter side
        translate([outer_length / 2 - slot_width / 2, -outer_width / 2, -border_height]) {
            cube([slot_width, border_height + 1, slot_depth]);
        }
    }

    // Create the thin opaque bottom layer
    translate([0, 0, -bottom_thickness - border_height])
    linear_extrude(height = bottom_thickness) {
        offset(r = corner_radius) {
            square([outer_length, outer_width], center = true);
        }
    }
}

// Create the frame using the module
rec_frame();
openscad
1个回答
0
投票

使用

%cube([slot_width, border_height + 1, slot_depth]);

这将使立方体可见。

在 z 轴上将其向上平移约 10。

然后摆弄你的另一个翻译,你就能看到什么效果了 翻译在立方体上。

将其移动到您需要的地方。 删除翻译+10。 删除%。

你应该可以走了。

© www.soinside.com 2019 - 2024. All rights reserved.