mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-20 12:22:28 +02:00
reordering and moving for improved docs
removed xxrot and xxflip
This commit is contained in:
360
transforms.scad
360
transforms.scad
@@ -603,183 +603,6 @@ module zrot(a=0, p, cp)
|
||||
function zrot(a=0, p, cp) = rot(a, cp=cp, p=p);
|
||||
|
||||
|
||||
// Function&Module: xyrot()
|
||||
//
|
||||
// Usage: As Module
|
||||
// xyrot(a, [cp=]) ...
|
||||
// Usage: As a Function to rotate points
|
||||
// rotated = xyrot(a, p, [cp=]);
|
||||
// Usage: As a Function to get rotation matrix
|
||||
// mat = xyrot(a, [cp=]);
|
||||
//
|
||||
// Topics: Affine, Matrices, Transforms, Rotation
|
||||
// See Also: rot(), xrot(), yrot(), zrot(), xzrot(), yzrot(), xyzrot(), affine3d_rot_by_axis()
|
||||
//
|
||||
// Description:
|
||||
// Rotates around the [1,1,0] vector axis by the given number of degrees. If `cp` is given, rotations are performed around that centerpoint.
|
||||
// * Called as a module, rotates all children.
|
||||
// * Called as a function with a `p` argument containing a point, returns the rotated point.
|
||||
// * Called as a function with a `p` argument containing a list of points, returns the list of rotated points.
|
||||
// * Called as a function with a [bezier patch](beziers.scad) in the `p` argument, returns the rotated patch.
|
||||
// * Called as a function with a [VNF structure](vnf.scad) in the `p` argument, returns the rotated VNF.
|
||||
// * Called as a function without a `p` argument, returns the affine3d rotational matrix.
|
||||
//
|
||||
// Arguments:
|
||||
// a = angle to rotate by in degrees.
|
||||
// p = If called as a function, this contains data to rotate: a point, list of points, bezier patch or VNF.
|
||||
// ---
|
||||
// cp = centerpoint to rotate around. Default: [0,0,0]
|
||||
//
|
||||
// Example:
|
||||
// #cylinder(h=50, r=10, center=true);
|
||||
// xyrot(90) cylinder(h=50, r=10, center=true);
|
||||
module xyrot(a=0, p, cp)
|
||||
{
|
||||
assert(is_undef(p), "Module form `xyrot()` does not accept p= argument.");
|
||||
if (a==0) {
|
||||
children(); // May be slightly faster?
|
||||
} else {
|
||||
mat = xyrot(a=a, cp=cp);
|
||||
multmatrix(mat) children();
|
||||
}
|
||||
}
|
||||
|
||||
function xyrot(a=0, p, cp) = rot(a=a, v=[1,1,0], cp=cp, p=p);
|
||||
|
||||
|
||||
// Function&Module: xzrot()
|
||||
//
|
||||
// Usage: As Module
|
||||
// xzrot(a, [cp=]) ...
|
||||
// Usage: As Function to rotate points
|
||||
// rotated = xzrot(a, p, [cp=]);
|
||||
// Usage: As Function to return rotation matrix
|
||||
// mat = xzrot(a, [cp=]);
|
||||
//
|
||||
// Topics: Affine, Matrices, Transforms, Rotation
|
||||
// See Also: rot(), xrot(), yrot(), zrot(), xyrot(), yzrot(), xyzrot(), affine3d_rot_by_axis()
|
||||
//
|
||||
// Description:
|
||||
// Rotates around the [1,0,1] vector axis by the given number of degrees. If `cp` is given, rotations are performed around that centerpoint.
|
||||
// * Called as a module, rotates all children.
|
||||
// * Called as a function with a `p` argument containing a point, returns the rotated point.
|
||||
// * Called as a function with a `p` argument containing a list of points, returns the list of rotated points.
|
||||
// * Called as a function with a [bezier patch](beziers.scad) in the `p` argument, returns the rotated patch.
|
||||
// * Called as a function with a [VNF structure](vnf.scad) in the `p` argument, returns the rotated VNF.
|
||||
// * Called as a function without a `p` argument, returns the affine3d rotational matrix.
|
||||
//
|
||||
// Arguments:
|
||||
// a = angle to rotate by in degrees.
|
||||
// p = If called as a function, this contains data to rotate: a point, list of points, bezier patch or VNF.
|
||||
// ---
|
||||
// cp = centerpoint to rotate around. Default: [0,0,0]
|
||||
//
|
||||
// Example:
|
||||
// #cylinder(h=50, r=10, center=true);
|
||||
// xzrot(90) cylinder(h=50, r=10, center=true);
|
||||
module xzrot(a=0, p, cp)
|
||||
{
|
||||
assert(is_undef(p), "Module form `xzrot()` does not accept p= argument.");
|
||||
if (a==0) {
|
||||
children(); // May be slightly faster?
|
||||
} else {
|
||||
mat = xzrot(a=a, cp=cp);
|
||||
multmatrix(mat) children();
|
||||
}
|
||||
}
|
||||
|
||||
function xzrot(a=0, p, cp) = rot(a=a, v=[1,0,1], cp=cp, p=p);
|
||||
|
||||
|
||||
// Function&Module: yzrot()
|
||||
//
|
||||
// Usage: As Module
|
||||
// yzrot(a, [cp=]) ...
|
||||
// Usage: As Function to rotate points
|
||||
// rotated = yzrot(a, p, [cp=]);
|
||||
// Usage: As Function to return rotation matrix
|
||||
// mat = yzrot(a, [cp=]);
|
||||
//
|
||||
// Topics: Affine, Matrices, Transforms, Rotation
|
||||
// See Also: rot(), xrot(), yrot(), zrot(), xyrot(), xzrot(), xyzrot(), affine3d_rot_by_axis()
|
||||
//
|
||||
// Description:
|
||||
// Rotates around the [0,1,1] vector axis by the given number of degrees. If `cp` is given, rotations are performed around that centerpoint.
|
||||
// * Called as a module, rotates all children.
|
||||
// * Called as a function with a `p` argument containing a point, returns the rotated point.
|
||||
// * Called as a function with a `p` argument containing a list of points, returns the list of rotated points.
|
||||
// * Called as a function with a [bezier patch](beziers.scad) in the `p` argument, returns the rotated patch.
|
||||
// * Called as a function with a [VNF structure](vnf.scad) in the `p` argument, returns the rotated VNF.
|
||||
// * Called as a function without a `p` argument, returns the affine3d rotational matrix.
|
||||
//
|
||||
// Arguments:
|
||||
// a = angle to rotate by in degrees.
|
||||
// p = If called as a function, this contains data to rotate: a point, list of points, bezier patch or VNF.
|
||||
// ---
|
||||
// cp = centerpoint to rotate around. Default: [0,0,0]
|
||||
//
|
||||
// Example:
|
||||
// #cylinder(h=50, r=10, center=true);
|
||||
// yzrot(90) cylinder(h=50, r=10, center=true);
|
||||
module yzrot(a=0, p, cp)
|
||||
{
|
||||
assert(is_undef(p), "Module form `yzrot()` does not accept p= argument.");
|
||||
if (a==0) {
|
||||
children(); // May be slightly faster?
|
||||
} else {
|
||||
mat = yzrot(a=a, cp=cp);
|
||||
multmatrix(mat) children();
|
||||
}
|
||||
}
|
||||
|
||||
function yzrot(a=0, p, cp) = rot(a=a, v=[0,1,1], cp=cp, p=p);
|
||||
|
||||
|
||||
// Function&Module: xyzrot()
|
||||
//
|
||||
// Usage: As Module
|
||||
// xyzrot(a, [cp=]) ...
|
||||
// Usage: As Function to rotate points
|
||||
// rotated = xyzrot(a, p, [cp=]);
|
||||
// Usage: As Function to return rotation matrix
|
||||
// mat = xyzrot(a, [cp=]);
|
||||
//
|
||||
// Topics: Affine, Matrices, Transforms, Rotation
|
||||
// See Also: rot(), xrot(), yrot(), zrot(), xyrot(), xzrot(), yzrot(), affine3d_rot_by_axis()
|
||||
//
|
||||
// Description:
|
||||
// Rotates around the [1,1,1] vector axis by the given number of degrees. If `cp` is given, rotations are performed around that centerpoint.
|
||||
// * Called as a module, rotates all children.
|
||||
// * Called as a function with a `p` argument containing a point, returns the rotated point.
|
||||
// * Called as a function with a `p` argument containing a list of points, returns the list of rotated points.
|
||||
// * Called as a function with a [bezier patch](beziers.scad) in the `p` argument, returns the rotated patch.
|
||||
// * Called as a function with a [VNF structure](vnf.scad) in the `p` argument, returns the rotated VNF.
|
||||
// * Called as a function without a `p` argument, returns the affine3d rotational matrix.
|
||||
//
|
||||
// Arguments:
|
||||
// a = angle to rotate by in degrees.
|
||||
// p = If called as a function, this contains data to rotate: a point, list of points, bezier patch or VNF.
|
||||
// ---
|
||||
// cp = centerpoint to rotate around. Default: [0,0,0]
|
||||
//
|
||||
// Example:
|
||||
// #cylinder(h=50, r=10, center=true);
|
||||
// xyzrot(90) cylinder(h=50, r=10, center=true);
|
||||
module xyzrot(a=0, p, cp)
|
||||
{
|
||||
assert(is_undef(p), "Module form `xyzrot()` does not accept p= argument.");
|
||||
if (a==0) {
|
||||
children(); // May be slightly faster?
|
||||
} else {
|
||||
mat = xyzrot(a=a, cp=cp);
|
||||
multmatrix(mat) children();
|
||||
}
|
||||
}
|
||||
|
||||
function xyzrot(a=0, p, cp) = rot(a=a, v=[1,1,1], cp=cp, p=p);
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Section: Scaling and Mirroring
|
||||
@@ -1265,189 +1088,6 @@ function zflip(p, z=0) =
|
||||
move([0,0,z],p=mirror([0,0,1],p=move([0,0,-z],p=p)));
|
||||
|
||||
|
||||
// Function&Module: xyflip()
|
||||
//
|
||||
// Usage: As Module
|
||||
// xyflip([cp]) ...
|
||||
// Usage: As Function
|
||||
// pt = xyflip(p, [cp]);
|
||||
// Usage: Get Affine Matrix
|
||||
// pt = xyflip([cp], [planar=]);
|
||||
//
|
||||
// Topics: Affine, Matrices, Transforms, Reflection, Mirroring
|
||||
// See Also: mirror(), xflip(), yflip(), zflip(), xzflip(), yzflip(), affine2d_mirror(), affine3d_mirror()
|
||||
//
|
||||
// Description:
|
||||
// Mirrors/reflects across the origin [0,0,0], along the reflection plane where X=Y. If `cp` is given, the reflection plane passes through that point
|
||||
// * Called as the built-in module, mirrors all children across the line/plane.
|
||||
// * Called as a function with a point in the `p` argument, returns the point mirrored across the line/plane.
|
||||
// * Called as a function with a list of points in the `p` argument, returns the list of points, with each one mirrored across the line/plane.
|
||||
// * Called as a function with a [bezier patch](beziers.scad) in the `p` argument, returns the mirrored patch.
|
||||
// * Called as a function with a [VNF structure](vnf.scad) in the `p` argument, returns the mirrored VNF.
|
||||
// * Called as a function without a `p` argument, and `planer=true`, returns the affine2d 3x3 mirror matrix.
|
||||
// * Called as a function without a `p` argument, and `planar=false`, returns the affine3d 4x4 mirror matrix.
|
||||
//
|
||||
// Arguments:
|
||||
// p = If given, the point, path, patch, or VNF to mirror. Function use only.
|
||||
// cp = The centerpoint of the plane of reflection, given either as a point, or as a scalar distance away from the origin.
|
||||
// ---
|
||||
// planar = If true, and p is not given, returns a 2D affine transformation matrix. Function use only. Default: False
|
||||
//
|
||||
// Example(2D):
|
||||
// xyflip() text("Foobar", size=20, halign="center");
|
||||
//
|
||||
// Example:
|
||||
// left(10) frame_ref();
|
||||
// right(10) xyflip() frame_ref();
|
||||
//
|
||||
// Example:
|
||||
// xyflip(cp=-15) frame_ref();
|
||||
//
|
||||
// Example:
|
||||
// xyflip(cp=[10,10,10]) frame_ref();
|
||||
//
|
||||
// Example: Called as Function for a 3D matrix
|
||||
// mat = xyflip();
|
||||
// multmatrix(mat) frame_ref();
|
||||
//
|
||||
// Example(2D): Called as Function for a 2D matrix
|
||||
// mat = xyflip(planar=true);
|
||||
// multmatrix(mat) text("Foobar", size=20, halign="center");
|
||||
module xyflip(p, cp=0, planar) {
|
||||
assert(is_undef(p), "Module form `xyflip()` does not accept p= argument.");
|
||||
assert(is_undef(planar), "Module form `xyflip()` does not accept planar= argument.");
|
||||
mat = xyflip(cp=cp);
|
||||
multmatrix(mat) children();
|
||||
}
|
||||
|
||||
function xyflip(p, cp=0, planar=false) =
|
||||
assert(is_finite(cp) || is_vector(cp))
|
||||
let(
|
||||
v = unit([-1,1,0]),
|
||||
n = planar? point2d(v) : v
|
||||
)
|
||||
cp == 0 || cp==[0,0,0]? mirror(n, p=p) :
|
||||
let(
|
||||
cp = is_finite(cp)? n * cp :
|
||||
is_vector(cp)? assert(len(cp) == len(n)) cp :
|
||||
assert(is_finite(cp) || is_vector(cp)),
|
||||
mat = move(cp) * mirror(n) * move(-cp)
|
||||
) is_undef(p)? mat : apply(mat, p);
|
||||
|
||||
|
||||
// Function&Module: xzflip()
|
||||
//
|
||||
// Usage: As Module
|
||||
// xzflip([cp]) ...
|
||||
// Usage: As Function
|
||||
// pt = xzflip([cp], p);
|
||||
// Usage: Get Affine Matrix
|
||||
// pt = xzflip([cp]);
|
||||
//
|
||||
// Topics: Affine, Matrices, Transforms, Reflection, Mirroring
|
||||
// See Also: mirror(), xflip(), yflip(), zflip(), xyflip(), yzflip(), affine2d_mirror(), affine3d_mirror()
|
||||
//
|
||||
// Description:
|
||||
// Mirrors/reflects across the origin [0,0,0], along the reflection plane where X=Y. If `cp` is given, the reflection plane passes through that point
|
||||
// * Called as the built-in module, mirrors all children across the line/plane.
|
||||
// * Called as a function with a point in the `p` argument, returns the point mirrored across the line/plane.
|
||||
// * Called as a function with a list of points in the `p` argument, returns the list of points, with each one mirrored across the line/plane.
|
||||
// * Called as a function with a [bezier patch](beziers.scad) in the `p` argument, returns the mirrored patch.
|
||||
// * Called as a function with a [VNF structure](vnf.scad) in the `p` argument, returns the mirrored VNF.
|
||||
// * Called as a function without a `p` argument, returns the affine3d 4x4 mirror matrix.
|
||||
//
|
||||
// Arguments:
|
||||
// p = If given, the point, path, patch, or VNF to mirror. Function use only.
|
||||
// cp = The centerpoint of the plane of reflection, given either as a point, or as a scalar distance away from the origin.
|
||||
//
|
||||
// Example:
|
||||
// left(10) frame_ref();
|
||||
// right(10) xzflip() frame_ref();
|
||||
//
|
||||
// Example:
|
||||
// xzflip(cp=-15) frame_ref();
|
||||
//
|
||||
// Example:
|
||||
// xzflip(cp=[10,10,10]) frame_ref();
|
||||
//
|
||||
// Example: Called as Function
|
||||
// mat = xzflip();
|
||||
// multmatrix(mat) frame_ref();
|
||||
module xzflip(p, cp=0) {
|
||||
assert(is_undef(p), "Module form `xzflip()` does not accept p= argument.");
|
||||
mat = xzflip(cp=cp);
|
||||
multmatrix(mat) children();
|
||||
}
|
||||
|
||||
function xzflip(p, cp=0) =
|
||||
assert(is_finite(cp) || is_vector(cp))
|
||||
let( n = unit([-1,0,1]) )
|
||||
cp == 0 || cp==[0,0,0]? mirror(n, p=p) :
|
||||
let(
|
||||
cp = is_finite(cp)? n * cp :
|
||||
is_vector(cp,3)? cp :
|
||||
assert(is_finite(cp) || is_vector(cp,3)),
|
||||
mat = move(cp) * mirror(n) * move(-cp)
|
||||
) is_undef(p)? mat : apply(mat, p);
|
||||
|
||||
|
||||
// Function&Module: yzflip()
|
||||
//
|
||||
// Usage: As Module
|
||||
// yzflip([x=]) ...
|
||||
// Usage: As Function
|
||||
// pt = yzflip(p, [x=]);
|
||||
// Usage: Get Affine Matrix
|
||||
// pt = yzflip([x=]);
|
||||
//
|
||||
// Topics: Affine, Matrices, Transforms, Reflection, Mirroring
|
||||
// See Also: mirror(), xflip(), yflip(), zflip(), xyflip(), xzflip(), affine2d_mirror(), affine3d_mirror()
|
||||
//
|
||||
// Description:
|
||||
// Mirrors/reflects across the origin [0,0,0], along the reflection plane where X=Y. If `cp` is given, the reflection plane passes through that point
|
||||
// * Called as the built-in module, mirrors all children across the line/plane.
|
||||
// * Called as a function with a point in the `p` argument, returns the point mirrored across the line/plane.
|
||||
// * Called as a function with a list of points in the `p` argument, returns the list of points, with each one mirrored across the line/plane.
|
||||
// * Called as a function with a [bezier patch](beziers.scad) in the `p` argument, returns the mirrored patch.
|
||||
// * Called as a function with a [VNF structure](vnf.scad) in the `p` argument, returns the mirrored VNF.
|
||||
// * Called as a function without a `p` argument, returns the affine3d 4x4 mirror matrix.
|
||||
//
|
||||
// Arguments:
|
||||
// p = If given, the point, path, patch, or VNF to mirror. Function use only.
|
||||
// cp = The centerpoint of the plane of reflection, given either as a point, or as a scalar distance away from the origin.
|
||||
//
|
||||
// Example:
|
||||
// left(10) frame_ref();
|
||||
// right(10) yzflip() frame_ref();
|
||||
//
|
||||
// Example:
|
||||
// yzflip(cp=-15) frame_ref();
|
||||
//
|
||||
// Example:
|
||||
// yzflip(cp=[10,10,10]) frame_ref();
|
||||
//
|
||||
// Example: Called as Function
|
||||
// mat = yzflip();
|
||||
// multmatrix(mat) frame_ref();
|
||||
module yzflip(p, cp=0) {
|
||||
assert(is_undef(p), "Module form `yzflip()` does not accept p= argument.");
|
||||
mat = yzflip(cp=cp);
|
||||
multmatrix(mat) children();
|
||||
}
|
||||
|
||||
function yzflip(p, cp=0) =
|
||||
assert(is_finite(cp) || is_vector(cp))
|
||||
let( n = unit([0,-1,1]) )
|
||||
cp == 0 || cp==[0,0,0]? mirror(n, p=p) :
|
||||
let(
|
||||
cp = is_finite(cp)? n * cp :
|
||||
is_vector(cp,3)? cp :
|
||||
assert(is_finite(cp) || is_vector(cp,3)),
|
||||
mat = move(cp) * mirror(n) * move(-cp)
|
||||
) is_undef(p)? mat : apply(mat, p);
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Section: Other Transformations
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user