mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-19 12:51:30 +02:00
Move affine3d_frame_map to transforms.scad and rename to frame_map.
Add module version. Change all calls.
This commit is contained in:
58
affine.scad
58
affine.scad
@@ -882,64 +882,6 @@ function affine3d_rot_from_to(from, to) =
|
||||
];
|
||||
|
||||
|
||||
// Function: affine3d_frame_map()
|
||||
// Usage:
|
||||
// map = affine3d_frame_map(v1, v2, v3, [reverse=]);
|
||||
// map = affine3d_frame_map(x=VECTOR1, y=VECTOR2, [reverse=]);
|
||||
// map = affine3d_frame_map(x=VECTOR1, z=VECTOR2, [reverse=]);
|
||||
// map = affine3d_frame_map(y=VECTOR1, z=VECTOR2, [reverse=]);
|
||||
// Topics: Affine, Matrices, Transforms, Rotation
|
||||
// See Also: rot(), xrot(), yrot(), zrot(), affine2d_zrot()
|
||||
// Description:
|
||||
// Returns a transformation that maps one coordinate frame to another. You must specify two or
|
||||
// three of `x`, `y`, and `z`. The specified axes are mapped to the vectors you supplied. If you
|
||||
// give two inputs, the third vector is mapped to the appropriate normal to maintain a right hand
|
||||
// coordinate system. If the vectors you give are orthogonal the result will be a rotation and the
|
||||
// `reverse` parameter will supply the inverse map, which enables you to map two arbitrary
|
||||
// coordinate systems to each other by using the canonical coordinate system as an intermediary.
|
||||
// You cannot use the `reverse` option with non-orthogonal inputs.
|
||||
// Arguments:
|
||||
// x = Destination 3D vector for x axis.
|
||||
// y = Destination 3D vector for y axis.
|
||||
// z = Destination 3D vector for z axis.
|
||||
// reverse = reverse direction of the map for orthogonal inputs. Default: false
|
||||
// Example:
|
||||
// T = affine3d_frame_map(x=[1,1,0], y=[-1,1,0]); // This map is just a rotation around the z axis
|
||||
// Example:
|
||||
// T = affine3d_frame_map(x=[1,0,0], y=[1,1,0]); // This map is not a rotation because x and y aren't orthogonal
|
||||
// Example:
|
||||
// // The next map sends [1,1,0] to [0,1,1] and [-1,1,0] to [0,-1,1]
|
||||
// T = affine3d_frame_map(x=[0,1,1], y=[0,-1,1]) * affine3d_frame_map(x=[1,1,0], y=[-1,1,0],reverse=true);
|
||||
function affine3d_frame_map(x,y,z, reverse=false) =
|
||||
assert(num_defined([x,y,z])>=2, "Must define at least two inputs")
|
||||
let(
|
||||
xvalid = is_undef(x) || (is_vector(x) && len(x)==3),
|
||||
yvalid = is_undef(y) || (is_vector(y) && len(y)==3),
|
||||
zvalid = is_undef(z) || (is_vector(z) && len(z)==3)
|
||||
)
|
||||
assert(xvalid,"Input x must be a length 3 vector")
|
||||
assert(yvalid,"Input y must be a length 3 vector")
|
||||
assert(zvalid,"Input z must be a length 3 vector")
|
||||
let(
|
||||
x = is_undef(x)? undef : unit(x,RIGHT),
|
||||
y = is_undef(y)? undef : unit(y,BACK),
|
||||
z = is_undef(z)? undef : unit(z,UP),
|
||||
map = is_undef(x)? [cross(y,z), y, z] :
|
||||
is_undef(y)? [x, cross(z,x), z] :
|
||||
is_undef(z)? [x, y, cross(x,y)] :
|
||||
[x, y, z]
|
||||
)
|
||||
reverse? (
|
||||
let(
|
||||
ocheck = (
|
||||
approx(map[0]*map[1],0) &&
|
||||
approx(map[0]*map[2],0) &&
|
||||
approx(map[1]*map[2],0)
|
||||
)
|
||||
)
|
||||
assert(ocheck, "Inputs must be orthogonal when reverse==true")
|
||||
[for (r=map) [for (c=r) c, 0], [0,0,0,1]]
|
||||
) : [for (r=transpose(map)) [for (c=r) c, 0], [0,0,0,1]];
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user