summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/example015.scad23
-rw-r--r--primitives.cc36
-rw-r--r--transform.cc2
3 files changed, 53 insertions, 8 deletions
diff --git a/examples/example015.scad b/examples/example015.scad
index ddf907a..a39d384 100644
--- a/examples/example015.scad
+++ b/examples/example015.scad
@@ -1,9 +1,18 @@
-union() {
- difference() {
- square(100, true);
- square(50, true);
+difference()
+{
+ translate([ -35, -35 ]) intersection()
+ {
+ union() {
+ difference() {
+ square(100, true);
+ square(50, true);
+ }
+ translate([ 50, 50 ])
+ square(15, true);
+ }
+ rotate(45) translate([ 0, -15 ]) square([ 100, 30 ]);
}
- translate([50, 50])
- square(15, true);
-} \ No newline at end of file
+
+ rotate(-45) scale([ 0.7, 1.3 ]) circle(5);
+}
diff --git a/primitives.cc b/primitives.cc
index 893a0aa..90a22ba 100644
--- a/primitives.cc
+++ b/primitives.cc
@@ -27,7 +27,8 @@ enum primitive_type_e {
SPHERE,
CYLINDER,
POLYHEDRON,
- SQUARE
+ SQUARE,
+ CIRCLE
};
class PrimitiveModule : public AbstractModule
@@ -76,6 +77,9 @@ AbstractNode *PrimitiveModule::evaluate(const Context *ctx, const ModuleInstanci
if (type == SQUARE) {
argnames = QVector<QString>() << "size" << "center";
}
+ if (type == CIRCLE) {
+ argnames = QVector<QString>() << "r";
+ }
Context c(ctx);
c.args(argnames, argexpr, inst->argnames, inst->argvalues);
@@ -145,6 +149,13 @@ AbstractNode *PrimitiveModule::evaluate(const Context *ctx, const ModuleInstanci
}
}
+ if (type == CIRCLE) {
+ Value r = c.lookup_variable("r");
+ if (r.type == Value::NUMBER) {
+ node->r1 = r.num;
+ }
+ }
+
return node;
}
@@ -155,6 +166,7 @@ void register_builtin_primitives()
builtin_modules["cylinder"] = new PrimitiveModule(CYLINDER);
builtin_modules["polyhedron"] = new PrimitiveModule(POLYHEDRON);
builtin_modules["square"] = new PrimitiveModule(SQUARE);
+ builtin_modules["circle"] = new PrimitiveModule(CIRCLE);
}
int get_fragments_from_r(double r, double fn, double fs, double fa)
@@ -395,6 +407,28 @@ sphere_next_r2:
p->append_vertex(x1, y2);
}
+ if (type == CIRCLE)
+ {
+ int fragments = get_fragments_from_r(r1, fn, fs, fa);
+
+ struct point2d {
+ double x, y;
+ };
+
+ point2d circle[fragments];
+
+ for (int i=0; i<fragments; i++) {
+ double phi = (M_PI*2*i) / fragments;
+ circle[i].x = r1*cos(phi);
+ circle[i].y = r1*sin(phi);
+ }
+
+ p->is2d = true;
+ p->append_poly();
+ for (int i=0; i<fragments; i++)
+ p->append_vertex(circle[i].x, circle[i].y);
+ }
+
return p;
}
diff --git a/transform.cc b/transform.cc
index ff27e80..b7408d7 100644
--- a/transform.cc
+++ b/transform.cc
@@ -83,6 +83,8 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanci
v.getnum(node->m[5]);
v.getnum(node->m[10]);
v.getv3(node->m[0], node->m[5], node->m[10]);
+ if (node->m[10] <= 0)
+ node->m[10] = 1;
}
if (type == ROTATE)
{
contact: Jan Huwald // Impressum