Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement and apply openscad-format #50

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .openscad-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
BasedOnStyle: Mozilla
ColumnLimit: 80
IndentWidth: 2
AccessModifierOffset: -2
ContinuationIndentWidth: 2
TabWidth: 2
UseTab: Never
19 changes: 8 additions & 11 deletions array/along_curve.scad
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,23 @@ include <MCAD/units/metric.scad>
* rotation (default: undef)
* @param axis Axis to rotate around (default: Z)
*/
module mcad_rotate_multiply (no, angle = undef, axis = Z)
module mcad_rotate_multiply(no, angle = undef, axis = Z)
{
if (no > 0) {
angle = (angle == undef) ? 360 / no : angle;
if (no > 0) {
angle = (angle == undef) ? 360 / no : angle;

for (i = [0:no - 1]) {
rotate (angle * i, axis)
children ();
}
for (i = [0:no - 1]) {
rotate(angle * i, axis) children();
}
}
}

/**
* Duplicate object by rotating 180° around an axis
*
* @param axis Axis of rotation (default: Z)
*/
module mcad_duplicate (axis = Z)
module mcad_duplicate(axis = Z)
{
mcad_rotate_multiply (no = 2, axis = axis)
children ();
mcad_rotate_multiply(no = 2, axis = axis) children();
}

11 changes: 5 additions & 6 deletions array/generic-multiply.scad
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
* @param transformations List of transformations to apply to children()
* @Param keep_original Whether or not to show the original child
*/
module mcad_multiply (transformations, keep_original = true)
module mcad_multiply(transformations, keep_original = true)
{
if (keep_original)
children ();
if (keep_original)
children();

for (t = transformations)
multmatrix (t)
children ();
for (t = transformations)
multmatrix(t) children();
}
7 changes: 3 additions & 4 deletions array/mirror.scad
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
*
* @param axis Vector representing axis to mirror().
*/
module mcad_mirror_duplicate (axis)
module mcad_mirror_duplicate(axis)
{
children ();
children();

mirror (axis)
children ();
mirror(axis) children();
}
65 changes: 28 additions & 37 deletions array/polar.scad
Original file line number Diff line number Diff line change
@@ -1,51 +1,42 @@
include <MCAD/units/metric.scad>
use <MCAD/array/translations.scad>
use <MCAD/general/utilities.scad>
include <MCAD/units/metric.scad>
use <scad-utils/transformations.scad>

/**
* Generate polar coordinates for polar-arrayed objects
*
* @param angle Angle increment between each coordinate (negative is clockwise)
* @param number Number of coordinates
* @param radius Radius of coordinates
*/
function mcad_generate_polar_coords (angle, number, radius) = (
let (total = angle * number)
[
for (i = [0:number-1])
[radius, i * total / number]
]
);
* Generate polar coordinates for polar-arrayed objects
*
* @param angle Angle increment between each coordinate (negative is clockwise)
* @param number Number of coordinates
* @param radius Radius of coordinates
*/
function mcad_generate_polar_coords(angle, number, radius) = (let(
total = angle * number)[for (i = [0:number - 1])[radius, i* total / number]]);

/**
* Polar array, i.e. place objects in a circular arc
*
* @param angle Angle between each copy (negative is clockwise)
* @param number Number of copies
* @param radius Radius of array path
*/
module mcad_array_polar (angle, number, radius, preserve_orientation = false)
* Polar array, i.e. place objects in a circular arc
*
* @param angle Angle between each copy (negative is clockwise)
* @param number Number of copies
* @param radius Radius of array path
*/
module mcad_array_polar(angle, number, radius, preserve_orientation = false)
{
polar_coords = mcad_generate_polar_coords (angle, number, radius);
polar_coords = mcad_generate_polar_coords(angle, number, radius);

if (preserve_orientation)
mcad_place_at ([for (coord = polar_coords)
conv2D_polar2cartesian (coord)])
children ();
if (preserve_orientation)
mcad_place_at([for (coord = polar_coords) conv2D_polar2cartesian(coord)])
children();

else
for (coord = polar_coords)
rotate (coord[1], Z)
translate ([coord[0], 0])
children ();
else
for (coord = polar_coords)
rotate(coord[1], Z) translate([ coord[0], 0 ]) children();
}

module test_mcad_array_polar ()
module
test_mcad_array_polar()
{
mcad_array_polar (angle = 30,
number = 3,
radius = 10,
preserve_orientation = true)
cube (2, center = true);
mcad_array_polar(
angle = 30, number = 3, radius = 10, preserve_orientation = true)
cube(2, center = true);
}
54 changes: 25 additions & 29 deletions array/rectangular.scad
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
/**
* Copyright (C) 2016 Chow Loong Jin <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/

* Copyright (C) 2016 Chow Loong Jin <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/

use <MCAD/array/translations.scad>
include <MCAD/units/metric.scad>
Expand All @@ -28,12 +27,11 @@ include <MCAD/units/metric.scad>
* @param separation 2- or 3-vector indicating separation in respective axes
* @param center Boolean or vector indicating which axes to center
*/
module mcad_array_rectangular (grid_size, separation, center = true)
module mcad_array_rectangular(grid_size, separation, center = true)
{
mcad_place_at (mcad_generate_grid (grid_size = grid_size,
separation = separation,
center = center))
children ();
mcad_place_at(mcad_generate_grid(
grid_size = grid_size, separation = separation, center = center))
children();
}

/**
Expand All @@ -44,12 +42,10 @@ module mcad_array_rectangular (grid_size, separation, center = true)
* @param separation Separation between centers of adjacent copies
* @param axis Direction to project toward
*/
module mcad_linear_multiply (no, separation, axis = Z, center = false)
module mcad_linear_multiply(no, separation, axis = Z, center = false)
{
centering_offset = -1 * axis * (no - 1) * separation / 2;
centering_offset = -1 * axis * (no - 1) * separation / 2;

translate (center ? centering_offset : [0, 0, 0])
for (i = [0:no - 1])
translate (i * separation * axis)
children ();
translate(center ? centering_offset : [ 0, 0, 0 ]) for (i = [0:no - 1])
translate(i * separation * axis) children();
}
57 changes: 24 additions & 33 deletions array/translations.scad
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ use <scad-utils/transformations.scad>
* @param points Vector of points
* @returns Vector of translation matrices
**/
function mcad_points2translations (points) = [
for (point = points)
translation (point)
];
function mcad_points2translations(points) = [for (point = points)
translation(point)];

/**
* Generate vector of points that represents grid
Expand All @@ -38,48 +36,41 @@ function mcad_points2translations (points) = [
* @param separation 2- or 3-vector indicating separation in respective axes
* @param center Boolean or vector indicating which axes to center
*/
function mcad_generate_grid (grid_size, separation, center = false) = (
let (
sep = len (separation) > 0 ? separation : [1, 1, 1] * separation,
g = grid_size,
center = len(center) > 0 ? center : [center, center, center],
function mcad_generate_grid(grid_size, separation, center = false) =
(let(sep = len(separation) > 0 ? separation : [ 1, 1, 1 ] * separation,
g = grid_size,
center = len(center) > 0 ? center : [ center, center, center ],

center_offset = [
for (i = [0:len(g)])
(center[i]) ? (g[i] - 1) * sep[i] / 2 : 0
]
)

(len (grid_size) == 2) ? [
for (x = [0 : g[0] - 1])
for (y = [0 : g[1] - 1])
[x * sep[0], y * sep[1]] - center_offset
] :
(len (grid_size) == 3) ? [
for (x = [0 : g[0] - 1])
for (y = [0 : g[1] - 1])
for (z = [0 : g[2] - 1])
[x * sep[0], y * sep[1], z * sep[2]] - center_offset
] : []
);
center_offset = [for (i = [0:len(g)])(center[i])
? (g[i] - 1) * sep[i] / 2
: 0])

(len(grid_size) == 2)
? [for (x = [0:g[0] - 1]) for (y = [0:g[1] - 1])[x * sep[0], y* sep[1]] -
center_offset]
: (len(grid_size) == 3)
? [for (x = [0:g[0] - 1]) for (y = [0:g[1] - 1]) for (
z = [0:g[2] - 1])[x * sep[0], y* sep[1], z* sep[2]] -
center_offset]
: []);

/**
* Place children at points
*
* @param List of points.
*/
module mcad_place_at (points)
module mcad_place_at(points)
{
mcad_multiply (mcad_points2translations (points), keep_original = false)
children ();
mcad_multiply(mcad_points2translations(points), keep_original = false)
children();
}

/**
* Test mcad_place_at module
*/
module mcad_test_place_at ()
module
mcad_test_place_at()
{
mcad_place_at (mcad_generate_grid ([10, 10, 10], separation = $t * 10,
center = true));
mcad_place_at(
mcad_generate_grid([ 10, 10, 10 ], separation = $t * 10, center = true));
}
4 changes: 2 additions & 2 deletions boxes.scad
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use <MCAD/shapes/3Dshapes.scad>

// @deprecated
module roundedBox (size, radius, sidesonly, center = true)
mcad_rounded_box (size, radius, sidesonly, center);
module roundedBox(size, radius, sidesonly, center = true)
mcad_rounded_box(size, radius, sidesonly, center);
18 changes: 6 additions & 12 deletions curves.scad
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
// Parametric curves, to be used as paths
// Licensed under the MIT license.
// © 2010 by Elmo Mäntynen
use <MCAD/general/math.scad>
include <MCAD/general/constants.scad>
use <MCAD/general/math.scad>



/* A circular helix of radius a and pitch 2πb is described by the following parametrisation:
x(t) = a*cos(t),
y(t) = a*sin(t),
z(t) = b*t
/* A circular helix of radius a and pitch 2πb is described by the following
parametrisation: x(t) = a*cos(t), y(t) = a*sin(t), z(t) = b*t
*/


function b(pitch) = pitch/(const_tau);
function t(pitch, z) = z/b(pitch);
function b(pitch) = pitch / (const_tau);
function t(pitch, z) = z / b(pitch);

function helix_curve(pitch, radius, z) =
[radius*cos(deg(t(pitch, z))), radius*sin(deg(t(pitch, z))), z];

[ radius * cos(deg(t(pitch, z))), radius* sin(deg(t(pitch, z))), z ];
32 changes: 16 additions & 16 deletions demos/array_along_curve_demo.scad
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
include <MCAD/array/along_curve.scad>;
include <MCAD/array/along_curve.scad>

//center reference point
translate([0,0,0])
#cube([5,5,5],center=true);
// center reference point
translate([ 0, 0, 0 ])
#cube([ 5, 5, 5 ], center = true);

spin(3,30,Z)
spin(3, 30, Z)
{
translate([5,5,5])
#cube([5,5,5],center=true);
// square([25,10]);
// square([25,10]);
// square([25,10]);
// square([25,10]);
// square([25,10]);
translate([ 5, 5, 5 ])
#cube([ 5, 5, 5 ], center = true);
// square([25,10]);
// square([25,10]);
// square([25,10]);
// square([25,10]);
// square([25,10]);
}

//cubic array of 5*5*5 objects spaced 10*10*10 center relative
//array_linear(20)
// cubic array of 5*5*5 objects spaced 10*10*10 center relative
// array_linear(20)
//{
// sphere(2.5,center=true,$fn=60);
// cylinder(h=10,r=.5,center=true);
Expand All @@ -26,8 +26,8 @@ spin(3,30,Z)
// cylinder(h=10,r=.5,center=true);
//}
//
//translate([0,0,10])
//array_linear_grid(30,15,false,3)
// translate([0,0,10])
// array_linear_grid(30,15,false,3)
//{
// square([25,10]);
// square([25,10]);
Expand Down
Loading