summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2009-06-23 11:28:35 (GMT)
committerclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2009-06-23 11:28:35 (GMT)
commit0fcdcb6bd6117e8e8ccaff15b0a083c2f76266a6 (patch)
tree3935db3fda7426d1b7180c8fc15f2069301aee76
parent9271046a02c5e8b62a9ed92e914ab6cf30938fc7 (diff)
Clifford Wolf:
Added cylinder primitive git-svn-id: http://svn.clifford.at/openscad/trunk@12 b57f626f-c46c-0410-a088-ec61d464b74c
-rw-r--r--csg.cc10
-rw-r--r--example.scad8
-rw-r--r--openscad.h1
-rw-r--r--primitive.cc43
4 files changed, 52 insertions, 10 deletions
diff --git a/csg.cc b/csg.cc
index 04f6798..3ad02d6 100644
--- a/csg.cc
+++ b/csg.cc
@@ -25,7 +25,7 @@
enum csg_type_e {
UNION,
DIFFERENCE,
- INTERSECT
+ INTERSECTION
};
class CsgModule : public AbstractModule
@@ -68,7 +68,7 @@ CGAL_Nef_polyhedron CsgNode::render_cgal_nef_polyhedron() const
N += v->render_cgal_nef_polyhedron();
} else if (type == DIFFERENCE) {
N -= v->render_cgal_nef_polyhedron();
- } else if (type == INTERSECT) {
+ } else if (type == INTERSECTION) {
N *= v->render_cgal_nef_polyhedron();
}
}
@@ -83,8 +83,8 @@ QString CsgNode::dump(QString indent) const
text += "union() {\n";
if (type == DIFFERENCE)
text += "difference() {\n";
- if (type == INTERSECT)
- text += "intersect() {\n";
+ if (type == INTERSECTION)
+ text += "intersection() {\n";
foreach (AbstractNode *v, children)
text += v->dump(indent + QString("\t"));
return text + indent + "}\n";
@@ -94,6 +94,6 @@ void register_builtin_csg()
{
builtin_modules["union"] = new CsgModule(UNION);
builtin_modules["difference"] = new CsgModule(DIFFERENCE);
- builtin_modules["intersect"] = new CsgModule(INTERSECT);
+ builtin_modules["intersection"] = new CsgModule(INTERSECTION);
}
diff --git a/example.scad b/example.scad
index 9f21ea7..b74c29c 100644
--- a/example.scad
+++ b/example.scad
@@ -29,5 +29,11 @@ module test002()
}
}
-test002();
+module test003()
+{
+ cylinder(h = 5, r1 = 3, r2 = 1, center = true);
+ // cylinder(h = 7, r1 = 1, r2 = 5, center = true);
+}
+
+test003();
diff --git a/openscad.h b/openscad.h
index 48d6c1e..f0b1e33 100644
--- a/openscad.h
+++ b/openscad.h
@@ -241,7 +241,6 @@ public:
#include <CGAL/IO/Polyhedron_iostream.h>
typedef CGAL::Cartesian<CGAL::Gmpq> CGAL_Kernel;
-// typedef CGAL::Extended_cartesian<CGAL::Gmpq> CGAL_Kernel;
typedef CGAL::Polyhedron_3<CGAL_Kernel> CGAL_Polyhedron;
typedef CGAL_Polyhedron::HalfedgeDS CGAL_HDS;
typedef CGAL::Polyhedron_incremental_builder_3<CGAL_HDS> CGAL_Polybuilder;
diff --git a/primitive.cc b/primitive.cc
index 91f84d5..48d819f 100644
--- a/primitive.cc
+++ b/primitive.cc
@@ -112,7 +112,7 @@ AbstractNode *PrimitiveModule::evaluate(const Context *ctx, const QVector<QStrin
node->r1 = r1.num;
}
if (r2.type == Value::NUMBER) {
- node->r2 = r2.x;
+ node->r2 = r2.num;
}
if (center.type == Value::BOOL) {
node->center = center.b;
@@ -192,8 +192,42 @@ public:
if (n->type == CYLINDER) {
int fragments = 10;
- B.begin_surface(fragments*2, fragments+2);
- /* FIXME */
+ B.begin_surface(fragments*2, fragments*2+2);
+ double z1, z2;
+ if (n->center) {
+ z1 = -n->h/2;
+ z2 = +n->h/2;
+ } else {
+ z1 = 0;
+ z2 = n->h;
+ }
+ for (int i=0; i<fragments; i++) {
+ double phi = (M_PI*2*i) / fragments;
+ B.add_vertex(Point(n->r1*cos(phi), n->r1*sin(phi), z1));
+ B.add_vertex(Point(n->r2*cos(phi), n->r2*sin(phi), z2));
+ }
+ for (int i=0; i<fragments; i++) {
+ B.begin_facet();
+ B.add_vertex_to_facet(i*2);
+ B.add_vertex_to_facet(i*2+1);
+ B.add_vertex_to_facet(((i+1)%fragments)*2);
+ B.end_facet();
+ B.begin_facet();
+ B.add_vertex_to_facet(i*2+1);
+ B.add_vertex_to_facet(((i+1)%fragments)*2+1);
+ B.add_vertex_to_facet(((i+1)%fragments)*2);
+ B.end_facet();
+ }
+ B.begin_facet();
+ for (int i=0; i<fragments; i++) {
+ B.add_vertex_to_facet(i*2);
+ }
+ B.end_facet();
+ B.begin_facet();
+ for (int i=fragments-1; i>=0; i--) {
+ B.add_vertex_to_facet(i*2+1);
+ }
+ B.end_facet();
B.end_surface();
}
}
@@ -204,6 +238,9 @@ CGAL_Nef_polyhedron PrimitiveNode::render_cgal_nef_polyhedron() const
CGAL_Polyhedron P;
CGAL_Build_cube builder(this);
P.delegate(builder);
+#if 0
+ std::cout << P;
+#endif
CGAL_Nef_polyhedron N(P);
progress_report();
return N;
contact: Jan Huwald // Impressum