mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
commit
811d958146
3 changed files with 141 additions and 69 deletions
|
@ -1551,6 +1551,7 @@ module corner_mask(corners=CORNERS_ALL, except=[]) {
|
|||
// r = Radius of corner mask.
|
||||
// ---
|
||||
// d = Diameter of corner mask.
|
||||
// excess = Excess length to extrude the profile to make edge masks. Default: 0.01
|
||||
// convexity = Max number of times a line could intersect the perimeter of the mask shape. Default: 10
|
||||
// Side Effects:
|
||||
// Tags the children with "remove" (and hence sets `$tag`) if no tag is already set.
|
||||
|
@ -1562,13 +1563,13 @@ module corner_mask(corners=CORNERS_ALL, except=[]) {
|
|||
// cube([50,60,70],center=true)
|
||||
// face_profile(TOP,r=10)
|
||||
// mask2d_roundover(r=10);
|
||||
module face_profile(faces=[], r, d, convexity=10) {
|
||||
module face_profile(faces=[], r, d, excess=0.01, convexity=10) {
|
||||
req_children($children);
|
||||
faces = is_vector(faces)? [faces] : faces;
|
||||
assert(all([for (face=faces) is_vector(face) && sum([for (x=face) x!=0? 1 : 0])==1]), "Vector in faces doesn't point at a face.");
|
||||
r = get_radius(r=r, d=d, dflt=undef);
|
||||
assert(is_num(r) && r>0);
|
||||
edge_profile(faces) children();
|
||||
assert(is_num(r) && r>=0);
|
||||
edge_profile(faces, excess=excess) children();
|
||||
corner_profile(faces, convexity=convexity, r=r) children();
|
||||
}
|
||||
|
||||
|
@ -1589,6 +1590,7 @@ module face_profile(faces=[], r, d, convexity=10) {
|
|||
// Arguments:
|
||||
// edges = Edges to mask. See [Specifying Edges](attachments.scad#subsection-specifying-edges). Default: All edges.
|
||||
// except = Edges to explicitly NOT mask. See [Specifying Edges](attachments.scad#subsection-specifying-edges). Default: No edges.
|
||||
// excess = Excess length to extrude the profile to make edge masks. Default: 0.01
|
||||
// convexity = Max number of times a line could intersect the perimeter of the mask shape. Default: 10
|
||||
// Side Effects:
|
||||
// Tags the children with "remove" (and hence sets `$tag`) if no tag is already set.
|
||||
|
@ -1600,7 +1602,7 @@ module face_profile(faces=[], r, d, convexity=10) {
|
|||
// cube([50,60,70],center=true)
|
||||
// edge_profile([TOP,"Z"],except=[BACK,TOP+LEFT])
|
||||
// mask2d_roundover(r=10, inset=2);
|
||||
module edge_profile(edges=EDGES_ALL, except=[], convexity=10) {
|
||||
module edge_profile(edges=EDGES_ALL, except=[], excess=0.01, convexity=10) {
|
||||
req_children($children);
|
||||
assert($parent_geom != undef, "No object to attach to!");
|
||||
edges = _edges(edges, except=except);
|
||||
|
@ -1619,7 +1621,7 @@ module edge_profile(edges=EDGES_ALL, except=[], convexity=10) {
|
|||
$attach_norot = true;
|
||||
$profile_type = "edge";
|
||||
psize = point3d($parent_size);
|
||||
length = [for (i=[0:2]) if(!vec[i]) psize[i]][0]+0.1;
|
||||
length = [for (i=[0:2]) if(!vec[i]) psize[i]][0] + excess;
|
||||
rotang =
|
||||
vec.z<0? [90,0,180+v_theta(vec)] :
|
||||
vec.z==0 && sign(vec.x)==sign(vec.y)? 135+v_theta(vec) :
|
||||
|
@ -1644,8 +1646,8 @@ module edge_profile(edges=EDGES_ALL, except=[], convexity=10) {
|
|||
// PARENT() corner_profile([corners], [except], [r=|d=], [convexity=]) CHILDREN;
|
||||
// Description:
|
||||
// Takes a 2D mask shape, rotationally extrudes and converts it into a corner mask, and attaches it
|
||||
// to the selected corners with the appropriate orientation. If no tag is set
|
||||
// then `corner_profile` sets the tag for children to "remove" so that it will work with the default {{diff()}} tag.
|
||||
// to the selected corners with the appropriate orientation. If no tag is set then `corner_profile()`
|
||||
// sets the tag for children to "remove" so that it will work with the default {{diff()}} tag.
|
||||
// See [Specifying Corners](attachments.scad#subsection-specifying-corners) for information on how to specify corner sets.
|
||||
// For a step-by-step explanation of attachments, see the [Attachments Tutorial](Tutorial-Attachments).
|
||||
// Arguments:
|
||||
|
@ -1668,7 +1670,7 @@ module edge_profile(edges=EDGES_ALL, except=[], convexity=10) {
|
|||
// }
|
||||
module corner_profile(corners=CORNERS_ALL, except=[], r, d, convexity=10) {
|
||||
assert($parent_geom != undef, "No object to attach to!");
|
||||
r = get_radius(r=r, d=d, dflt=undef);
|
||||
r = max(0.01, get_radius(r=r, d=d, dflt=undef));
|
||||
assert(is_num(r));
|
||||
corners = _corners(corners, except=except);
|
||||
vecs = [for (i = [0:7]) if (corners[i]>0) CORNER_OFFSETS[i]];
|
||||
|
@ -1687,17 +1689,18 @@ module corner_profile(corners=CORNERS_ALL, except=[], r, d, convexity=10) {
|
|||
$tag = $tag=="" ? str($tag_prefix,"remove") : $tag;
|
||||
translate(anch[1]) {
|
||||
rot(rotang) {
|
||||
render(convexity=convexity)
|
||||
difference() {
|
||||
translate(-0.1*[1,1,1]) cube(r+0.1, center=false);
|
||||
right(r) back(r) zrot(180) {
|
||||
rotate_extrude(angle=90, convexity=convexity) {
|
||||
xflip() left(r) {
|
||||
difference() {
|
||||
square(r,center=false);
|
||||
children();
|
||||
}
|
||||
}
|
||||
down(0.01) {
|
||||
linear_extrude(height=r+0.01, center=false) {
|
||||
difference() {
|
||||
translate(-[0.01,0.01]) square(r);
|
||||
translate([r,r]) circle(r=r*0.999);
|
||||
}
|
||||
}
|
||||
}
|
||||
translate([r,r]) zrot(180) {
|
||||
rotate_extrude(angle=90, convexity=convexity) {
|
||||
right(r) xflip() {
|
||||
children();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ use <builtins.scad>
|
|||
|
||||
// Module: recolor()
|
||||
// Synopsis: Sets the color for attachable children and their descendants.
|
||||
// SynTags: Trans
|
||||
// Topics: Attachments
|
||||
// See Also: color_this(), hsl(), hsv()
|
||||
// Usage:
|
||||
|
@ -49,6 +50,7 @@ module recolor(c="default")
|
|||
|
||||
// Module: color_this()
|
||||
// Synopsis: Sets the color for children at the current level only.
|
||||
// SynTags: Trans
|
||||
// Topics: Attachments
|
||||
// See Also: recolor(), hsl(), hsv()
|
||||
// Usage:
|
||||
|
@ -82,6 +84,7 @@ module color_this(c="default")
|
|||
|
||||
// Module: rainbow()
|
||||
// Synopsis: Iterates through a list, displaying children in different colors.
|
||||
// SynTags: Trans
|
||||
// Topics: List Handling
|
||||
// See Also: hsl(), hsv()
|
||||
// Usage:
|
||||
|
@ -124,6 +127,7 @@ module rainbow(list, stride=1, maxhues, shuffle=false, seed)
|
|||
|
||||
// Function&Module: hsl()
|
||||
// Synopsis: Sets the color of children to a specified hue, saturation, lightness and optional alpha channel value.
|
||||
// SynTags: Trans
|
||||
// See Also: hsv(), recolor(), color_this()
|
||||
// Topics: Colors, Colorspace
|
||||
// Usage:
|
||||
|
@ -165,6 +169,7 @@ module hsl(h,s=1,l=0.5,a=1)
|
|||
|
||||
// Function&Module: hsv()
|
||||
// Synopsis: Sets the color of children to a hue, saturation, value and optional alpha channel value.
|
||||
// SynTags: Trans
|
||||
// See Also: hsl(), recolor(), color_this()
|
||||
// Topics: Colors, Colorspace
|
||||
// Usage:
|
||||
|
|
164
coords.scad
164
coords.scad
|
@ -136,13 +136,16 @@ function path4d(points, fill=0) =
|
|||
// Function: polar_to_xy()
|
||||
// Usage:
|
||||
// pt = polar_to_xy(r, theta);
|
||||
// pt = polar_to_xy([r, theta]);
|
||||
// pt = polar_to_xy([R, THETA]);
|
||||
// pts = polar_to_xy([[R,THETA], [R,THETA], ...]);
|
||||
// Topics: Coordinates, Points, Paths
|
||||
// Synopsis: Convert 2d polar coordinates to cartesian coordinates.
|
||||
// See Also: xy_to_polar(), xyz_to_cylindrical(), cylindrical_to_xyz(), xyz_to_spherical(), spherical_to_xyz()
|
||||
// Description:
|
||||
// Convert polar coordinates to 2D cartesian coordinates.
|
||||
// Returns [X,Y] cartesian coordinates.
|
||||
// Called with two arguments, converts the `r` and `theta` 2D polar coordinate into an `[X,Y]` cartesian coordinate.
|
||||
// Called with one `[R,THETA]` vector argument, converts the 2D polar coordinate into an `[X,Y]` cartesian coordinate.
|
||||
// Called with a list of `[R,THETA]` vector arguments, converts each 2D polar coordinate into `[X,Y]` cartesian coordinates.
|
||||
// Theta is the angle counter-clockwise of X+ on the XY plane.
|
||||
// Arguments:
|
||||
// r = distance from the origin.
|
||||
// theta = angle in degrees, counter-clockwise of X+.
|
||||
|
@ -150,6 +153,7 @@ function path4d(points, fill=0) =
|
|||
// xy = polar_to_xy(20,45); // Returns: ~[14.1421365, 14.1421365]
|
||||
// xy = polar_to_xy(40,30); // Returns: ~[34.6410162, 15]
|
||||
// xy = polar_to_xy([40,30]); // Returns: ~[34.6410162, 15]
|
||||
// xy = polar_to_xy([[40,30],[20,120]]); // Returns: ~[[34.6410162, 15], [-10, 17.3205]]
|
||||
// Example(2D):
|
||||
// r=40; ang=30; $fn=36;
|
||||
// pt = polar_to_xy(r,ang);
|
||||
|
@ -157,28 +161,36 @@ function path4d(points, fill=0) =
|
|||
// color("black") stroke([[r,0], [0,0], pt], width=0.5);
|
||||
// color("black") stroke(arc(r=15, angle=ang), width=0.5);
|
||||
// color("red") move(pt) circle(d=3);
|
||||
function polar_to_xy(r,theta=undef) = let(
|
||||
rad = theta==undef? r[0] : r,
|
||||
t = theta==undef? r[1] : theta
|
||||
) rad*[cos(t), sin(t)];
|
||||
function polar_to_xy(r,theta) =
|
||||
theta != undef
|
||||
? assert(is_num(r) && is_num(theta), "Bad Arguments.")
|
||||
[r*cos(theta), r*sin(theta)]
|
||||
: assert(is_list(r), "Bad Arguments")
|
||||
is_num(r.x)
|
||||
? polar_to_xy(r.x, r.y)
|
||||
: [for(p = r) polar_to_xy(p.x, p.y)];
|
||||
|
||||
|
||||
// Function: xy_to_polar()
|
||||
// Usage:
|
||||
// r_theta = xy_to_polar(x,y);
|
||||
// r_theta = xy_to_polar([X,Y]);
|
||||
// r_thetas = xy_to_polar([[X,Y], [X,Y], ...]);
|
||||
// Topics: Coordinates, Points, Paths
|
||||
// Synopsis: Convert 2d cartesian coordinates to polar coordinates (radius and angle)
|
||||
// See Also: polar_to_xy(), xyz_to_cylindrical(), cylindrical_to_xyz(), xyz_to_spherical(), spherical_to_xyz()
|
||||
// Description:
|
||||
// Convert 2D cartesian coordinates to polar coordinates.
|
||||
// Returns [radius, theta] where theta is the angle counter-clockwise of X+.
|
||||
// Called with two arguments, converts the `x` and `y` 2D cartesian coordinate into a `[RADIUS,THETA]` polar coordinate.
|
||||
// Called with one `[X,Y]` vector argument, converts the 2D cartesian coordinate into a `[RADIUS,THETA]` polar coordinate.
|
||||
// Called with a list of `[X,Y]` vector arguments, converts each 2D cartesian coordinate into `[RADIUS,THETA]` polar coordinates.
|
||||
// Theta is the angle counter-clockwise of X+ on the XY plane.
|
||||
// Arguments:
|
||||
// x = X coordinate.
|
||||
// y = Y coordinate.
|
||||
// Example:
|
||||
// plr = xy_to_polar(20,30);
|
||||
// plr = xy_to_polar([40,60]);
|
||||
// plrs = xy_to_polar([[40,60],[-10,20]]);
|
||||
// Example(2D):
|
||||
// pt = [-20,30]; $fn = 36;
|
||||
// rt = xy_to_polar(pt);
|
||||
|
@ -186,10 +198,14 @@ function polar_to_xy(r,theta=undef) = let(
|
|||
// stroke(circle(r=r), closed=true, width=0.5);
|
||||
// zrot(ang) stroke([[0,0],[r,0]],width=0.5);
|
||||
// color("red") move(pt) circle(d=3);
|
||||
function xy_to_polar(x,y=undef) = let(
|
||||
xx = y==undef? x[0] : x,
|
||||
yy = y==undef? x[1] : y
|
||||
) [norm([xx,yy]), atan2(yy,xx)];
|
||||
function xy_to_polar(x, y) =
|
||||
y != undef
|
||||
? assert(is_num(x) && is_num(y), "Bad Arguments.")
|
||||
[norm([x, y]), atan2(y, x)]
|
||||
: assert(is_list(x), "Bad Arguments")
|
||||
is_num(x.x)
|
||||
? xy_to_polar(x.x, x.y)
|
||||
: [for(p = x) xy_to_polar(p.x, p.y)];
|
||||
|
||||
|
||||
// Function: project_plane()
|
||||
|
@ -324,12 +340,16 @@ function lift_plane(plane, p) =
|
|||
// Function: cylindrical_to_xyz()
|
||||
// Usage:
|
||||
// pt = cylindrical_to_xyz(r, theta, z);
|
||||
// pt = cylindrical_to_xyz([r, theta, z]);
|
||||
// pt = cylindrical_to_xyz([RADIUS,THETA,Z]);
|
||||
// pts = cylindrical_to_xyz([[RADIUS,THETA,Z], [RADIUS,THETA,Z], ...]);
|
||||
// Topics: Coordinates, Points, Paths
|
||||
// See Also: xyz_to_cylindrical(), xy_to_polar(), polar_to_xy(), xyz_to_spherical(), spherical_to_xyz()
|
||||
// Synopsis: Convert cylindrical coordinates to cartesian coordinates.
|
||||
// Description:
|
||||
// Convert cylindrical coordinates to 3D cartesian coordinates. Returns [X,Y,Z] cartesian coordinates.
|
||||
// Called with three arguments, converts the `r`, `theta`, and 'z' 3D cylindrical coordinate into an `[X,Y,Z]` cartesian coordinate.
|
||||
// Called with one `[RADIUS,THETA,Z]` vector argument, converts the 3D cylindrical coordinate into an `[X,Y,Z]` cartesian coordinate.
|
||||
// Called with a list of `[RADIUS,THETA,Z]` vector arguments, converts each 3D cylindrical coordinate into `[X,Y,Z]` cartesian coordinates.
|
||||
// Theta is the angle counter-clockwise of X+ on the XY plane. Z is height above the XY plane.
|
||||
// Arguments:
|
||||
// r = distance from the Z axis.
|
||||
// theta = angle in degrees, counter-clockwise of X+ on the XY plane.
|
||||
|
@ -337,22 +357,28 @@ function lift_plane(plane, p) =
|
|||
// Example:
|
||||
// xyz = cylindrical_to_xyz(20,30,40);
|
||||
// xyz = cylindrical_to_xyz([40,60,50]);
|
||||
function cylindrical_to_xyz(r,theta=undef,z=undef) = let(
|
||||
rad = theta==undef? r[0] : r,
|
||||
t = theta==undef? r[1] : theta,
|
||||
zed = theta==undef? r[2] : z
|
||||
) [rad*cos(t), rad*sin(t), zed];
|
||||
function cylindrical_to_xyz(r,theta,z) =
|
||||
theta != undef
|
||||
? assert(is_num(r) && is_num(theta) && is_num(z), "Bad Arguments.")
|
||||
[r*cos(theta), r*sin(theta), z]
|
||||
: assert(is_list(r), "Bad Arguments")
|
||||
is_num(r.x)
|
||||
? cylindrical_to_xyz(r.x, r.y, r.z)
|
||||
: [for(p = r) cylindrical_to_xyz(p.x, p.y, p.z)];
|
||||
|
||||
|
||||
// Function: xyz_to_cylindrical()
|
||||
// Usage:
|
||||
// rtz = xyz_to_cylindrical(x,y,z);
|
||||
// rtz = xyz_to_cylindrical([X,Y,Z]);
|
||||
// rtzs = xyz_to_cylindrical([[X,Y,Z], [X,Y,Z], ...]);
|
||||
// Topics: Coordinates, Points, Paths
|
||||
// Synopsis: Convert 3d cartesian coordinates to cylindrical coordinates.
|
||||
// See Also: cylindrical_to_xyz(), xy_to_polar(), polar_to_xy(), xyz_to_spherical(), spherical_to_xyz()
|
||||
// Description:
|
||||
// Convert 3D cartesian coordinates to cylindrical coordinates. Returns [radius,theta,Z].
|
||||
// Called with three arguments, converts the `x`, `y`, and `z` 3D cartesian coordinate into a `[RADIUS,THETA,Z]` cylindrical coordinate.
|
||||
// Called with one `[X,Y,Z]` vector argument, converts the 3D cartesian coordinate into a `[RADIUS,THETA,Z]` cylindrical coordinate.
|
||||
// Called with a list of `[X,Y,Z]` vector arguments, converts each 3D cartesian coordinate into `[RADIUS,THETA,Z]` cylindrical coordinates.
|
||||
// Theta is the angle counter-clockwise of X+ on the XY plane. Z is height above the XY plane.
|
||||
// Arguments:
|
||||
// x = X coordinate.
|
||||
|
@ -361,17 +387,27 @@ function cylindrical_to_xyz(r,theta=undef,z=undef) = let(
|
|||
// Example:
|
||||
// cyl = xyz_to_cylindrical(20,30,40);
|
||||
// cyl = xyz_to_cylindrical([40,50,70]);
|
||||
function xyz_to_cylindrical(x,y=undef,z=undef) = let(
|
||||
p = is_num(x)? [x, default(y,0), default(z,0)] : point3d(x)
|
||||
) [norm([p.x,p.y]), atan2(p.y,p.x), p.z];
|
||||
// cyls = xyz_to_cylindrical([[40,50,70], [-10,15,-30]]);
|
||||
function xyz_to_cylindrical(x,y,z) =
|
||||
y != undef
|
||||
? assert(is_num(x) && is_num(y) && is_num(z), "Bad Arguments.")
|
||||
[norm([x,y]), atan2(y,x), z]
|
||||
: assert(is_list(x), "Bad Arguments")
|
||||
is_num(x.x)
|
||||
? xyz_to_cylindrical(x.x, x.y, x.z)
|
||||
: [for(p = x) xyz_to_cylindrical(p.x, p.y, p.z)];
|
||||
|
||||
|
||||
// Function: spherical_to_xyz()
|
||||
// Usage:
|
||||
// pt = spherical_to_xyz(r, theta, phi);
|
||||
// pt = spherical_to_xyz([r, theta, phi]);
|
||||
// pt = spherical_to_xyz([RADIUS,THETA,PHI]);
|
||||
// pts = spherical_to_xyz([[RADIUS,THETA,PHI], [RADIUS,THETA,PHI], ...]);
|
||||
// Description:
|
||||
// Convert spherical coordinates to 3D cartesian coordinates. Returns [X,Y,Z] cartesian coordinates.
|
||||
// Called with three arguments, converts the `r`, `theta`, and 'phi' 3D spherical coordinate into an `[X,Y,Z]` cartesian coordinate.
|
||||
// Called with one `[RADIUS,THETA,PHI]` vector argument, converts the 3D spherical coordinate into an `[X,Y,Z]` cartesian coordinate.
|
||||
// Called with a list of `[RADIUS,THETA,PHI]` vector arguments, converts each 3D spherical coordinate into `[X,Y,Z]` cartesian coordinates.
|
||||
// Theta is the angle counter-clockwise of X+ on the XY plane. Phi is the angle down from the Z+ pole.
|
||||
// Synopsis: Convert spherical coordinates to 3d cartesian coordinates.
|
||||
// Topics: Coordinates, Points, Paths
|
||||
// See Also: cylindrical_to_xyz(), xyz_to_spherical(), xyz_to_cylindrical(), altaz_to_xyz(), xyz_to_altaz()
|
||||
|
@ -382,23 +418,30 @@ function xyz_to_cylindrical(x,y=undef,z=undef) = let(
|
|||
// Example:
|
||||
// xyz = spherical_to_xyz(20,30,40);
|
||||
// xyz = spherical_to_xyz([40,60,50]);
|
||||
function spherical_to_xyz(r,theta=undef,phi=undef) = let(
|
||||
rad = theta==undef? r[0] : r,
|
||||
t = theta==undef? r[1] : theta,
|
||||
p = theta==undef? r[2] : phi
|
||||
) rad*[sin(p)*cos(t), sin(p)*sin(t), cos(p)];
|
||||
// xyzs = spherical_to_xyz([[40,60,50], [50,120,100]]);
|
||||
function spherical_to_xyz(r,theta,phi) =
|
||||
theta != undef
|
||||
? assert(is_num(r) && is_num(theta) && is_num(phi), "Bad Arguments.")
|
||||
r*[cos(theta)*sin(phi), sin(theta)*sin(phi), cos(phi)]
|
||||
: assert(is_list(r), "Bad Arguments")
|
||||
is_num(r.x)
|
||||
? spherical_to_xyz(r.x, r.y, r.z)
|
||||
: [for(p = r) spherical_to_xyz(p.x, p.y, p.z)];
|
||||
|
||||
|
||||
// Function: xyz_to_spherical()
|
||||
// Usage:
|
||||
// r_theta_phi = xyz_to_spherical(x,y,z)
|
||||
// r_theta_phi = xyz_to_spherical([X,Y,Z])
|
||||
// r_theta_phis = xyz_to_spherical([[X,Y,Z], [X,Y,Z], ...])
|
||||
// Topics: Coordinates, Points, Paths
|
||||
// Synopsis: Convert 3d cartesian coordinates to spherical coordinates.
|
||||
// See Also: cylindrical_to_xyz(), spherical_to_xyz(), xyz_to_cylindrical(), altaz_to_xyz(), xyz_to_altaz()
|
||||
// Description:
|
||||
// Convert 3D cartesian coordinates to spherical coordinates. Returns [r,theta,phi], where phi is
|
||||
// the angle from the Z+ pole, and theta is degrees counter-clockwise of X+ on the XY plane.
|
||||
// Called with three arguments, converts the `x`, `y`, and `z` 3D cartesian coordinate into a `[RADIUS,THETA,PHI]` spherical coordinate.
|
||||
// Called with one `[X,Y,Z]` vector argument, converts the 3D cartesian coordinate into a `[RADIUS,THETA,PHI]` spherical coordinate.
|
||||
// Called with a list of `[X,Y,Z]` vector arguments, converts each 3D cartesian coordinate into `[RADIUS,THETA,PHI]` spherical coordinates.
|
||||
// Theta is the angle counter-clockwise of X+ on the XY plane. Phi is the angle down from the Z+ pole.
|
||||
// Arguments:
|
||||
// x = X coordinate.
|
||||
// y = Y coordinate.
|
||||
|
@ -406,21 +449,31 @@ function spherical_to_xyz(r,theta=undef,phi=undef) = let(
|
|||
// Example:
|
||||
// sph = xyz_to_spherical(20,30,40);
|
||||
// sph = xyz_to_spherical([40,50,70]);
|
||||
function xyz_to_spherical(x,y=undef,z=undef) = let(
|
||||
p = is_num(x)? [x, default(y,0), default(z,0)] : point3d(x)
|
||||
) [norm(p), atan2(p.y,p.x), atan2(norm([p.x,p.y]),p.z)];
|
||||
// sphs = xyz_to_spherical([[40,50,70], [25,-14,27]]);
|
||||
function xyz_to_spherical(x,y,z) =
|
||||
y != undef
|
||||
? assert(is_num(x) && is_num(y) && is_num(z), "Bad Arguments.")
|
||||
[norm([x,y,z]), atan2(y,x), atan2(norm([x,y]),z)]
|
||||
: assert(is_list(x), "Bad Arguments")
|
||||
is_num(x.x)
|
||||
? xyz_to_spherical(x.x, x.y, x.z)
|
||||
: [for(p = x) xyz_to_spherical(p.x, p.y, p.z)];
|
||||
|
||||
|
||||
// Function: altaz_to_xyz()
|
||||
// Usage:
|
||||
// pt = altaz_to_xyz(alt, az, r);
|
||||
// pt = altaz_to_xyz([alt, az, r]);
|
||||
// pt = altaz_to_xyz([ALT,AZ,R]);
|
||||
// pts = altaz_to_xyz([[ALT,AZ,R], [ALT,AZ,R], ...]);
|
||||
// Topics: Coordinates, Points, Paths
|
||||
// See Also: cylindrical_to_xyz(), xyz_to_spherical(), spherical_to_xyz(), xyz_to_cylindrical(), xyz_to_altaz()
|
||||
// Synopsis: Convert altitude/azimuth/range to 3d cartesian coordinates.
|
||||
// Description:
|
||||
// Convert altitude/azimuth/range coordinates to 3D cartesian coordinates.
|
||||
// Returns [X,Y,Z] cartesian coordinates.
|
||||
// Called with three arguments, converts the `alt`, `az`, and 'r' 3D altitude-azimuth coordinate into an `[X,Y,Z]` cartesian coordinate.
|
||||
// Called with one `[ALTITUDE,AZIMUTH,RANGE]` vector argument, converts the 3D alt-az coordinate into an `[X,Y,Z]` cartesian coordinate.
|
||||
// Called with a list of `[ALTITUDE,AZIMUTH,RANGE]` vector arguments, converts each 3D alt-az coordinate into `[X,Y,Z]` cartesian coordinates.
|
||||
// Altitude is the angle above the XY plane, Azimuth is degrees clockwise of Y+ on the XY plane, and Range is the distance from the origin.
|
||||
// Arguments:
|
||||
// alt = altitude angle in degrees above the XY plane.
|
||||
// az = azimuth angle in degrees clockwise of Y+ on the XY plane.
|
||||
|
@ -428,25 +481,31 @@ function xyz_to_spherical(x,y=undef,z=undef) = let(
|
|||
// Example:
|
||||
// xyz = altaz_to_xyz(20,30,40);
|
||||
// xyz = altaz_to_xyz([40,60,50]);
|
||||
function altaz_to_xyz(alt,az=undef,r=undef) = let(
|
||||
p = az==undef? alt[0] : alt,
|
||||
t = 90 - (az==undef? alt[1] : az),
|
||||
rad = az==undef? alt[2] : r
|
||||
) rad*[cos(p)*cos(t), cos(p)*sin(t), sin(p)];
|
||||
function altaz_to_xyz(alt,az,r) =
|
||||
az != undef
|
||||
? assert(is_num(alt) && is_num(az) && is_num(r), "Bad Arguments.")
|
||||
r*[cos(90-az)*cos(alt), sin(90-az)*cos(alt), sin(alt)]
|
||||
: assert(is_list(alt), "Bad Arguments")
|
||||
is_num(alt.x)
|
||||
? altaz_to_xyz(alt.x, alt.y, alt.z)
|
||||
: [for(p = alt) altaz_to_xyz(p.x, p.y, p.z)];
|
||||
|
||||
|
||||
|
||||
// Function: xyz_to_altaz()
|
||||
// Usage:
|
||||
// alt_az_r = xyz_to_altaz(x,y,z);
|
||||
// alt_az_r = xyz_to_altaz([X,Y,Z]);
|
||||
// alt_az_rs = xyz_to_altaz([[X,Y,Z], [X,Y,Z], ...]);
|
||||
// Topics: Coordinates, Points, Paths
|
||||
// See Also: cylindrical_to_xyz(), xyz_to_spherical(), spherical_to_xyz(), xyz_to_cylindrical(), altaz_to_xyz()
|
||||
// Synopsis: Convert 3d cartesian coordinates to [altitude,azimuth,range].
|
||||
// Description:
|
||||
// Convert 3D cartesian coordinates to altitude/azimuth/range coordinates.
|
||||
// Returns [altitude,azimuth,range], where altitude is angle above the
|
||||
// XY plane, azimuth is degrees clockwise of Y+ on the XY plane, and
|
||||
// range is the distance from the origin.
|
||||
// Converts 3D cartesian coordinates to altitude/azimuth/range coordinates.
|
||||
// Called with three arguments, converts the `x`, `y`, and `z` 3D cartesian coordinate into an `[ALTITUDE,AZIMUTH,RANGE]` coordinate.
|
||||
// Called with one `[X,Y,Z]` vector argument, converts the 3D cartesian coordinate into a `[ALTITUDE,AZIMUTH,RANGE]` coordinate.
|
||||
// Called with a list of `[X,Y,Z]` vector arguments, converts each 3D cartesian coordinate into `[ALTITUDE,AZIMUTH,RANGE]` coordinates.
|
||||
// Altitude is the angle above the XY plane, Azimuth is degrees clockwise of Y+ on the XY plane, and Range is the distance from the origin.
|
||||
// Arguments:
|
||||
// x = X coordinate.
|
||||
// y = Y coordinate.
|
||||
|
@ -454,9 +513,14 @@ function altaz_to_xyz(alt,az=undef,r=undef) = let(
|
|||
// Example:
|
||||
// aa = xyz_to_altaz(20,30,40);
|
||||
// aa = xyz_to_altaz([40,50,70]);
|
||||
function xyz_to_altaz(x,y=undef,z=undef) = let(
|
||||
p = is_num(x)? [x, default(y,0), default(z,0)] : point3d(x)
|
||||
) [atan2(p.z,norm([p.x,p.y])), atan2(p.x,p.y), norm(p)];
|
||||
function xyz_to_altaz(x,y,z) =
|
||||
y != undef
|
||||
? assert(is_num(x) && is_num(y) && is_num(z), "Bad Arguments.")
|
||||
[atan2(z,norm([x,y])), atan2(x,y), norm([x,y,z])]
|
||||
: assert(is_list(x), "Bad Arguments")
|
||||
is_num(x.x)
|
||||
? xyz_to_altaz(x.x, x.y, x.z)
|
||||
: [for(p = x) xyz_to_altaz(p.x, p.y, p.z)];
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue