Skip to content

Commit

Permalink
use unit_vector
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinSDK committed May 16, 2022
1 parent be53dd2 commit 6f00785
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/__comm__/_face_normal.scad
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function _face_normal(points) =
let(v = cross(points[2] - points[0], points[1] - points[0])) v / norm(v);
use <../util/unit_vector.scad>;

function _face_normal(points) = unit_vector(cross(points[2] - points[0], points[1] - points[0]));
8 changes: 3 additions & 5 deletions src/_impl/_bijection_offset_impl.scad
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use <../__comm__/__lines_from.scad>;
use <../__comm__/__line_intersection.scad>;

use <../util/unit_vector.scad>;

function _outward_edge_normal(edge) =
let(
v = edge[1] - edge[0],
nv = v / norm(v)
)
let(nv = unit_vector(edge[1] - edge[0]))
[nv.y, -nv.x];

function _edge(edge, dxy) = edge + [dxy, dxy];
Expand Down
5 changes: 3 additions & 2 deletions src/polyhedra/_impl/_geom_platonic_polyhedra.scad
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use <../../util/unit_vector.scad>;

function _tri_subdivide_pts(points, radius, rows) =
let(
p0 = points[0],
basis = [points[2] - p0, points[1] - p0] / rows
)
[
for(ri = [0:rows], ci = [0:rows - ri])
let(p = p0 + [ri, ci] * basis)
radius * p / norm(p)
radius * unit_vector(p0 + [ri, ci] * basis)
];

function _tri_subdivide_faces(rows) =
Expand Down
3 changes: 2 additions & 1 deletion src/ptf/_impl/_ptf_rotate_impl.scad
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use <../../__comm__/__to2d.scad>;
use <../../__comm__/__to3d.scad>;
use <../../__comm__/__to_ang_vect.scad>;
use <../../util/unit_vector.scad>;

