1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-08-09 17:06:34 +02:00

added argument for text size, and improve auto size

This commit is contained in:
Alex Verschoot
2025-03-15 22:19:12 +01:00
parent 106666ec49
commit 8992cce7a6
2 changed files with 45 additions and 34 deletions

View File

@@ -23,32 +23,32 @@ use <../utils/dimension.scad>
module dimensions_3d_xy() { module dimensions_3d_xy() {
dimension([0,0,0], [10,10,0], "", 0.2); dimension([0,0,0], [10,10,0], "", 0.2);
dimension([0,0,0], [10,-10,0], "", 0.2); dimension([0,0,0], [10,-10,0], "", 0.2);
dimension([0,0,0], [-10,10,0], "", 0.2); dimension([0,0,0], [-10,10,0], "");
dimension([0,0,0], [-10,-10,0], "", 0.2); dimension([0,0,0], [-10,-10,0], "");
dimension([0,0,0], [0,10,0], "", 0.2); dimension([0,0,0], [0,10,0], "");
dimension([0,0,0], [0,-10,0], "", 0.2); dimension([0,0,0], [0,-10,0], "");
dimension([0,0,0], [10,0,0], "", 0.2,rot_around_dim=0); dimension([0,0,0], [10,0,0], "",rot_around_dim=0);
dimension([0,0,0], [-10,0,0], "", 0.2, rot_around_dim=90); dimension([0,0,0], [-10,0,0], "", rot_around_dim=90);
} }
module dimensions_3d_xyz() { module dimensions_3d_xyz() {
dimension([0,0,0], [10,10,10], "", 0.2); dimension([0,0,0], [10,10,10], "");
dimension([0,0,0], [10,-10,10], "", 0.2); dimension([0,0,0], [10,-10,10], "");
dimension([0,0,0], [-10,10,10], "", 0.2); dimension([0,0,0], [-10,10,10], "");
dimension([0,0,0], [-10,-10,10], "", 0.2); dimension([0,0,0], [-10,-10,10], "");
dimension([0,0,0], [10,10,-10], "", 0.2); dimension([0,0,0], [10,10,-10], "");
dimension([0,0,0], [10,-10,-10], "", 0.2); dimension([0,0,0], [10,-10,-10], "");
dimension([0,0,0], [-10,10,-10], "", 0.2); dimension([0,0,0], [-10,10,-10], "");
dimension([0,0,0], [-10,-10,-10], "", 0.2, rot_around_dim=45); dimension([0,0,0], [-10,-10,-10], "", rot_around_dim=45);
dimension([0,0,0], [-3,0,10], "", 0.2); dimension([0,0,0], [-3,0,10], "");
dimension([0,0,0], [0,0,-10], "", 0.2); dimension([0,0,0], [0,0,-10], "");
dimension([0,0,0], [0,2,10], "", 0.2); dimension([0,0,0], [0,2,10], "");
dimension([0,0,0], [0,2,-10], "", 0.2); dimension([0,0,0], [0,2,-10], "");
} }
@@ -72,8 +72,8 @@ module dimension_1d_z() {
} }
if($preview) if($preview)
//dimensions_3d_xy(); dimensions_3d_xy();
//dimensions_3d_xyz(); dimensions_3d_xyz();
dimension_1d_x(); dimension_1d_x();
dimension_1d_y(); dimension_1d_y();
dimension_1d_z(); dimension_1d_z();

View File

