mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-14 02:34:12 +02:00
use unit_vector
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
function _face_normal(points) =
|
use <../util/unit_vector.scad>;
|
||||||
let(v = cross(points[2] - points[0], points[1] - points[0])) v / norm(v);
|
|
||||||
|
|
||||||
|
function _face_normal(points) = unit_vector(cross(points[2] - points[0], points[1] - points[0]));
|
@@ -1,11 +1,9 @@
|
|||||||
use <../__comm__/__lines_from.scad>;
|
use <../__comm__/__lines_from.scad>;
|
||||||
use <../__comm__/__line_intersection.scad>;
|
use <../__comm__/__line_intersection.scad>;
|
||||||
|
use <../util/unit_vector.scad>;
|
||||||
|
|
||||||
function _outward_edge_normal(edge) =
|
function _outward_edge_normal(edge) =
|
||||||
let(
|
let(nv = unit_vector(edge[1] - edge[0]))
|
||||||
v = edge[1] - edge[0],
|
|
||||||
nv = v / norm(v)
|
|
||||||
)
|
|
||||||
[nv.y, -nv.x];
|
[nv.y, -nv.x];
|
||||||
|
|
||||||
function _edge(edge, dxy) = edge + [dxy, dxy];
|
function _edge(edge, dxy) = edge + [dxy, dxy];
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
use <../../util/unit_vector.scad>;
|
||||||
|
|
||||||
function _tri_subdivide_pts(points, radius, rows) =
|
function _tri_subdivide_pts(points, radius, rows) =
|
||||||
let(
|
let(
|
||||||
p0 = points[0],
|
p0 = points[0],
|
||||||
@@ -5,8 +7,7 @@ function _tri_subdivide_pts(points, radius, rows) =
|
|||||||
)
|
)
|
||||||
[
|
[
|
||||||
for(ri = [0:rows], ci = [0:rows - ri])
|
for(ri = [0:rows], ci = [0:rows - ri])
|
||||||
let(p = p0 + [ri, ci] * basis)
|
radius * unit_vector(p0 + [ri, ci] * basis)
|
||||||
radius * p / norm(p)
|
|
||||||
];
|
];
|
||||||
|
|
||||||
function _tri_subdivide_faces(rows) =
|
function _tri_subdivide_faces(rows) =
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
use <../../__comm__/__to2d.scad>;
|
use <../../__comm__/__to2d.scad>;
|
||||||
use <../../__comm__/__to3d.scad>;
|
use <../../__comm__/__to3d.scad>;
|
||||||
use <../../__comm__/__to_ang_vect.scad>;
|
use <../../__comm__/__to_ang_vect.scad>;
|
||||||
|
use <../../util/unit_vector.scad>;
|
||||||
|
|
||||||
function _q_rotate_p_3d(p, a, v) =
|
function _q_rotate_p_3d(p, a, v) =
|
||||||
let(
|
let(
|
||||||
uv = v / norm(v),
|
uv = unit_vector(v),
|
||||||
s = sin(a / 2) * uv,
|
s = sin(a / 2) * uv,
|
||||||
w = sin(a) * uv,
|
w = sin(a) * uv,
|
||||||
|
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
use <_impl/_sf_square_surfaces.scad>;
|
use <_impl/_sf_square_surfaces.scad>;
|
||||||
|
use <../util/unit_vector.scad>;
|
||||||
use <sf_solidify.scad>;
|
use <sf_solidify.scad>;
|
||||||
|
|
||||||
module sf_curve(levels, curve_path, thickness, depth, invert = false, convexity = 1) {
|
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);
|
m = __ry_matrix(-90);
|
||||||
normal_vts = [
|
normal_vts = [for(i = [0:columns - 1]) unit_vector(pts[i + 1] - pts[i]) * m];
|
||||||
for(i = [0:columns - 1])
|
|
||||||
let(v = pts[i + 1] - pts[i])
|
|
||||||
v / norm(v) * m
|
|
||||||
];
|
|
||||||
|
|
||||||
dp = is_undef(depth) ? thickness / 2 : depth;
|
dp = is_undef(depth) ? thickness / 2 : depth;
|
||||||
surfaces = _sf_square_surfaces(levels, thickness, dp, invert);
|
surfaces = _sf_square_surfaces(levels, thickness, dp, invert);
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
use <../__comm__/_face_normal.scad>;
|
use <../__comm__/_face_normal.scad>;
|
||||||
use <../util/sum.scad>;
|
use <../util/sum.scad>;
|
||||||
|
use <../util/unit_vector.scad>;
|
||||||
use <sf_solidify.scad>;
|
use <sf_solidify.scad>;
|
||||||
|
|
||||||
module sf_thicken(points, thickness, direction = "BOTH", convexity = 1) {
|
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]);
|
leng_point0 = len(points[0]);
|
||||||
x_range = [0:leng_point0 - 1];
|
x_range = [0:leng_point0 - 1];
|
||||||
if(is_list(direction)) {
|
if(is_list(direction)) {
|
||||||
dir_v = direction / norm(direction);
|
dir_v = unit_vector(direction);
|
||||||
dir_vs = [for(x = x_range) dir_v];
|
dir_vs = [for(x = x_range) dir_v];
|
||||||
surface_another = points + thickness * [
|
surface_another = points + thickness * [
|
||||||
for(y = [0:leng_points - 1])
|
for(y = [0:leng_points - 1])
|
||||||
|
@@ -13,6 +13,7 @@ use <../__comm__/_face_normal.scad>;
|
|||||||
use <../util/sorted.scad>;
|
use <../util/sorted.scad>;
|
||||||
use <../util/sum.scad>;
|
use <../util/sum.scad>;
|
||||||
use <../util/contains.scad>;
|
use <../util/contains.scad>;
|
||||||
|
use <../util/unit_vector.scad>;
|
||||||
use <../surface/sf_solidifyT.scad>;
|
use <../surface/sf_solidifyT.scad>;
|
||||||
use <../triangle/tri_delaunay.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]];
|
conn_indices_tris = [for(tri = real_triangles, i = tri) [i, tri]];
|
||||||
|
|
||||||
if(is_list(direction)) {
|
if(is_list(direction)) {
|
||||||
dir_v = direction / norm(direction);
|
dir_v = unit_vector(direction);
|
||||||
|
|
||||||
mid_pt = sorted(points)[leng_pts / 2];
|
mid_pt = sorted(points)[leng_pts / 2];
|
||||||
mid_i = search([mid_pt], points)[0];
|
mid_i = search([mid_pt], points)[0];
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
use <../matrix/m_transpose.scad>;
|
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") {
|
module vrn2_from(points, spacing = 1, r = 0, delta = 0, chamfer = false, region_type = "square") {
|
||||||
transposed = m_transpose(points);
|
transposed = m_transpose(points);
|
||||||
@@ -19,12 +20,10 @@ module vrn2_from(points, spacing = 1, r = 0, delta = 0, chamfer = false, region_
|
|||||||
half_region_size = 0.5 * region_size;
|
half_region_size = 0.5 * region_size;
|
||||||
offset_leng = spacing * 0.5 + half_region_size;
|
offset_leng = spacing * 0.5 + half_region_size;
|
||||||
|
|
||||||
function normalize(v) = v / norm(v);
|
|
||||||
|
|
||||||
module region(pt) {
|
module region(pt) {
|
||||||
intersection_for(p = [for(p = points) if(pt != p) p]) {
|
intersection_for(p = [for(p = points) if(pt != p) p]) {
|
||||||
v = p - pt;
|
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))
|
rotate(atan2(v.y, v.x))
|
||||||
children();
|
children();
|
||||||
}
|
}
|
||||||
|
@@ -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") {
|
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) =
|
function cell_pt(fcord, seed, x, y, gw, gh) =
|
||||||
let(
|
let(
|
||||||
@@ -27,12 +29,10 @@ module vrn2_space(size, grid_w, seed, spacing = 1, r = 0, delta = 0, chamfer = f
|
|||||||
half_region_size = 0.5 * region_size;
|
half_region_size = 0.5 * region_size;
|
||||||
offset_leng = (spacing + region_size) * 0.5;
|
offset_leng = (spacing + region_size) * 0.5;
|
||||||
|
|
||||||
function normalize(v) = v / norm(v);
|
|
||||||
|
|
||||||
module region(pt, points) {
|
module region(pt, points) {
|
||||||
intersection_for(p = points) {
|
intersection_for(p = points) {
|
||||||
v = p - pt;
|
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))
|
rotate(atan2(v.y, v.x))
|
||||||
children();
|
children();
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
use <../__comm__/__angy_angz.scad>;
|
use <../__comm__/__angy_angz.scad>;
|
||||||
use <../matrix/m_transpose.scad>;
|
use <../matrix/m_transpose.scad>;
|
||||||
|
use <../util/unit_vector.scad>;
|
||||||
|
|
||||||
// slow but workable
|
// slow but workable
|
||||||
|
|
||||||
@@ -24,13 +25,11 @@ module vrn3_from(points, spacing = 1) {
|
|||||||
double_space_size = 2 * space_size;
|
double_space_size = 2 * space_size;
|
||||||
offset_leng = (spacing + space_size) * 0.5;
|
offset_leng = (spacing + space_size) * 0.5;
|
||||||
|
|
||||||
function normalize(v) = v / norm(v);
|
|
||||||
|
|
||||||
module space(pt) {
|
module space(pt) {
|
||||||
intersection_for(p = [for(p = points) if(pt != p) p]) {
|
intersection_for(p = [for(p = points) if(pt != p) p]) {
|
||||||
ryz = __angy_angz(p, pt);
|
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]])
|
rotate([0, -ryz[0], ryz[1]])
|
||||||
cube([space_size, double_space_size, double_space_size], center = true);
|
cube([space_size, double_space_size, double_space_size], center = true);
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
use <../__comm__/__angy_angz.scad>;
|
use <../__comm__/__angy_angz.scad>;
|
||||||
|
use <../util/unit_vector.scad>;
|
||||||
|
|
||||||
// slow but workable
|
// slow but workable
|
||||||
module vrn3_space(size, grid_w, seed, spacing = 1) {
|
module vrn3_space(size, grid_w, seed, spacing = 1) {
|
||||||
@@ -25,13 +26,11 @@ module vrn3_space(size, grid_w, seed, spacing = 1) {
|
|||||||
space_size = grid_w * 3;
|
space_size = grid_w * 3;
|
||||||
offset_leng = (spacing + space_size) * 0.5;
|
offset_leng = (spacing + space_size) * 0.5;
|
||||||
|
|
||||||
function normalize(v) = v / norm(v);
|
|
||||||
|
|
||||||
module space(pt, points) {
|
module space(pt, points) {
|
||||||
intersection_for(p = points) {
|
intersection_for(p = points) {
|
||||||
v = p - pt;
|
v = p - pt;
|
||||||
ryz = __angy_angz(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]])
|
rotate([0, -ryz[0], ryz[1]])
|
||||||
cube(space_size, center = true);
|
cube(space_size, center = true);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user