1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-09-25 14:39:01 +02:00

Compare commits

..

8 Commits

Author SHA1 Message Date
Chris Palmer
b5fe03fcb2 Test image pixel differences due to switch to winter computer 2020-11-04 20:48:22 +00:00
Chris Palmer
1658f6f0b4 Sweep can now cope with the start having colinear points. 2020-11-04 19:56:51 +00:00
Chris Palmer
7b126f9792 More spelling 2020-11-04 19:50:35 +00:00
Chris Palmer
479207fd4f Spelling 2020-11-04 10:52:57 +00:00
Chris Palmer
3ee55981f9 Comment spelling. 2020-10-05 12:02:54 +01:00
Chris Palmer
8c2b4a20fe Added tesrdrop_minus() and horicylinder(). 2020-10-05 10:59:50 +01:00
Chris Palmer
1529759406 Fixes for lazy union. 2020-10-05 10:42:13 +01:00
Chris Palmer
c4a986aa21 Test for circle_intersect() 2020-10-05 10:41:27 +01:00
19 changed files with 87 additions and 16 deletions

View File

@@ -18,7 +18,7 @@
// //
// //
// Include this file to use the miniumum library plus screws, nuts and washers // Include this file to use the minimum library plus screws, nuts and washers
// //
include <utils/core/core.scad> include <utils/core/core.scad>
// //

View File

@@ -33,7 +33,7 @@ $exploded = is_undef($explode) ? 0 : $explode; // 1 f
layer_height = is_undef($layer_height) ? 0.25 : $layer_height; // layer heigth when printing layer_height = is_undef($layer_height) ? 0.25 : $layer_height; // layer heigth when printing
extrusion_width = is_undef($extrusion_width) ? 0.5 : $extrusion_width; // filament width when printing extrusion_width = is_undef($extrusion_width) ? 0.5 : $extrusion_width; // filament width when printing
nozzle = is_undef($nozzle) ? 0.45 : $nozzle; // 3D printer nozzle nozzle = is_undef($nozzle) ? 0.45 : $nozzle; // 3D printer nozzle
cnc_bit_r = is_undef($cnc_bit_r) ? 1.2 : $cnc_bit_r; // miniumum tool radius when milling 2D objects cnc_bit_r = is_undef($cnc_bit_r) ? 1.2 : $cnc_bit_r; // minimum tool radius when milling 2D objects
pp1_colour = is_undef($pp1_colour) ? [0, 146/255, 0] : $pp1_colour; // printed part colour 1, RepRap logo colour pp1_colour = is_undef($pp1_colour) ? [0, 146/255, 0] : $pp1_colour; // printed part colour 1, RepRap logo colour
pp2_colour = is_undef($pp2_colour) ? "red" : $pp2_colour; // printed part colour 2 pp2_colour = is_undef($pp2_colour) ? "red" : $pp2_colour; // printed part colour 2
pp3_colour = is_undef($pp3_colour) ? "blue" : $pp3_colour; // printed part colour 3 pp3_colour = is_undef($pp3_colour) ? "blue" : $pp3_colour; // printed part colour 3

View File