function _q_rotate_p_3d(p, a, v) =
let(
uv = v / norm(v),
uv = unit_vector(v),
s = sin(a / 2) * uv,
w = sin(a) * uv,

Expand Down
7 changes: 2 additions & 5 deletions src/surface/sf_curve.scad
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
**/

use <_impl/_sf_square_surfaces.scad>;
use <../util/unit_vector.scad>;
use <sf_solidify.scad>;

module sf_curve(levels, curve_path, thickness, depth, invert = false, convexity = 1) {
Expand Down Expand Up @@ -37,11 +38,7 @@ module sf_curve(levels, curve_path, thickness, depth, invert = false, convexity
];

m = __ry_matrix(-90);
normal_vts = [
for(i = [0:columns - 1])
let(v = pts[i + 1] - pts[i])
v / norm(v) * m
];
normal_vts = [for(i = [0:columns - 1]) unit_vector(pts[i + 1] - pts[i]) * m];

dp = is_undef(depth) ? thickness / 2 : depth;
surfaces = _sf_square_surfaces(levels, thickness, dp, invert);
Expand Down
3 changes: 2 additions & 1 deletion src/surface/sf_thicken.scad
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use <../__comm__/_face_normal.scad>;
use <../util/sum.scad>;
use <../util/unit_vector.scad>;
use <sf_solidify.scad>;

module sf_thicken(points, thickness, direction = "BOTH", convexity = 1) {
Expand Down Expand Up @@ -47,7 +48,7 @@ module sf_thicken(points, thickness, direction = "BOTH", convexity = 1) {
leng_point0 = len(points[0]);
x_range = [0:leng_point0 - 1];
if(is_list(direction)) {
dir_v = direction / norm(direction);
dir_v = unit_vector(direction);
dir_vs = [for(x = x_range) dir_v];
surface_another = points + thickness * [
for(y = [0:leng_points - 1])
Expand Down
3 changes: 2 additions & 1 deletion src/surface/sf_thickenT.scad
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use <../__comm__/_face_normal.scad>;
use <../util/sorted.scad>;
use <../util/sum.scad>;
use <../util/contains.scad>;
use <../util/unit_vector.scad>;
use <../surface/sf_solidifyT.scad>;
use <../triangle/tri_delaunay.scad>;

Expand All @@ -24,7 +25,7 @@ module sf_thickenT(points, thickness, triangles = undef, direction = "BOTH", con
conn_indices_tris = [for(tri = real_triangles, i = tri) [i, tri]];

if(is_list(direction)) {
dir_v = direction / norm(direction);
dir_v = unit_vector(direction);

mid_pt = sorted(points)[leng_pts / 2];
mid_i = search([mid_pt], points)[0];
Expand Down
5 changes: 2 additions & 3 deletions src/voronoi/vrn2_from.scad
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
**/

use <../matrix/m_transpose.scad>;
use <../util/unit_vector.scad>;

module vrn2_from(points, spacing = 1, r = 0, delta = 0, chamfer = false, region_type = "square") {
transposed = m_transpose(points);
Expand All @@ -18,13 +19,11 @@ module vrn2_from(points, spacing = 1, r = 0, delta = 0, chamfer = false, region_
region_size = max([max(xs) - min(xs), max(ys) - min(ys)]);
half_region_size = 0.5 * region_size;
offset_leng = spacing * 0.5 + half_region_size;

function normalize(v) = v / norm(v);

module region(pt) {
intersection_for(p = [for(p = points) if(pt != p) p]) {
v = p - pt;
translate((pt + p) / 2 - normalize(v) * offset_leng)
translate((pt + p) / 2 - unit_vector(v) * offset_leng)
rotate(atan2(v.y, v.x))
children();
}
Expand Down
6 changes: 3 additions & 3 deletions src/voronoi/vrn2_space.scad
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*
**/

use <../util/unit_vector.scad>;

module vrn2_space(size, grid_w, seed, spacing = 1, r = 0, delta = 0, chamfer = false, region_type = "square") {
function cell_pt(fcord, seed, x, y, gw, gh) =
let(
Expand All @@ -26,13 +28,11 @@ module vrn2_space(size, grid_w, seed, spacing = 1, r = 0, delta = 0, chamfer = f
region_size = grid_w * 3;
half_region_size = 0.5 * region_size;
offset_leng = (spacing + region_size) * 0.5;

function normalize(v) = v / norm(v);

module region(pt, points) {
intersection_for(p = points) {
v = p - pt;
translate((pt + p) / 2 - normalize(v) * offset_leng)
translate((pt + p) / 2 - unit_vector(v) * offset_leng)
rotate(atan2(v.y, v.x))
children();
}
Expand Down
5 changes: 2 additions & 3 deletions src/voronoi/vrn3_from.scad
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use <../__comm__/__angy_angz.scad>;
use <../matrix/m_transpose.scad>;
use <../util/unit_vector.scad>;

// slow but workable

Expand All @@ -23,14 +24,12 @@ module vrn3_from(points, spacing = 1) {
half_space_size = 0.5 * space_size;
double_space_size = 2 * space_size;
offset_leng = (spacing + space_size) * 0.5;

function normalize(v) = v / norm(v);

module space(pt) {
intersection_for(p = [for(p = points) if(pt != p) p]) {
ryz = __angy_angz(p, pt);

translate((pt + p) / 2 - normalize(p - pt) * offset_leng)
translate((pt + p) / 2 - unit_vector(p - pt) * offset_leng)
rotate([0, -ryz[0], ryz[1]])
cube([space_size, double_space_size, double_space_size], center = true);
}
Expand Down
5 changes: 2 additions & 3 deletions src/voronoi/vrn3_space.scad
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
**/

use <../__comm__/__angy_angz.scad>;
use <../util/unit_vector.scad>;

// slow but workable
module vrn3_space(size, grid_w, seed, spacing = 1) {
Expand All @@ -24,14 +25,12 @@ module vrn3_space(size, grid_w, seed, spacing = 1) {

space_size = grid_w * 3;
offset_leng = (spacing + space_size) * 0.5;

function normalize(v) = v / norm(v);

module space(pt, points) {
intersection_for(p = points) {
v = p - pt;
ryz = __angy_angz(p, pt);
translate((pt + p) / 2 - normalize(v) * offset_leng)
translate((pt + p) / 2 - unit_vector(v) * offset_leng)
rotate([0, -ryz[0], ryz[1]])
cube(space_size, center = true);
}
Expand Down

0 comments on commit 6f00785

Please sign in to comment.