mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
vector3d_angle -> vector_angle
This commit is contained in:
parent
b8c53219d5
commit
228f4c4134
5 changed files with 22 additions and 8 deletions
|
@ -154,7 +154,7 @@ function fillet3pts(p0, p1, p2, r, maxerr=0.1, w=0.5, dw=0.25) = let(
|
||||||
v0 = normalize(p0-p1),
|
v0 = normalize(p0-p1),
|
||||||
v1 = normalize(p2-p1),
|
v1 = normalize(p2-p1),
|
||||||
midv = normalize((v0+v1)/2),
|
midv = normalize((v0+v1)/2),
|
||||||
a = vector3d_angle(v0,v1),
|
a = vector_angle(v0,v1),
|
||||||
tanr = min(r/tan(a/2), norm(p0-p1)*0.99, norm(p2-p1)*0.99),
|
tanr = min(r/tan(a/2), norm(p0-p1)*0.99, norm(p2-p1)*0.99),
|
||||||
tp0 = p1+v0*tanr,
|
tp0 = p1+v0*tanr,
|
||||||
tp1 = p1+v1*tanr,
|
tp1 = p1+v1*tanr,
|
||||||
|
|
|
@ -123,7 +123,7 @@ module debug_faces(vertices, faces, size=1, disabled=false) {
|
||||||
nrm0 = normalize(cross(dv0, dv1));
|
nrm0 = normalize(cross(dv0, dv1));
|
||||||
nrm1 = [0, 0, 1];
|
nrm1 = [0, 0, 1];
|
||||||
axis = normalize(cross(nrm0, nrm1));
|
axis = normalize(cross(nrm0, nrm1));
|
||||||
ang = vector3d_angle(nrm0, nrm1);
|
ang = vector_angle(nrm0, nrm1);
|
||||||
theta = atan2(nrm0[1], nrm0[0]);
|
theta = atan2(nrm0[1], nrm0[0]);
|
||||||
translate(c) {
|
translate(c) {
|
||||||
rotate(a=180-ang, v=axis) {
|
rotate(a=180-ang, v=axis) {
|
||||||
|
|
18
math.scad
18
math.scad
|
@ -568,6 +568,7 @@ function normalize(v) = v/norm(v);
|
||||||
|
|
||||||
|
|
||||||
// Function: vector2d_angle()
|
// Function: vector2d_angle()
|
||||||
|
// Status: DEPRECATED, use `vector_angle()` instead.
|
||||||
// Usage:
|
// Usage:
|
||||||
// vector2d_angle(v1,v2);
|
// vector2d_angle(v1,v2);
|
||||||
// Description:
|
// Description:
|
||||||
|
@ -575,9 +576,11 @@ function normalize(v) = v/norm(v);
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// v1 = First 2D vector.
|
// v1 = First 2D vector.
|
||||||
// v2 = Second 2D vector.
|
// v2 = Second 2D vector.
|
||||||
function vector2d_angle(v1,v2) = atan2(v1[1],v1[0]) - atan2(v2[1],v2[0]);
|
function vector2d_angle(v1,v2) = vector_angle(v1,v2);
|
||||||
|
|
||||||
|
|
||||||
// Function: vector3d_angle()
|
// Function: vector3d_angle()
|
||||||
|
// Status: DEPRECATED, use `vector_angle()` instead.
|
||||||
// Usage:
|
// Usage:
|
||||||
// vector3d_angle(v1,v2);
|
// vector3d_angle(v1,v2);
|
||||||
// Description:
|
// Description:
|
||||||
|
@ -585,8 +588,19 @@ function vector2d_angle(v1,v2) = atan2(v1[1],v1[0]) - atan2(v2[1],v2[0]);
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// v1 = First 3D vector.
|
// v1 = First 3D vector.
|
||||||
// v2 = Second 3D vector.
|
// v2 = Second 3D vector.
|
||||||
|
function vector3d_angle(v1,v2) = vector_angle(v1,v2);
|
||||||
|
|
||||||
|
|
||||||
|
// Function: vector_angle()
|
||||||
|
// Usage:
|
||||||
|
// vector_angle(v1,v2);
|
||||||
|
// Description:
|
||||||
|
// Returns angle in degrees between two vectors of similar dimensions.
|
||||||
|
// Arguments:
|
||||||
|
// v1 = First vector.
|
||||||
|
// v2 = Second vector.
|
||||||
// NOTE: constrain() corrects crazy FP rounding errors that exceed acos()'s domain.
|
// NOTE: constrain() corrects crazy FP rounding errors that exceed acos()'s domain.
|
||||||
function vector3d_angle(v1,v2) = acos(constrain((v1*v2)/(norm(v1)*norm(v2)), -1, 1));
|
function vector_angle(v1,v2) = acos(constrain((v1*v2)/(norm(v1)*norm(v2)), -1, 1));
|
||||||
|
|
||||||
|
|
||||||
// Section: Coordinates Manipulation
|
// Section: Coordinates Manipulation
|
||||||
|
|
|
@ -85,7 +85,7 @@ function simplify3d_path(path, eps=1e-6) = concat(
|
||||||
) let (
|
) let (
|
||||||
v1 = path[i] - path[i-1],
|
v1 = path[i] - path[i-1],
|
||||||
v2 = path[i+1] - path[i-1]
|
v2 = path[i+1] - path[i-1]
|
||||||
) if (vector3d_angle(v1,v2) > eps) path[i]
|
) if (vector_angle(v1,v2) > eps) path[i]
|
||||||
],
|
],
|
||||||
[path[len(path)-1]]
|
[path[len(path)-1]]
|
||||||
);
|
);
|
||||||
|
@ -165,7 +165,7 @@ function points_along_path3d(
|
||||||
v2 = (n == end)? normalize(path[n]-path[n-1]) : normalize(path[n+1]-path[n]),
|
v2 = (n == end)? normalize(path[n]-path[n-1]) : normalize(path[n+1]-path[n]),
|
||||||
crs = cross(v1, v2),
|
crs = cross(v1, v2),
|
||||||
axis = norm(crs) <= 0.001? [0, 0, 1] : crs,
|
axis = norm(crs) <= 0.001? [0, 0, 1] : crs,
|
||||||
ang = vector3d_angle(v1, v2),
|
ang = vector_angle(v1, v2),
|
||||||
hang = ang * (n==0? 1.0 : 0.5),
|
hang = ang * (n==0? 1.0 : 0.5),
|
||||||
hrot = Quat(axis, hang),
|
hrot = Quat(axis, hang),
|
||||||
arot = Quat(axis, ang),
|
arot = Quat(axis, ang),
|
||||||
|
@ -376,7 +376,7 @@ module extrude_2dpath_along_3dpath(polyline, path, ang=0, convexity=10) {
|
||||||
module extrude_2d_shapes_along_3dpath(path, convexity=10, clipsize=100) {
|
module extrude_2d_shapes_along_3dpath(path, convexity=10, clipsize=100) {
|
||||||
function polyquats(path, q=Q_Ident(), v=[0,0,1], i=0) = let(
|
function polyquats(path, q=Q_Ident(), v=[0,0,1], i=0) = let(
|
||||||
v2 = path[i+1] - path[i],
|
v2 = path[i+1] - path[i],
|
||||||
ang = vector3d_angle(v,v2),
|
ang = vector_angle(v,v2),
|
||||||
axis = ang>0.001? normalize(cross(v,v2)) : [0,0,1],
|
axis = ang>0.001? normalize(cross(v,v2)) : [0,0,1],
|
||||||
newq = Q_Mul(Quat(axis, ang), q),
|
newq = Q_Mul(Quat(axis, ang), q),
|
||||||
dist = norm(v2)
|
dist = norm(v2)
|
||||||
|
|
|
@ -289,7 +289,7 @@ module rot(a=0, v=undef, cp=undef, from=undef, to=undef, reverse=false)
|
||||||
V_RIGHT
|
V_RIGHT
|
||||||
);
|
);
|
||||||
axis = normalize(cross(vv1, vv3));
|
axis = normalize(cross(vv1, vv3));
|
||||||
ang = vector3d_angle(vv1, vv2);
|
ang = vector_angle(vv1, vv2);
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
rotate(a=-ang, v=axis) rotate(a=-a, v=vv1) children();
|
rotate(a=-ang, v=axis) rotate(a=-a, v=vv1) children();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue