[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Surface.java, 1.218, 1.219 Geometry.
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2008-01-25 13:06:05
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv30394/src/net/sourceforge/bprocessor/model Modified Files: Surface.java Geometry.java Command.java Log Message: Cylinder Index: Surface.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v retrieving revision 1.218 retrieving revision 1.219 diff -C2 -d -r1.218 -r1.219 *** Surface.java 24 Jan 2008 10:35:35 -0000 1.218 --- Surface.java 25 Jan 2008 13:06:02 -0000 1.219 *************** *** 552,574 **** /** - * Compute the traversed angle of this Surface - * @return The angle - */ - public double angle() { - return angle(coordinateSystem()); - } - - /** - * Compute the traversed angle of this Surface - * @param coordinateSystem The CoordinateSystem - * @return The angle - */ - public double angle(CoordinateSystem coordinateSystem) { - List vertices = getVertices(); - vertices = coordinateSystem.translate(vertices); - return Geometry.angle(vertices); - } - - /** * Get the hole surfaces * @return The hole surfaces --- 552,555 ---- Index: Command.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Command.java,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** Command.java 22 Jan 2008 13:12:58 -0000 1.65 --- Command.java 25 Jan 2008 13:06:02 -0000 1.66 *************** *** 853,856 **** --- 853,922 ---- Surface bottom = new Surface(edges); Container space = Project.getInstance().getActiveSpace(); + Container union = new Container("Cylinder", Container.CONSTRUCTION, true); + Set<Surface> sides = new HashSet<Surface>(); + Surface top = bottom.extrusion(h, sides); + + union.insert(bottom); + for (Surface surface : sides) { + union.insert(surface); + } + Collection<Edge> visibleEdges = Surface.edges(sides); + visibleEdges.removeAll(top.getEdges()); + visibleEdges.removeAll(bottom.getEdges()); + for (Edge e : visibleEdges) { + e.setSmooth(true); + } + sides.add(top); + sides.add(bottom); + union.insert(top); + + space.add(union); + } + } + + /** + * A command to create a cylinder + */ + public static class Cylinder0 extends Command { + /** + * + */ + public Cylinder0() { + parameters.add(new Attribute("radius", 1.0)); + parameters.add(new Attribute("height", 3.0)); + parameters.add(new Attribute("slices", 10.0)); + } + + /** {@inheritDoc}} */ + @Override + public String title() { + return "Create Cylinder"; + } + + /** {@inheritDoc}} */ + @Override + public void evaluate() { + double r = parameters.getDouble("radius"); + double h = parameters.getDouble("height"); + int s = (int) parameters.getDouble("slices"); + + List<Edge> edges = new LinkedList<Edge>(); + Vertex first = null, prev = null; + for (int i = 0; i < s; i++) { + double val = i * Math.PI * 2 / s; + double sin = Math.sin(val) * r; + double cos = Math.cos(val) * r; + Vertex cur = new Vertex(cos, sin, 0); + if (first == null) { + first = cur; + } + if (prev != null) { + edges.add(new Edge(prev, cur)); + } + prev = cur; + } + edges.add(new Edge(prev, first)); + Surface bottom = new Surface(edges); + Container space = Project.getInstance().getActiveSpace(); Container inside = space.createConstructionSpace("Cylinder"); bottom.setFrontDomain(inside); Index: Geometry.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Geometry.java,v retrieving revision 1.70 retrieving revision 1.71 diff -C2 -d -r1.70 -r1.71 *** Geometry.java 24 Jan 2008 10:35:35 -0000 1.70 --- Geometry.java 25 Jan 2008 13:06:02 -0000 1.71 *************** *** 105,156 **** /** - * Calculate the normal that points outwards - * @param vertices The vertices describing a planar polygon - * @return The outwards pointing normal - */ - public static Vertex normal(List vertices) { - Vertex normal = normal0(vertices); - if (normal == null) { - return null; - } - Vertex origin = (Vertex) vertices.get(0); - Vertex a = (Vertex) vertices.get(1); - Vertex i = a.minus(origin); - Vertex j = normal.cross(i); - CoordinateSystem system = new CoordinateSystem(i, j, normal, origin); - List projection = system.translate(vertices); - double tetra = angle(projection); - if (tetra > 0) { - normal.scaleIt(-1); - } - normal.scaleIt(1 / normal.length()); - return normal; - } - - /** - * Calculate some normal vector - * @param vertices The vertices describing a planar polygon - * @return A normal vector - */ - public static Vertex normal0(List vertices) { - if (vertices.size() < 2) { - return null; - } else { - Vertex a = (Vertex) vertices.get(0); - Vertex b = (Vertex) vertices.get(1); - Vertex v1 = b.minus(a); - for (int i = 2; i < vertices.size(); i++) { - Vertex c = (Vertex) vertices.get(i); - Vertex v2 = c.minus(b); - Vertex normal = v1.cross(v2); - if (!normal.isZero()) { - return normal; - } - } - } - return null; - } - - /** * Rotate * @param angle The angle --- 105,108 ---- *************** *** 202,257 **** } - - /** - * Calculate the projection of the vertices into the - * specified plane. - * @param vertices The vertices to project - * @param origin The origin of the plane - * @param normal The normal to the plane - * @return The projection - */ - public static List projection(List vertices, Vertex origin, Vertex normal) { - List projection = new ArrayList(); - - // TODO The following projection calculation should - // be done using a plane. - - for (int i = 0; i < vertices.size(); i++) { - Vertex current = (Vertex) vertices.get(i); - Vertex v = current.minus(origin); - double t = v.dot(normal); - Vertex up = normal.copy(); - up.scaleIt(t); - projection.add(v.minus(up)); - } - return projection; - } - - /** - * Calculate the turn angle of the vertices, which - * are assumed to be 2d (z is ignored). - * @param vertices The vertices to calculate the turn angle for - * @return The turn angle - */ - public static double angle(List vertices) { - Vertex first = (Vertex) vertices.get(0); - Vertex last = (Vertex) vertices.get(vertices.size() - 1); - vertices.add(first); - vertices.add(0, last); - Vertex[] vertexarray = new Vertex[vertices.size()]; - vertices.toArray(vertexarray); - - double tetra = 0.0; - for (int i = 1; i <= (vertexarray.length - 2); i++) { - double dxi = vertexarray[i + 1].getX() - vertexarray[i].getX(); - double dxi1 = vertexarray[i].getX() - vertexarray[i - 1].getX(); - double dyi = vertexarray[i + 1].getY() - vertexarray[i].getY(); - double dyi1 = vertexarray[i].getY() - vertexarray[i - 1].getY(); - double tetrai = Math.atan2((dxi * dyi1 - dxi1 * dyi), (dxi * dxi1 + dyi * dyi1)); - tetra += tetrai; - } - return tetra; - } - /** * Test if exterior contains interior --- 154,157 ---- |