线性&同时旋转挤出

时间:2015-03-03 21:38:23

标签: openscad

我正试图绘制这个(空心)形状:

funky_shape

圆圈实际上是不同的直径,我想要像连接管的中间那样颈缩(但不是必需的)。我可以通过逐段绘制它来伪造形状,但我有问题缩小它,并且它不像OpenSCAD想要它完成(即长达一小时的CSG生成)。有更好的方法吗? rendered shape

for(i = [0:180]) {
    rotate([0,i,0])
    translate([26,0,0])
    difference() {
        cylinder(r=10 + (0.083 * i),h=.1);
        cylinder(r=8 + (0.083 * i),h=.1);
    }
}

2 个答案:

答案 0 :(得分:4)

这是纯粹的openscad版本。有关模块及其用法的详细信息,请参阅scad-utilslist-comprehension-demos

use <scad-utils/transformations.scad>
use <scad-utils/shapes.scad>
use <skin.scad>

fn=32;
$fn=60;

r1 = 25;
r2 = 10;
R = 40;
th = 2;

module tube()
{
    difference()
    {
        skin([for(i=[0:fn]) 
              transform(rotation([0,180/fn*i,0])*translation([-R,0,0]), 
                        circle(r1+(r1-r2)/fn*i))]);
        assign(r1 = r1-th, r2 = r2-th)
        skin([for(i=[0:fn]) 
              transform(rotation([0,180/fn*i,0])*translation([-R,0,0]), 
                        circle(r1+(r1-r2)/fn*i))]);
    }
}

tube();

result

答案 1 :(得分:1)

首先是结果:

difference if 2 polyhedrons

由两个多面体的差异创建。 3d对象有效,请参阅控制台中的“simple:yes”

要获得多面体python3所需的点数,请使用: 首先构造基圆上的任意数量的点(点的数量定义3D对象的分辨率)。这些点旋转并按n步骤缩放到180度,最终比例因子(n也控制分辨率)。然后使用这些点来定义形状的面。最后,所有内容都以openscad-syntax编写到文件中。

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import math

# define parameters
rr = 26                     # radius of rotation
r1 = 10                     # outer radius of tube                      
r2 = 8                      # inner radius of tube
scale = 2                   # scalefactor over rotation
segments = 90               # segments of base circle   -> resolution
rAngle = 180                # angle of rotation
rSegments = 45              # segments of rotation      -> resolution

def polyhedron(rr,radius,scale, segments, rAngle, rSegments):
    stepAngle = 360/segments
    rotAngle = rAngle/rSegments
    points = '['                # string with the vector of point-vectors
    faces = '['                 # string with the vector of face-vectors
    sprs = (scale-1)/rSegments                  # scale per rSegment

    # construct all points
    for j in range(0,rSegments+1):
        angle = j*rotAngle
        for i in range(0,segments):
            xflat = (math.sin(math.radians(i*stepAngle))*radius)            # x on base-circle
            xscaled = xflat*(1 + sprs*j) + rr                       # x scaled (+ rr -> correction of centerpoint
            xrot = math.cos(math.radians(angle))*xscaled                # x rotated
            yflat = (math.cos(math.radians(-i*stepAngle))*radius)           # y on base-circle
            yscaled = yflat*(1 + sprs*j)                        # y scaled
            z = math.sin(math.radians(angle))*xscaled                   # z rotated
            string  = '[{},{},{}],'.format(xrot,yscaled,z)
            points += string

    points += ']' 

    # construct all faces
    # bottom
    f = '['
    for i in range(segments-1,-1,-1):
        f += '{},'.format(i)
    f += '],'
    faces += f                  # add bottom to faces

    # all faces on the side of the tube
    for p in range(0, segments*rSegments):
        p1 = p
        p2 = p + 1 -segments if p%segments == segments-1 else p +1
        p3 = p + segments
        p4 = p3 + 1 -segments if p%segments == segments-1 else p3 +1
        f = '[{},{},{}],'.format(p1,p4,p3)
        faces += f
        f = '[{},{},{}],'.format(p1,p2,p4)
        faces += f
    # top
    f = '['
    for i in range(segments*rSegments,segments*(rSegments+1)):
        f += '{},'.format(i)
    f += ']'
    faces += f                  # add top to faces
    faces += ']'

    string = 'polyhedron( points = {}, faces = {});'.format(points,faces)
    return string    

# output in openscad-file
wobj = open('horn.scad','w')            # open openscad-file for writing
wobj.write('difference() {\n')
string = '    '
string += polyhedron(rr,r1,scale,segments,rAngle,rSegments)
string += '\n'
wobj.write(string)
string = '    '
string += polyhedron(rr,r2,scale,segments,rAngle,rSegments) 
string += '\n'
wobj.write(string)
wobj.write('}')
wobj.close()                        # close openscad-file
# finally open openscad-file in openscad

它在34秒内呈现