1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-11 01:04:07 +02:00

use unit_vector

This commit is contained in:
Justin Lin
2022-05-16 17:06:16 +08:00
parent be53dd21c1
commit 6f00785d6c
11 changed files with 26 additions and 30 deletions

View File

@@ -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]));

View File

@@ -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];

View File

@@ -1,3 +1,5 @@
use <../../util/unit_vector.scad>;
function _tri_subdivide_pts(points, radius, rows) =
let(
p0 = points[0],
@@ -5,8 +7,7 @@ function _tri_subdivide_pts(points, radius, 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) =

View File

@@ -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,

View File

@@ -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) {
@@ -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);

View File

@@ -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) {
@@ -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])

View File

@@ -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>;
@@ -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];

View File

@@ -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);
@@ -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();
}

View File

@@ -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(
@@ -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();
}

View File

@@ -10,6 +10,7 @@
use <../__comm__/__angy_angz.scad>;
use <../matrix/m_transpose.scad>;
use <../util/unit_vector.scad>;
// slow but workable
@@ -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);
}

View File

@@ -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) {
@@ -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);
}