mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-14 02:34:12 +02:00
refactor: use norm
This commit is contained in:
@@ -14,8 +14,9 @@ use <__comm__/__nearest_multiple_of_4.scad>;
|
|||||||
module line2d(p1, p2, width = 1, p1Style = "CAP_SQUARE", p2Style = "CAP_SQUARE") {
|
module line2d(p1, p2, width = 1, p1Style = "CAP_SQUARE", p2Style = "CAP_SQUARE") {
|
||||||
half_width = 0.5 * width;
|
half_width = 0.5 * width;
|
||||||
|
|
||||||
atan_angle = atan2(p2.y - p1.y, p2.x - p1.x);
|
v = p2 - p1;
|
||||||
leng = sqrt(pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2));
|
atan_angle = atan2(v.y, v.x);
|
||||||
|
leng = norm(v);
|
||||||
|
|
||||||
frags = __nearest_multiple_of_4(__frags(half_width));
|
frags = __nearest_multiple_of_4(__frags(half_width));
|
||||||
|
|
||||||
|
@@ -17,13 +17,10 @@ module line3d(p1, p2, diameter = 1, p1Style = "CAP_CIRCLE", p2Style = "CAP_CIRCL
|
|||||||
frags = __nearest_multiple_of_4(__frags(r));
|
frags = __nearest_multiple_of_4(__frags(r));
|
||||||
half_fa = 180 / frags;
|
half_fa = 180 / frags;
|
||||||
|
|
||||||
dx = p2.x - p1.x;
|
v = p2 - p1;
|
||||||
dy = p2.y - p1.y;
|
length = norm(v);
|
||||||
dz = p2.z - p1.z;
|
ay = 90 - atan2(v.z, norm([v.x, v.y]));
|
||||||
|
az = atan2(v.y, v.x);
|
||||||
length = sqrt(pow(dx, 2) + pow(dy, 2) + pow(dz, 2));
|
|
||||||
ay = 90 - atan2(dz, sqrt(pow(dx, 2) + pow(dy, 2)));
|
|
||||||
az = atan2(dy, dx);
|
|
||||||
|
|
||||||
angles = [0, ay, az];
|
angles = [0, ay, az];
|
||||||
|
|
||||||
@@ -35,8 +32,8 @@ module line3d(p1, p2, diameter = 1, p1Style = "CAP_CIRCLE", p2Style = "CAP_CIRCL
|
|||||||
|
|
||||||
module cap_butt() {
|
module cap_butt() {
|
||||||
cap_with(p1)
|
cap_with(p1)
|
||||||
linear_extrude(length)
|
linear_extrude(length)
|
||||||
circle(r, $fn = frags);
|
circle(r, $fn = frags);
|
||||||
|
|
||||||
// hook for testing
|
// hook for testing
|
||||||
test_line3d_butt(p1, r, frags, length, angles);
|
test_line3d_butt(p1, r, frags, length, angles);
|
||||||
|
Reference in New Issue
Block a user