mirror of
https://github.com/nophead/NopSCADlib.git
synced 2025-08-11 01:44:01 +02:00
replaced the new math functions with rotate and transform
This commit is contained in:
@@ -59,9 +59,9 @@ module dimension(startpoint, endpoint, text = "", thickness = 0.1) {
|
||||
|
||||
// Draw the text/distance
|
||||
dir = (length > 0) ? (direction / length) * thickness * 4 : [1, 0, 0];
|
||||
up_dir = rotate_vector_3d([0,1,0], [0,0,1] ,azimuth);
|
||||
up_dir = transform([0,1,0], rotate(azimuth));
|
||||
|
||||
translate(midpoint + up_dir*0.66)
|
||||
translate(midpoint + up_dir*thickness)
|
||||
rotate([0, elevation, azimuth])
|
||||
linear_extrude(thickness)
|
||||
text(text == "" ? str(length) : text, size = thickness * 5, valign = "bottom", halign = "center");
|
||||
|
@@ -190,28 +190,4 @@ function cubic_real_roots(a, b, c, d) = //! Returns real roots of cubic equation
|
||||
|
||||
function path_length(path, i = 0, length = 0) = //! Calculated the length along a path
|
||||
i >= len(path) - 1 ? length
|
||||
: path_length(path, i + 1, length + norm(path[i + 1] - path[i]));
|
||||
|
||||
function rotate_vector_2d(v, angle) = [
|
||||
v[0] * cos(angle) - v[1] * sin(angle),
|
||||
v[0] * sin(angle) + v[1] * cos(angle)
|
||||
];
|
||||
|
||||
function rotation_matrix(axis, angle) = let(
|
||||
u = axis / norm(axis), // Normalize axis
|
||||
ux = u[0], uy = u[1], uz = u[2],
|
||||
cosA = cos(angle), sinA = sin(angle),
|
||||
one_minus_cosA = 1 - cosA
|
||||
) [
|
||||
[cosA + ux*ux*one_minus_cosA, ux*uy*one_minus_cosA - uz*sinA, ux*uz*one_minus_cosA + uy*sinA],
|
||||
[uy*ux*one_minus_cosA + uz*sinA, cosA + uy*uy*one_minus_cosA, uy*uz*one_minus_cosA - ux*sinA],
|
||||
[uz*ux*one_minus_cosA - uy*sinA, uz*uy*one_minus_cosA + ux*sinA, cosA + uz*uz*one_minus_cosA]
|
||||
];
|
||||
|
||||
function rotate_vector_3d(v, axis, angle) = let(
|
||||
mat = rotation_matrix(axis, angle)
|
||||
) [
|
||||
mat[0][0]*v[0] + mat[0][1]*v[1] + mat[0][2]*v[2],
|
||||
mat[1][0]*v[0] + mat[1][1]*v[1] + mat[1][2]*v[2],
|
||||
mat[2][0]*v[0] + mat[2][1]*v[1] + mat[2][2]*v[2]
|
||||
];
|
||||
: path_length(path, i + 1, length + norm(path[i + 1] - path[i]));
|
Reference in New Issue
Block a user