public static void main(String[] args) { List<Shape2D> listShape2D = new ArrayList<Shape2D>(); listShape2D.add(new Point2D(1, 1)); listShape2D.add(new Line2D(new Point2D(1, 1), new Point2D(1, 3))); listShape2D.add(new Circle2D(new Point2D(1, 1), 2)); listShape2D.add(new Ellipse2D(new Point2D(1, 1), 2, 4)); listShape2D.add(new Rectangle2D(2, 4, new Point2D(1, 1))); listShape2D.add(new Parallelogram2D(2, 4, new Point2D(1, 1), 40)); listShape2D.add(new Square2D(4, new Point2D(1, 1))); listShape2D.add(new Rhombus2D(2, new Point2D(1, 1), 30, 40)); listShape2D.add(new Trapeze2D(10, 5, new Point2D(1, 1), 30, 30, 5)); listShape2D.add(new Triangle2D(new Point2D(1, 1), new Point2D(1, 4), new Point2D(6, 1))); List<Point2D> listPoint = new ArrayList<Point2D>(); listPoint.add(new Point2D(1, 1)); listPoint.add(new Point2D(1, 4)); listPoint.add(new Point2D(4, 4)); listPoint.add(new Point2D(4, 1)); listShape2D.add(new Polygon2D(listPoint)); Iterator<Shape2D> iterator = listShape2D.iterator(); while (iterator.hasNext()) { Shape2D shape2d = iterator.next(); shape2d.drow(); System.out.println("Площадь = " + shape2d.area()); } }
/* (non-Javadoc) * @see math.geom2d.Shape2D#transform(math.geom2d.AffineTransform2D) */ public ShapeSet2D<? extends Shape2D> transform(AffineTransform2D trans) { // Allocate array for result ShapeArray2D<Shape2D> result = new ShapeArray2D<Shape2D>(shapes.size()); // add each transformed curve for (Shape2D shape : this.shapes) result.add(shape.transform(trans)); return result; }
public Shape2D convertTo2D() { Point p1, p2; Shape2D shape = new Shape2D(); for (Line3D line : this.lines) { p1 = this.camera.project(line.getStart()); p2 = this.camera.project(line.getEnd()); shape.addLine(new Line2D(p1, p2)); } return shape; }
/* (non-Javadoc) * @see math.geom2d.Shape2D#getBoundingBox() */ public Box2D boundingBox() { double xmin = Double.MAX_VALUE; double ymin = Double.MAX_VALUE; double xmax = Double.MIN_VALUE; double ymax = Double.MIN_VALUE; Box2D box; for (Shape2D shape : shapes) { box = shape.boundingBox(); xmin = Math.min(xmin, box.getMinX()); ymin = Math.min(ymin, box.getMinY()); xmax = Math.max(xmax, box.getMaxX()); ymax = Math.max(ymax, box.getMaxY()); } return new Box2D(xmin, xmax, ymin, ymax); }
/* (non-Javadoc) * @see math.geom2d.Shape2D#isBounded() */ public boolean isBounded() { for (Shape2D shape : shapes) if (!shape.isBounded()) return false; return true; }
/* (non-Javadoc) * @see math.geom2d.Shape2D#getDistance(double, double) */ public double distance(double x, double y) { double dist = Double.POSITIVE_INFINITY; for (Shape2D shape : shapes) dist = Math.min(dist, shape.distance(x, y)); return dist; }
/* (non-Javadoc) * @see math.geom2d.Shape2D#draw(java.awt.Graphics2D) */ public void draw(Graphics2D g2) { for (Shape2D shape : shapes) shape.draw(g2); }
/* (non-Javadoc) * @see math.geom2d.Shape2D#contains(double, double) */ public boolean contains(double x, double y) { for (Shape2D shape : shapes) { if (shape.contains(x, y)) return true; } return false; }