@@ -403,7 +403,7 @@ PCB mounted buttons. Can optionally have a coloured cap
## Cable_strips ## Cable_strips
A strip of polypropylene used with ribbon cable to make a cable flexible in one direction only. A strip of polypropylene used with ribbon cable to make a cable flexible in one direction only.
Modelled with a Bezier spline, which is not quite the same as a miniumum energy curve but very close, epecially Modelled with a Bezier spline, which is not quite the same as a minimum energy curve but very close, epecially
near the extreme positions, where the model needs to be accurate. near the extreme positions, where the model needs to be accurate.
When the sides are constrained then a circular model is more accurate. When the sides are constrained then a circular model is more accurate.
@@ -5387,6 +5387,8 @@ Method to print holes in mid air. See <https://hydraraptor.blogspot.com/2014/03/
## Horiholes ## Horiholes
Utilities for depicting the staircase slicing of horizontal holes made with [`teardrop_plus()`](#teardrops), see <https://hydraraptor.blogspot.com/2020/07/horiholes-2.html> Utilities for depicting the staircase slicing of horizontal holes made with [`teardrop_plus()`](#teardrops), see <https://hydraraptor.blogspot.com/2020/07/horiholes-2.html>
```horicylinder()``` makes cylinders that fit inside a round hole. Layers that are less than 2 filaments wide and layers that need more than a 45 degree overhang are omitted.
[utils/horiholes.scad](utils/horiholes.scad) Implementation. [utils/horiholes.scad](utils/horiholes.scad) Implementation.
@@ -5395,11 +5397,13 @@ Utilities for depicting the staircase slicing of horizontal holes made with [`te
### Functions ### Functions
| Function | Description | | Function | Description |
|:--- |:--- | |:--- |:--- |
| ```teardrop_minus_x(r, y, h)``` | Calculate the ordinate of a compensated teardrop given y and layer height. |
| ```teardrop_plus_x(r, y, h)``` | Calculate the ordinate of a compensated teardrop given y and layer height. | | ```teardrop_plus_x(r, y, h)``` | Calculate the ordinate of a compensated teardrop given y and layer height. |
### Modules ### Modules
| Module | Description | | Module | Description |
|:--- |:--- | |:--- |:--- |
| ```horicylinder(r, z, h = 0, center = true)``` | For making horizontal cylinders that don't need support material and are correct dimensions |
| ```horihole(r, z, h = 0, center = true)``` | For making horizontal holes that don't need support material and are correct dimensions | | ```horihole(r, z, h = 0, center = true)``` | For making horizontal holes that don't need support material and are correct dimensions |
![horiholes](tests/png/horiholes.png) ![horiholes](tests/png/horiholes.png)

View File

@@ -69,9 +69,13 @@ module horiholes() {
color(silver) color(silver)
cylinder(r = $r, h = eps, center = true, $fn = 360); cylinder(r = $r, h = eps, center = true, $fn = 360);
hole_positions()
color("blue")
horicylinder(r = $r, z = $z, h = 2 * eps, center = true, $fn = 360);
hole_positions() hole_positions()
color("red") color("red")
linear_extrude(2 * eps, center = true) linear_extrude(3 * eps, center = true)
intersection() { intersection() {
difference() { difference() {
square(8, center = true); square(8, center = true);

View File

@@ -69,6 +69,33 @@ module maths() {
// Test Euler // Test Euler
// //
assert(euler(rotate(r)) == r, "euler() failed"); assert(euler(rotate(r)) == r, "euler() failed");
//
// Circle intersect
//
r1 = 10;
c1 = [50, 0, 10];
r2 = 20;
c2 = [67, 0, 0];
p1 = circle_intersect(c1, r1, c2, r2);
p2 = circle_intersect(c2, r2, c1, r1);
rotate(90) {
color(grey(90))
translate(c1) rotate([90, 0, 0]) cylinder(r = r1, h = 4 * eps, center = true);
color(grey(80))
translate(c2) rotate([90, 0, 0]) cylinder(r = r2, h = eps, center = true);
color("red")
translate(p1) rotate([90, 0, 0]) cylinder(r = 0.1, h = 6 * eps, center = true);
color("blue")
translate(p2) rotate([90, 0, 0]) cylinder(r = 0.1, h = 6 * eps, center = true);
translate(p1) arrow();
translate(p2) vflip() arrow();
}
} }
rotate(45) rotate(45)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 119 KiB

After

Width:  |  Height:  |  Size: 119 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 KiB

After

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 KiB

After

Width:  |  Height:  |  Size: 160 KiB

View File

@@ -18,7 +18,7 @@
// //
// //
// Include this file to use the miniumum library // Include this file to use the minimum library
// //
include <../../global_defs.scad> include <../../global_defs.scad>
// //

View File

@@ -19,6 +19,8 @@
// //
//! Utilities for depicting the staircase slicing of horizontal holes made with [`teardrop_plus()`](#teardrops), see <https://hydraraptor.blogspot.com/2020/07/horiholes-2.html> //! Utilities for depicting the staircase slicing of horizontal holes made with [`teardrop_plus()`](#teardrops), see <https://hydraraptor.blogspot.com/2020/07/horiholes-2.html>
//!
//! ```horicylinder()``` makes cylinders that fit inside a round hole. Layers that are less than 2 filaments wide and layers that need more than a 45 degree overhang are omitted.
// //
include <../utils/core/core.scad> include <../utils/core/core.scad>
@@ -53,3 +55,29 @@ module horihole(r, z, h = 0, center = true) { //! For making horizontal holes th
} }
} }
} }
function teardrop_minus_x(r, y, h) = //! Calculate the ordinate of a compensated teardrop given y and layer height.
let(fr = h / 2,
hpot = r - fr,
x2 = sqr(hpot) - sqr(y),
x = x2 > 0 ? sqrt(x2) : 0,
X = y >= -hpot / sqrt(2) ? x + fr : 0
)
X >= extrusion_width ? X : 0;
module horicylinder(r, z, h = 0, center = true) { //! For making horizontal cylinders that don't need support material and are correct dimensions
bot_layer = floor((z - r) / layer_height);
top_layer = ceil((z + r) / layer_height);
render(convexity = 5)
extrude_if(h, center)
for(i = [bot_layer : top_layer]) {
Z = i * layer_height;
y = Z - z + layer_height / 2;
x = teardrop_minus_x(r, y, layer_height);
if(x >= extrusion_width)
hull()
for(end = [-1, 1])
translate([end * (x - layer_height / 2), y])
circle(d = layer_height, $fn = 32);
}
}

View File

@@ -34,14 +34,22 @@ function transpose3(m) = [ [m[0].x, m[1].x, m[2].x],
[m[0].y, m[1].y, m[2].y], [m[0].y, m[1].y, m[2].y],
[m[0].z, m[1].z, m[2].z] ]; [m[0].z, m[1].z, m[2].z] ];
// //
// Find the first non-colinear point
//
tiny = 0.00001;
function find_curve(tangents, i = 1) =
i >= len(tangents) - 1 || norm(cross(tangents[0], tangents[i] - tangents[0])) > tiny ? i
: find_curve(tangents, i + 1);
//
// Frenet-Serret frame // Frenet-Serret frame
// //
function fs_frame(tangents) = function fs_frame(tangents) =
let(tangent = tangents[0], let(tangent = tangents[0],
normal = tangents[1] - tangents[0], i = find_curve(tangents),
normal = tangents[i] - tangents[0],
binormal = cross(tangent, normal), binormal = cross(tangent, normal),
z = unit(tangent), z = unit(tangent),
x = assert(norm(binormal) > 0.00001, "first three points are colinear") unit(binormal), x = assert(norm(binormal) > tiny, "all points are colinear") unit(binormal),
y = unit(cross(z, x)) y = unit(cross(z, x))
) [[x.x, y.x, z.x], ) [[x.x, y.x, z.x],
[x.y, y.y, z.y], [x.y, y.y, z.y],
@@ -70,7 +78,6 @@ function orientate(p, r) =
[x.y, y.y, z.y], [x.y, y.y, z.y],
[x.z, y.z, z.z], [x.z, y.z, z.z],
[p.x, p.y, p.z]]; [p.x, p.y, p.z]];
// //
// Rotate around z // Rotate around z
// //

View File

@@ -20,7 +20,7 @@
// //
//! A strip of polypropylene used with ribbon cable to make a cable flexible in one direction only. //! A strip of polypropylene used with ribbon cable to make a cable flexible in one direction only.
//! //!
//! Modelled with a Bezier spline, which is not quite the same as a miniumum energy curve but very close, epecially //! Modelled with a Bezier spline, which is not quite the same as a minimum energy curve but very close, epecially
//! near the extreme positions, where the model needs to be accurate. //! near the extreme positions, where the model needs to be accurate.
//! //!
//! When the sides are constrained then a circular model is more accurate. //! When the sides are constrained then a circular model is more accurate.

View File

@@ -161,13 +161,13 @@ module al_clad_resistor(type, value, leads = true) { //! Draw an aluminium clad
} }
linear_extrude(thickness) linear_extrude(thickness)
difference() { difference() {
union()
for(end = [-1, 1]) for(end = [-1, 1])
translate([end * (length - tab) / 2, end * (width - width / 2) / 2]) translate([end * (length - tab) / 2, end * (width - width / 2) / 2])
square([tab, width / 2], center = true); square([tab, width / 2], center = true);
al_clad_resistor_hole_positions(type) al_clad_resistor_hole_positions(type)
circle(d = al_clad_hole(type)); circle(d = al_clad_hole(type));
} }
if(leads) { if(leads) {
translate_z(height / 2) translate_z(height / 2)

View File

@@ -62,6 +62,7 @@ module smd_led(type, colour, cutout) { //! Draw an SMD LED with specified ```col
intersection() { intersection() {
square([size.x, size.y], center = true); square([size.x, size.y], center = true);
union()
for(end = [-1, 1]) for(end = [-1, 1])
translate([end * size.x / 2, 0]) translate([end * size.x / 2, 0])
ring(or = r, ir = r / 2); ring(or = r, ir = r / 2);