@@ -17,21 +17,20 @@
// If not, see <https://www.gnu.org/licenses/>. // If not, see <https://www.gnu.org/licenses/>.
// //
//
//! Annotation used in this documentation
//
include <../utils/core/core.scad> include <../utils/core/core.scad>
include <../utils/maths.scad> include <../utils/maths.scad>
//if text is empty, will display the number value //if text is empty, will display the number value
module dimension(startpoint, endpoint, text = "", thickness = 0.1, rot_around_dim=0) { //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) {
// Compute vector between points // Compute vector between points
direction = endpoint - startpoint; direction = endpoint - startpoint;
length = norm(direction); length = norm(direction);
midpoint = (startpoint + endpoint) / 2; midpoint = (startpoint + endpoint) / 2;
thickness = (thickness == 0? length/200:thickness);
// Ensure nonzero values for calculations // Ensure nonzero values for calculations
dir_xy = norm([direction.x, direction.y]); dir_xy = norm([direction.x, direction.y]);
@@ -41,8 +40,8 @@ module dimension(startpoint, endpoint, text = "", thickness = 0.1, rot_around_di
elevation = -atan2(direction.z, dir_xy); elevation = -atan2(direction.z, dir_xy);
//end triangle size //end triangle size
etr_width = thickness *5; etr_width = thickness *10;
etr_height = thickness *3; etr_height = thickness *4;
// Draw measurement line as a thin cylinder // Draw measurement line as a thin cylinder
translate(midpoint) translate(midpoint)
@@ -78,17 +77,21 @@ module dimension(startpoint, endpoint, text = "", thickness = 0.1, rot_around_di
rotate([rot_around_dim,0,0]) rotate([rot_around_dim,0,0])
translate([0,thickness,-thickness/2]) translate([0,thickness,-thickness/2])
linear_extrude(thickness) linear_extrude(thickness)
text(text == "" ? str(length) : text, size = thickness * 5, valign = "bottom", halign = "center"); text(text == "" ? str(length) : text, size = (text_size == 0? length/15:text_size), valign = "bottom", halign = "center");
} }
//offset will detirmine how much space is between the measured point and the dimension //offset will detirmine how much space is between the measured point and the dimension
//for x, this offset will be in the y direction //for x, this offset will be in the y direction
//plane options : xy, xz //plane options : xy, xz
module dimension_x(startpoint, endpoint, offset = 1, text = "", thickness = 0.1, plane = "xy") { module dimension_x(startpoint, endpoint, offset = 1, text = "", thickness = 0, text_size = 0 , plane = "xy") {
length = norm(endpoint - startpoint);
thickness = (thickness == 0? length/200:thickness);
y = max(startpoint.y, endpoint.y) + (plane=="xy"?offset:0); y = max(startpoint.y, endpoint.y) + (plane=="xy"?offset:0);
z = max(startpoint.z, endpoint.z) + (plane=="xz"?offset:0); z = max(startpoint.z, endpoint.z) + (plane=="xz"?offset:0);
dimension([startpoint.x, y, z], [endpoint.x, y, z], text, thickness, 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; v1= [startpoint.x, y, z]-startpoint;
h1 = norm(v1); h1 = norm(v1);
@@ -112,10 +115,14 @@ module dimension_x(startpoint, endpoint, offset = 1, text = "", thickness = 0.1,
//offset will detirmine how much space is between the measured point and the dimension //offset will detirmine how much space is between the measured point and the dimension
//for y, this offset will be in the x direction //for y, this offset will be in the x direction
//plane options : xy, yz //plane options : xy, yz
module dimension_y(startpoint, endpoint, offset = 1, text = "", thickness = 0.1, plane = "xy") { module dimension_y(startpoint, endpoint, offset = 1, text = "", thickness = 0, text_size = 0 , plane = "xy") {
length = norm(endpoint - startpoint);
thickness = (thickness == 0? length/200:thickness);
x = max(startpoint.x, endpoint.x) + (plane=="xy"?offset:0); x = max(startpoint.x, endpoint.x) + (plane=="xy"?offset:0);
z = max(startpoint.z, endpoint.z) + (plane=="yz"?offset:0); z = max(startpoint.z, endpoint.z) + (plane=="yz"?offset:0);
dimension([x, startpoint.y, z], [x, endpoint.y, z], text, thickness, rot_around_dim=(plane=="yz"?90: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; v1= [x, startpoint.y, z]-startpoint;
h1 = norm(v1); h1 = norm(v1);
@@ -140,10 +147,14 @@ module dimension_y(startpoint, endpoint, offset = 1, text = "", thickness = 0.1,
//offset will detirmine how much space is between the measured point and the dimension //offset will detirmine how much space is between the measured point and the dimension
//for z, this offset will be in the x direction //for z, this offset will be in the x direction
//plane options : xz, yz //plane options : xz, yz
module dimension_z(startpoint, endpoint, offset = 1, text = "", thickness = 0.1, plane = "xz") { module dimension_z(startpoint, endpoint, offset = 1, text = "", thickness = 0, text_size = 0 , plane = "xz") {
length = norm(endpoint - startpoint);
thickness = (thickness == 0? length/200:thickness);
x = max(startpoint.x, endpoint.x) + (plane=="xz"?offset:0); x = max(startpoint.x, endpoint.x) + (plane=="xz"?offset:0);
y = max(startpoint.y, endpoint.y) + (plane=="yz"?offset:0); y = max(startpoint.y, endpoint.y) + (plane=="yz"?offset:0);
dimension([x, y, startpoint.z], [x, y, endpoint.z], text, thickness, rot_around_dim=(plane=="xz"?90: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; v1= [x, y, startpoint.z]-startpoint;
h1 = norm(v1); h1 = norm(v1);