[OpenSCAD] 2D, 3D OpenSCAD Problem

Jordan Brown openscad at jordan.maileater.net
Sat Oct 26 18:20:26 EDT 2019


Your immediate problem is that your polyhedron is malformed.  Several of
the faces are wound counterclockwise, and that confuses OpenSCAD.  Use
View/Thrown Together to see.  From the outside, you want to see all
yellow. It's also more complex than it needs to be, because you've built
it out of triangles and your bar is built out of four-edged faces.

Here's a Paths list that works:

Paths=[
    [3,2,1,0],
    [0,5,4,3],
    [5,6,7,4],
    [6,1,2,7],
    [2,3,4,7],
    [0,1,6,5]
    ];

Continuing...

Cleaning up your indentation would make it easier to read.

The union() in objet() isn't necessary.  It doesn't even do anything,
since it only encloses one object (the translated polyhedron).

The linear extrusion of a circle is a cylinder, so might as well use
that directly.

You seem to be needing a lot of arithmetic to compensate for the fact
that you've translated the bar down to be centered on Z=0.  Leaving so
its bottom is at Z=0 makes it simpler.

The halign="center" option on the text makes positioning simpler.  (Here
it's simpler to have the bar centered on X=0 and Y=0.

Cutting $fn down from 250 to 50 is almost imperceptible and speeds F6
rendering up from 17s to 11s on my system.

text_w is used as a "negative" object, so doesn't really make sense to
color.

Assuming that you want the "Gold" centered in the circles, the text
option valign=center helps, and then the text and the circle are
positioned to the same place.

Here's the result of that cleanup...


// Size of 2KG of Gold Linget Fonte
// 10mm x 4.3mm X 2.41mm
// Calculated from Density of gold = 19.30 g/cm3 at 20°C
// 30 => 4.3
// 100 => 10
// 30 h =>2.41 
// 25 => 3.15
// 5 => 1.15
// 95 => 8.85

l=4.3;
L=10;
h=2.41;
inset = 0.005;
circle_h = 0.005;
epsilon = 0.001;
gold_y = 2.25;

top_x= (l/2)-1; // top_x=1.15
bottom_x= l-top_x; // bottom_x=3.15
L_R_h= L-top_x; // L_R_h=8.85

Points=[[0,0,0],[l,0,0],[bottom_x,top_x,h],[top_x,top_x,h],[top_x,L_R_h,h],[0,L,0],[l,L,0],[bottom_x,L_R_h,h]];

Paths=[
    [3,2,1,0],
    [0,5,4,3],
    [5,6,7,4],
    [6,1,2,7],
    [2,3,4,7],
    [0,1,6,5]
    ];

module text_w() {
    translate([0,gold_y,h-inset])
        resize([1,0.5,0])
        linear_extrude(height=inset+epsilon)
        text("Gold", halign="center", valign="center");
    translate([0,-2,h-inset])
        resize([1,0.5,0])
        linear_extrude(height=inset+epsilon) text("2 Kg", halign="center");
    translate([0,-3,h-inset])
        resize([1,0.4,0])
        linear_extrude(height=inset+epsilon) text("70.5479 oz", halign="center");
}

module Torn() { 
    difference(){
        resize([1.6,1.2,0])
            cylinder(h=circle_h, r=5, $fn=50);
        translate([0,0,-epsilon])
            resize([1.4,1,0])
            cylinder(h=circle_h + 2*epsilon, r=2, $fn=50);
    }   
}

translate([0,gold_y,h]){
    Torn();
} 

module objet(){
    translate([-l/2,-L/2,0])
        polyhedron(points=Points, faces=Paths);  
}

difference(){
    objet();
    text_w();
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20191026/e482e6bd/attachment.html>


More information about the Discuss mailing list