mirror of
https://github.com/nophead/NopSCADlib.git
synced 2025-08-09 08:56:29 +02:00
simplified the math to use rotates instead, added examples, and allowed the user to choose witch plane the x,y and z dimensions are in
This commit is contained in:
@@ -29,8 +29,8 @@ module dimensions_3d_xy() {
|
||||
|
||||
dimension([0,0,0], [0,10,0], "", 0.2);
|
||||
dimension([0,0,0], [0,-10,0], "", 0.2);
|
||||
dimension([0,0,0], [10,0,0], "", 0.2);
|
||||
dimension([0,0,0], [-10,0,0], "", 0.2, rot_around_dim=270);
|
||||
dimension([0,0,0], [10,0,0], "", 0.2,rot_around_dim=0);
|
||||
dimension([0,0,0], [-10,0,0], "", 0.2, rot_around_dim=90);
|
||||
}
|
||||
|
||||
module dimensions_3d_xyz() {
|
||||
@@ -42,7 +42,7 @@ module dimensions_3d_xyz() {
|
||||
dimension([0,0,0], [10,10,-10], "", 0.2);
|
||||
dimension([0,0,0], [10,-10,-10], "", 0.2);
|
||||
dimension([0,0,0], [-10,10,-10], "", 0.2);
|
||||
dimension([0,0,0], [-10,-10,-10], "", 0.2);
|
||||
dimension([0,0,0], [-10,-10,-10], "", 0.2, rot_around_dim=45);
|
||||
|
||||
dimension([0,0,0], [-3,0,10], "", 0.2);
|
||||
dimension([0,0,0], [0,0,-10], "", 0.2);
|
||||
@@ -55,24 +55,25 @@ module dimensions_3d_xyz() {
|
||||
module dimension_1d_x() {
|
||||
dimension_x([12,0,0], [18,0,0]);
|
||||
dimension_x([12,5,0], [18,10,0]);
|
||||
dimension_x([12,0,-5], [18,0,0], plane= "xz");
|
||||
dimension_x([12,5,0], [18,10,5]);
|
||||
}
|
||||
|
||||
module dimension_1d_y() {
|
||||
dimension_y([12,0,0], [12,-5,0]);
|
||||
dimension_y([12,-8,0], [18,-10,0]);
|
||||
dimension_y([12,-5,0], [18,-10,5]);
|
||||
dimension_y([12,-5,0], [18,-10,5], plane= "yz");
|
||||
}
|
||||
|
||||
module dimension_1d_z() {
|
||||
dimension_z([20,0,0], [20,0,5]);
|
||||
dimension_z([20,0,0], [20,0,10]);
|
||||
dimension_z([20,0,0], [20,10,10]);
|
||||
dimension_z([20,0,5], [20,0,0]);
|
||||
dimension_z([20,0,10], [20,0,0]);
|
||||
dimension_z([20,0,0], [20,10,10],plane= "yz");
|
||||
}
|
||||
|
||||
if($preview)
|
||||
dimensions_3d_xy();
|
||||
dimensions_3d_xyz();
|
||||
//dimensions_3d_xy();
|
||||
//dimensions_3d_xyz();
|
||||
dimension_1d_x();
|
||||
dimension_1d_y();
|
||||
dimension_1d_z();
|
||||
|
@@ -40,41 +40,55 @@ module dimension(startpoint, endpoint, text = "", thickness = 0.1, rot_around_di
|
||||
azimuth = atan2(direction.y, direction.x);
|
||||
elevation = -atan2(direction.z, dir_xy);
|
||||
|
||||
//end triangle size
|
||||
etr_width = thickness *5;
|
||||
etr_height = thickness *3;
|
||||
|
||||
// Draw measurement line as a thin cylinder
|
||||
translate(midpoint)
|
||||
rotate([0, elevation, azimuth])
|
||||
rotate([0, 90, 0])
|
||||
cylinder(d = thickness, h = length - thickness * 2, center = true);
|
||||
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];
|
||||
//up_dir = transform([0,1,0], rotate(azimuth));
|
||||
//depth_dir = transform([0,0,1], rotate(azimuth));
|
||||
|
||||
// Draw endpoint markers
|
||||
translate(startpoint)
|
||||
rotate([0, elevation - 90, azimuth])
|
||||
translate([0, 0, -thickness * 4])
|
||||
cylinder(h = thickness * 4, r1 = thickness * 2, r2 = 0);
|
||||
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 + 90, azimuth])
|
||||
translate([0, 0, -thickness * 4])
|
||||
cylinder(h = thickness * 4, r1 = thickness * 2, r2 = 0);
|
||||
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
|
||||
dir = (length > 0) ? (direction / length) * thickness * 4 : [1, 0, 0];
|
||||
up_dir = transform([0,1,0], rotate(azimuth));
|
||||
depth_dir = transform([0,0,1], rotate(azimuth));
|
||||
|
||||
rotate(direction*rot_around_dim/2)
|
||||
translate(midpoint + up_dir*thickness - depth_dir*thickness/2)
|
||||
translate(midpoint)
|
||||
rotate([0, elevation, azimuth])
|
||||
rotate([rot_around_dim,0,0])
|
||||
translate([0,thickness,-thickness/2])
|
||||
linear_extrude(thickness)
|
||||
text(text == "" ? str(length) : text, size = thickness * 5, valign = "bottom", halign = "center");
|
||||
}
|
||||
|
||||
//offset will detirmine how much space is between the measured point and the dimension
|
||||
//for x, this offset will be in the y direction
|
||||
module dimension_x(startpoint, endpoint, offset = 1, text = "", thickness = 0.1) {
|
||||
y = max(startpoint.y, endpoint.y) + offset;
|
||||
z = max(startpoint.z, endpoint.z) ;
|
||||
dimension([startpoint.x, y, z], [endpoint.x, y, z], text, thickness);
|
||||
//plane options : xy, xz
|
||||
module dimension_x(startpoint, endpoint, offset = 1, text = "", thickness = 0.1, plane = "xy") {
|
||||
y = max(startpoint.y, endpoint.y) + (plane=="xy"?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));
|
||||
|
||||
v1= [startpoint.x, y, z]-startpoint;
|
||||
h1 = norm(v1);
|
||||
@@ -97,10 +111,11 @@ 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
|
||||
//for y, this offset will be in the x direction
|
||||
module dimension_y(startpoint, endpoint, offset = 1, text = "", thickness = 0.1) {
|
||||
x = max(startpoint.x, endpoint.x) + offset;
|
||||
z = max(startpoint.z, endpoint.z) ;
|
||||
dimension([x, startpoint.y, z], [x, endpoint.y, z], text, thickness);
|
||||
//plane options : xy, yz
|
||||
module dimension_y(startpoint, endpoint, offset = 1, text = "", thickness = 0.1, plane = "xy") {
|
||||
x = max(startpoint.x, endpoint.x) + (plane=="xy"?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));
|
||||
|
||||
v1= [x, startpoint.y, z]-startpoint;
|
||||
h1 = norm(v1);
|
||||
@@ -124,10 +139,11 @@ 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
|
||||
//for z, this offset will be in the x direction
|
||||
module dimension_z(startpoint, endpoint, offset = 1, text = "", thickness = 0.1) {
|
||||
x = max(startpoint.x, endpoint.x) + offset;
|
||||
y = max(startpoint.y, endpoint.y) ;
|
||||
dimension([x, y, startpoint.z], [x, y, endpoint.z], text, thickness);
|
||||
//plane options : xz, yz
|
||||
module dimension_z(startpoint, endpoint, offset = 1, text = "", thickness = 0.1, plane = "xz") {
|
||||
x = max(startpoint.x, endpoint.x) + (plane=="xz"?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));
|
||||
|
||||
v1= [x, y, startpoint.z]-startpoint;
|
||||
h1 = norm(v1);
|
||||
|
Reference in New Issue
Block a user