mirror of
https://github.com/nophead/NopSCADlib.git
synced 2025-08-25 16:31:01 +02:00
Shortened the module comments by factoring out the parameter discriptions.
Added the nut example picture. Fixed nut picture placement. Updated images and readme.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// NopSCADlib Copyright Chris Palmer 2018
|
||||
// NopSCADlib Copyright Chris Palmer 2025
|
||||
// nop.head@gmail.com
|
||||
// hydraraptor.blogspot.com
|
||||
//
|
||||
@@ -17,13 +17,20 @@
|
||||
// If not, see <https://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
//
|
||||
//! Modules for adding dimensions to assembly views.
|
||||
//!
|
||||
//! <img src="docs/sliding_t_nut.png" width="500", height="378">
|
||||
//!
|
||||
//! * If `text` is empty, will display the measured distance.
|
||||
//! * `offset` will determine how much space is between the measured point and the dimension.
|
||||
//! * `thickness` is the thickness of the lines, and size of the arrows, if 0, will use 0.5% of the length of the dim.
|
||||
//! * `text_size` will determine the size of the text, if 0, will use percentage of the length of the dim.
|
||||
|
||||
include <../utils/core/core.scad>
|
||||
include <../utils/maths.scad>
|
||||
|
||||
|
||||
|
||||
|
||||
module dimension(startpoint, endpoint, text = "", thickness = 0, text_size = 0 , rot_around_dim=0) { //! Will create a 3D dimension between two points. If text is empty, will display the measured distance. Thickness will determine the thickness of the lines, and size of the arrows, if 0, will use 0.5% of the length of the dim. Text_size will determine the size of the text, if 0, will use percentage of the length of the dim
|
||||
module dimension(startpoint, endpoint, text = "", thickness = 0, text_size = 0 , rot_around_dim = 0) { //! Creates a 3D dimension between two points.
|
||||
// Compute vector between points
|
||||
direction = endpoint - startpoint;
|
||||
length = norm(direction);
|
||||
@@ -34,9 +41,9 @@ module dimension(startpoint, endpoint, text = "", thickness = 0, text_size = 0 ,
|
||||
dir_xy = norm([direction.x, direction.y]);
|
||||
|
||||
// Compute rotation angles
|
||||
azimuth = atan2(direction.y, direction.x);
|
||||
azimuth = atan2(direction.y, direction.x);
|
||||
elevation = -atan2(direction.z, dir_xy);
|
||||
|
||||
|
||||
//end triangle size
|
||||
etr_width = thickness *10;
|
||||
etr_height = thickness *4;
|
||||
@@ -44,32 +51,32 @@ module dimension(startpoint, endpoint, text = "", thickness = 0, text_size = 0 ,
|
||||
// Draw measurement line as a thin cylinder
|
||||
translate(midpoint)
|
||||
rotate([0, elevation, azimuth])
|
||||
rotate([0, 90, 0])
|
||||
rotate([0, 90, 0])
|
||||
resize([thickness, thickness, length - etr_width+0.01 ])
|
||||
cube(center = true);
|
||||
|
||||
|
||||
//do some vector calculations
|
||||
dir = (length > 0) ? (direction / length) * thickness * 4 : [1, 0, 0];
|
||||
dir = (length > 0) ? (direction / length) * thickness * 4 : [1, 0, 0];
|
||||
|
||||
// Draw endpoint markers
|
||||
translate(startpoint)
|
||||
rotate([0, elevation, azimuth])
|
||||
translate(startpoint)
|
||||
rotate([0, elevation, azimuth])
|
||||
rotate([rot_around_dim,0,0])
|
||||
translate([0,0,-thickness/2])
|
||||
linear_extrude(thickness)
|
||||
polygon([[etr_width, etr_height/2],[0,0],[etr_width, -etr_height/2]],[[0,1,2]]);
|
||||
|
||||
translate(endpoint)
|
||||
rotate([0, elevation, azimuth])
|
||||
|
||||
translate(endpoint)
|
||||
rotate([0, elevation, azimuth])
|
||||
rotate([rot_around_dim,0,0])
|
||||
translate([0,0,-thickness/2])
|
||||
linear_extrude(thickness)
|
||||
polygon([[-etr_width, etr_height/2],[0,0],[-etr_width, -etr_height/2]],[[0,1,2]]);
|
||||
|
||||
|
||||
|
||||
// Draw the text/distance
|
||||
translate(midpoint)
|
||||
rotate([0, elevation, azimuth])
|
||||
rotate([0, elevation, azimuth])
|
||||
rotate([rot_around_dim,0,0])
|
||||
translate([0,thickness,-thickness/2])
|
||||
linear_extrude(thickness)
|
||||
@@ -77,36 +84,36 @@ module dimension(startpoint, endpoint, text = "", thickness = 0, text_size = 0 ,
|
||||
}
|
||||
|
||||
|
||||
module dimension_x(startpoint, endpoint, offset = 1, text = "", thickness = 0, text_size = 0 , plane = "xy") { //! Will create a dimension in the x direction. Offset will determine how much space is between the measured point and the dimension. Plane options : xy, xz
|
||||
module dimension_x(startpoint, endpoint, offset = 1, text = "", thickness = 0, text_size = 0 , plane = "xy") { //! Creates a dimension in the x direction. Plane options : xy, xz
|
||||
length = norm(endpoint - startpoint);
|
||||
thickness = (thickness == 0? length/200:thickness);
|
||||
|
||||
y = offset > 0 ? max(startpoint.y, endpoint.y) + (plane=="xy"?offset:0) : min(startpoint.y, endpoint.y) + (plane=="xy"?offset:0);
|
||||
z = offset > 0 ? max(startpoint.z, endpoint.z) + (plane=="xz"?offset:0) : min(startpoint.z, endpoint.z) + (plane=="xz"?offset:0);
|
||||
|
||||
dimension([startpoint.x, y, z], [endpoint.x, y, z], text, thickness, text_size, rot_around_dim=(plane=="xz"?90:0));
|
||||
|
||||
|
||||
dimension([startpoint.x, y, z], [endpoint.x, y, z], text, thickness, text_size, rot_around_dim=(plane=="xz"?90:0));
|
||||
|
||||
v1= [startpoint.x, y, z]-startpoint;
|
||||
h1 = norm(v1);
|
||||
axis1 = cross([0,0,1], v1);
|
||||
angle1 = atan2(norm(axis1), v1.z);
|
||||
angle1 = atan2(norm(axis1), v1.z);
|
||||
translate(startpoint)
|
||||
rotate(angle1, axis1)
|
||||
cylinder( h= h1+thickness*2, d=thickness);
|
||||
|
||||
|
||||
|
||||
|
||||
v2= [endpoint.x, y, z]-endpoint;
|
||||
h2 = norm(v2);
|
||||
axis2 = cross([0,0,1], v2);
|
||||
angle2 = atan2(norm(axis2), v2.z);
|
||||
|
||||
|
||||
translate(endpoint)
|
||||
rotate(angle2, axis2)
|
||||
cylinder( h= h2+thickness*2, d=thickness);
|
||||
cylinder( h= h2+thickness*2, d=thickness);
|
||||
}
|
||||
|
||||
|
||||
module dimension_y(startpoint, endpoint, offset = 1, text = "", thickness = 0, text_size = 0 , plane = "xy") { //! Will create a dimension in the y direction. Offset will determine how much space is between the measured point and the dimension. Plane options : xy, yz
|
||||
module dimension_y(startpoint, endpoint, offset = 1, text = "", thickness = 0, text_size = 0 , plane = "xy") { //! Creates a dimension in the y direction. Plane options : xy, yz
|
||||
length = norm(endpoint - startpoint);
|
||||
thickness = (thickness == 0? length/200:thickness);
|
||||
|
||||
@@ -114,30 +121,30 @@ module dimension_y(startpoint, endpoint, offset = 1, text = "", thickness = 0, t
|
||||
x = offset > 0 ? max(startpoint.x, endpoint.x) + (plane=="xy"?offset:0) : min(startpoint.x, endpoint.x) + (plane=="xy"?offset:0);
|
||||
z = offset > 0 ? max(startpoint.z, endpoint.z) + (plane=="yz"?offset:0) : min(startpoint.z, endpoint.z) + (plane=="yz"?offset:0);
|
||||
dimension([x, startpoint.y, z], [x, endpoint.y, z], text, thickness, text_size, rot_around_dim=(plane=="yz"?90:0));
|
||||
|
||||
|
||||
v1= [x, startpoint.y, z]-startpoint;
|
||||
h1 = norm(v1);
|
||||
axis1 = cross([0,0,1], v1);
|
||||
angle1 = atan2(norm(axis1), v1.z);
|
||||
|
||||
|
||||
translate(startpoint)
|
||||
rotate(angle1, axis1)
|
||||
rotate([offset>0?0:180,0,0])
|
||||
cylinder( h= h1+thickness*2, d=thickness);
|
||||
|
||||
|
||||
|
||||
|
||||
v2= [x, endpoint.y, z]-endpoint;
|
||||
h2 = norm(v2);
|
||||
axis2 = cross([0,0,1], v2);
|
||||
angle2 = atan2(norm(axis2), v2.z);
|
||||
|
||||
|
||||
translate(endpoint)
|
||||
rotate(angle2, axis2)
|
||||
rotate([offset>0?0:180,0,0])
|
||||
cylinder( h= h2+thickness*2, d=thickness);
|
||||
cylinder( h= h2+thickness*2, d=thickness);
|
||||
}
|
||||
|
||||
module dimension_z(startpoint, endpoint, offset = 1, text = "", thickness = 0, text_size = 0 , plane = "xz") { //! Will create a dimension in the z direction. Offset will determine how much space is between the measured point and the dimension. Plane options : xz, yz
|
||||
module dimension_z(startpoint, endpoint, offset = 1, text = "", thickness = 0, text_size = 0 , plane = "xz") { //! Creates a dimension in the z direction. Plane options : xz, yz
|
||||
length = norm(endpoint - startpoint);
|
||||
thickness = (thickness == 0? length/200:thickness);
|
||||
|
||||
@@ -145,27 +152,23 @@ module dimension_z(startpoint, endpoint, offset = 1, text = "", thickness = 0, t
|
||||
x = offset > 0 ? max(startpoint.x, endpoint.x) + (plane=="xz"?offset:0) : min(startpoint.x, endpoint.x) + (plane=="xz"?offset:0);
|
||||
y = offset > 0 ? max(startpoint.y, endpoint.y) + (plane=="yz"?offset:0) : min(startpoint.y, endpoint.y) + (plane=="yz"?offset:0);
|
||||
dimension([x, y, startpoint.z], [x, y, endpoint.z], text, thickness, text_size, rot_around_dim=(plane=="xz"?90:0));
|
||||
|
||||
|
||||
v1= [x, y, startpoint.z]-startpoint;
|
||||
h1 = norm(v1);
|
||||
axis1 = cross([0,0,1], v1);
|
||||
angle1 = atan2(norm(axis1), v1.z);
|
||||
|
||||
|
||||
translate(startpoint)
|
||||
rotate(angle1, axis1)
|
||||
cylinder( h= h1+thickness*2, d=thickness);
|
||||
|
||||
|
||||
|
||||
|
||||
v2= [x, y, endpoint.z]-endpoint;
|
||||
h2 = norm(v2);
|
||||
axis2 = cross([0,0,1], v2);
|
||||
angle2 = atan2(norm(axis2), v2.z);
|
||||
|
||||
|
||||
translate(endpoint)
|
||||
rotate(angle2, axis2)
|
||||
cylinder( h= h2+thickness*2, d=thickness);
|
||||
cylinder( h= h2+thickness*2, d=thickness);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -190,4 +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]));
|
||||
: path_length(path, i + 1, length + norm(path[i + 1] - path[i]));
|
||||
|
Reference in New Issue
Block a user