chiark / gitweb /
funcs.scad.cpp: rename 2d things 2d, provide tangents_intersect_beta
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 23 Feb 2014 18:25:47 +0000 (18:25 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 23 Feb 2014 18:25:47 +0000 (18:25 +0000)
funcs.scad.cpp

index 29d5a1e..007ac45 100644 (file)
@@ -1,14 +1,17 @@
 // -*- C -*-
 
-function dist(a,b) =
+function vecdiff2d(a,b) = [b[0]-a[0], b[1]-a[1]];
+function vecdiff(a,b)   = [b[0]-a[0], b[1]-a[1], b[2]-a[2]];
+
 #define dsq(i) (a[i]-b[i])*(a[i]-b[i])
-              sqrt(dsq(0) + dsq(1));
+function dist2d(a,b) = sqrt(dsq(0) + dsq(1));
+function dist(a,b)   = sqrt(dsq(0) + dsq(1) + dsq(2));
 #undef dsq
 
 function circle_point(c, r, alpha) = [ c[0] + r * cos(alpha),
                                       c[1] + r * sin(alpha) ];
 
-#define d     (dist(a,c))
+#define d     (dist2d(a,c))
 #define alpha (atan2(a[1]-c[1],a[0]-c[0]))
 #define gamma (asin(r / d))
 #define beta  (alpha + 90 - gamma)
@@ -23,5 +26,8 @@ function tangent_intersect_b(c,r,a) =
 #undef gamma
 #undef beta
 
+function tangents_intersect_beta(cbig,rbig,csmall,rsmall) =
+        tangent_intersect_beta(cbig,rbig-rsmall,csmall);
+
 function reflect_in_y(p) = [-p[0], p[1]];