skew() now can take angle arguments.

This commit is contained in:
Garth Minette 2022-07-10 20:58:19 -07:00
parent 05e65e4492
commit fdcfd8c36b
2 changed files with 48 additions and 18 deletions

View file

@ -5,6 +5,8 @@
A library for OpenSCAD, filled with useful tools, shapes, masks, math and manipulators, designed to make OpenSCAD easier to use. A library for OpenSCAD, filled with useful tools, shapes, masks, math and manipulators, designed to make OpenSCAD easier to use.
Requires OpenSCAD 2021.01 or later.
- **NOTE:** BOSL2 IS BETA CODE. THE CODE IS STILL BEING REORGANIZED. - **NOTE:** BOSL2 IS BETA CODE. THE CODE IS STILL BEING REORGANIZED.
- **NOTE2:** CODE WRITTEN FOR BOSLv1 PROBABLY WON'T WORK WITH BOSL2! - **NOTE2:** CODE WRITTEN FOR BOSLv1 PROBABLY WON'T WORK WITH BOSL2!
@ -31,15 +33,15 @@ A lot of the features of this library are to allow shorter, easier-to-read, inte
`xrot(30,cp=[0,10,20])` | `translate([0,10,20]) rotate([30,0,0]) translate([0,-10,-20])` `xrot(30,cp=[0,10,20])` | `translate([0,10,20]) rotate([30,0,0]) translate([0,-10,-20])`
`xcopies(20,n=3)` | `for (dx=[-20,0,20]) translate([dx,0,0])` `xcopies(20,n=3)` | `for (dx=[-20,0,20]) translate([dx,0,0])`
`zrot_copies(n=6,r=20)` | `for (zr=[0:5]) rotate([0,0,zr*60]) translate([20,0,0])` `zrot_copies(n=6,r=20)` | `for (zr=[0:5]) rotate([0,0,zr*60]) translate([20,0,0])`
`skew_xy(xa=30,ya=45)` | `multmatrix([[1,0,tan(30),0],[0,1,tan(45),0],[0,0,1,0],[0,0,0,1]])` `skew(sxz=0.5,syz=0.333)` | `multmatrix([[1,0,0.5,0],[0,1,0.333,0],[0,0,1,0],[0,0,0,1]])`
[`BOSL2/shapes.scad`](https://github.com/revarbat/BOSL2/wiki/shapes.scad) Examples | Raw OpenSCAD Equivalent [`BOSL2/shapes.scad`](https://github.com/revarbat/BOSL2/wiki/shapes.scad) Examples | Raw OpenSCAD Equivalent
---------------------------------- | ------------------------------- ---------------------------------- | -------------------------------
`cube([10,20,30], anchor=BOTTOM);` | `translate([0,0,15]) cube([10,20,30], center=true);` `cube([10,20,30], anchor=BOTTOM);` | `translate([0,0,15]) cube([10,20,30], center=true);`
`cuboid([20,20,30], fillet=5);` | `minkowski() {cube([10,10,20], center=true); sphere(r=5, $fn=32);}` `cuboid([20,20,30], rounding=5);` | `minkowski() {cube([10,10,20], center=true); sphere(r=5, $fn=32);}`
`prismoid([30,40],[20,30],h=10);` | `hull() {translate([0,0,0.005]) cube([30,40,0.01], center=true); translate([0,0,9.995]) cube([20,30,0.01],center=true);}` `prismoid([30,40],[20,30],h=10);` | `hull() {translate([0,0,0.005]) cube([30,40,0.01], center=true); translate([0,0,9.995]) cube([20,30,0.01],center=true);}`
`xcyl(l=20,d=4);` | `rotate([0,90,0]) cylinder(h=20, d=4, center=true);` `xcyl(l=20,d=4);` | `rotate([0,90,0]) cylinder(h=20, d=4, center=true);`
`cyl(l=100, d=40, fillet=5);` | `translate([0,0,50]) minkowski() {cylinder(h=90, d=30, center=true); sphere(r=5);}` `cyl(l=100, d=40, rounding=5);` | `translate([0,0,50]) minkowski() {cylinder(h=90, d=30, center=true); sphere(r=5);}`
## Documentation ## Documentation

View file

@ -1234,11 +1234,11 @@ module frame_map(x,y,z,p,reverse=false)
// Function&Module: skew() // Function&Module: skew()
// Usage: As Module // Usage: As Module
// skew([sxy=], [sxz=], [syx=], [syz=], [szx=], [szy=]) CHILDREN; // skew([sxy=]|[axy=], [sxz=]|[axz=], [syx=]|[ayx=], [syz=]|[ayz=], [szx=]|[azx=], [szy=]|[azy=]) CHILDREN;
// Usage: As Function // Usage: As Function
// pts = skew(p, [sxy=], [sxz=], [syx=], [syz=], [szx=], [szy=]); // pts = skew(p, [sxy=]|[axy=], [sxz=]|[axz=], [syx=]|[ayx=], [syz=]|[ayz=], [szx=]|[azx=], [szy=]|[azy=]);
// Usage: Get Affine Matrix // Usage: Get Affine Matrix
// mat = skew([sxy=], [sxz=], [syx=], [syz=], [szx=], [szy=]); // mat = skew([sxy=]|[axy=], [sxz=]|[axz=], [syx=]|[ayx=], [syz=]|[ayz=], [szx=]|[azx=], [szy=]|[azy=]);
// Topics: Affine, Matrices, Transforms, Skewing // Topics: Affine, Matrices, Transforms, Skewing
// //
// Description: // Description:
@ -1259,8 +1259,16 @@ module frame_map(x,y,z,p,reverse=false)
// syz = Skew factor multiplier for skewing along the Y axis as you get farther from the Z axis. Default: 0 // syz = Skew factor multiplier for skewing along the Y axis as you get farther from the Z axis. Default: 0
// szx = Skew factor multiplier for skewing along the Z axis as you get farther from the X axis. Default: 0 // szx = Skew factor multiplier for skewing along the Z axis as you get farther from the X axis. Default: 0
// szy = Skew factor multiplier for skewing along the Z axis as you get farther from the Y axis. Default: 0 // szy = Skew factor multiplier for skewing along the Z axis as you get farther from the Y axis. Default: 0
// axy = Angle to skew along the X axis as you get farther from the Y axis.
// axz = Angle to skew along the X axis as you get farther from the Z axis.
// ayx = Angle to skew along the Y axis as you get farther from the X axis.
// ayz = Angle to skew along the Y axis as you get farther from the Z axis.
// azx = Angle to skew along the Z axis as you get farther from the X axis.
// azy = Angle to skew along the Z axis as you get farther from the Y axis.
// Example(2D): Skew along the X axis in 2D. // Example(2D): Skew along the X axis in 2D.
// skew(sxy=0.5) square(40, center=true); // skew(sxy=0.5) square(40, center=true);
// Example(2D): Skew along the X axis by 30º in 2D.
// skew(axy=30) square(40, center=true);
// Example(2D): Skew along the Y axis in 2D. // Example(2D): Skew along the Y axis in 2D.
// skew(syx=0.5) square(40, center=true); // skew(syx=0.5) square(40, center=true);
// Example: Skew along the X axis in 3D as a factor of Y coordinate. // Example: Skew along the X axis in 3D as a factor of Y coordinate.
@ -1284,23 +1292,43 @@ module frame_map(x,y,z,p,reverse=false)
// Example(FlatSpin,VPD=175): Calling as a 3D Function // Example(FlatSpin,VPD=175): Calling as a 3D Function
// pts = skew(p=path3d(square(40,center=true)), szx=0.5, szy=0.3); // pts = skew(p=path3d(square(40,center=true)), szx=0.5, szy=0.3);
// stroke(pts,closed=true,dots=true,dots_color="blue"); // stroke(pts,closed=true,dots=true,dots_color="blue");
module skew(p, sxy=0, sxz=0, syx=0, syz=0, szx=0, szy=0) module skew(p, sxy, sxz, syx, syz, szx, szy, axy, axz, ayx, ayz, azx, azy)
{ {
req_children($children); req_children($children);
assert(is_undef(p), "Module form `skew()` does not accept p= argument.") assert(is_undef(p), "Module form `skew()` does not accept p= argument.");
multmatrix( mat = skew(
affine3d_skew(sxy=sxy, sxz=sxz, syx=syx, syz=syz, szx=szx, szy=szy) sxy=sxy, sxz=sxz, syx=syx, syz=syz, szx=szx, szy=szy,
) children(); axy=axy, axz=axz, ayx=ayx, ayz=ayz, azx=azx, azy=azy
);
multmatrix(mat) children();
} }
function skew(p=_NO_ARG, sxy=0, sxz=0, syx=0, syz=0, szx=0, szy=0) = function skew(p=_NO_ARG, sxy, sxz, syx, syz, szx, szy, axy, axz, ayx, ayz, azx, azy) =
assert(is_finite(sxy)) assert(num_defined([sxy,axy]) < 2)
assert(is_finite(sxz)) assert(num_defined([sxz,axz]) < 2)
assert(is_finite(syx)) assert(num_defined([syx,ayx]) < 2)
assert(is_finite(syz)) assert(num_defined([syz,ayz]) < 2)
assert(is_finite(szx)) assert(num_defined([szx,azx]) < 2)
assert(is_finite(szy)) assert(num_defined([szy,azy]) < 2)
assert(sxy==undef || is_finite(sxy))
assert(sxz==undef || is_finite(sxz))
assert(syx==undef || is_finite(syx))
assert(syz==undef || is_finite(syz))
assert(szx==undef || is_finite(szx))
assert(szy==undef || is_finite(szy))
assert(axy==undef || is_finite(axy))
assert(axz==undef || is_finite(axz))
assert(ayx==undef || is_finite(ayx))
assert(ayz==undef || is_finite(ayz))
assert(azx==undef || is_finite(azx))
assert(azy==undef || is_finite(azy))
let( let(
sxy = is_num(sxy)? sxy : is_num(axy)? tan(axy) : 0,
sxz = is_num(sxz)? sxz : is_num(axz)? tan(axz) : 0,
syx = is_num(syx)? syx : is_num(ayx)? tan(ayx) : 0,
syz = is_num(syz)? syz : is_num(ayz)? tan(ayz) : 0,
szx = is_num(szx)? szx : is_num(azx)? tan(azx) : 0,
szy = is_num(szy)? szy : is_num(azy)? tan(azy) : 0,
m = affine3d_skew(sxy=sxy, sxz=sxz, syx=syx, syz=syz, szx=szx, szy=szy) m = affine3d_skew(sxy=sxy, sxz=sxz, syx=syx, syz=syz, szx=szx, szy=szy)
) )
p==_NO_ARG? m : apply(m, p); p==_NO_ARG? m : apply(m, p);