List of usage examples for java.awt.geom GeneralPath quadTo
public abstract void quadTo(double x1, double y1, double x2, double y2);
From source file:Main.java
public static void main(String[] args) { GeneralPath shape = new GeneralPath(); shape.moveTo(1, 1);// w ww. j a va 2 s .c o m shape.lineTo(2, 2); shape.quadTo(3, 3, 4, 4); shape.curveTo(5, 5, 6, 6, 7, 7); shape.closePath(); }
From source file:Main.java
public static void main(String[] args) { GeneralPath shape = new GeneralPath(); shape.moveTo(1, 1);/*from w ww . java2 s.c o m*/ shape.lineTo(2, 2); shape.quadTo(3, 3, 4, 4); shape.curveTo(5, 5, 6, 6, 7, 7); shape.closePath(); System.out.println("done"); }
From source file:Hypnosis1.java
private Shape createShape() { GeneralPath path = new GeneralPath(); path.moveTo(coordinates[0], coordinates[1]); for (int i = 2; i < coordinates.length; i += 4) path.quadTo(coordinates[i], coordinates[i + 1], coordinates[i + 2], coordinates[i + 3]); path.closePath();//from w ww. java2s . c o m return path; }
From source file:Main.java
/** * Reads a <code>Shape</code> object that has been serialised by the * {@link #writeShape(Shape, ObjectOutputStream)} method. * * @param stream the input stream (<code>null</code> not permitted). * * @return The shape object (possibly <code>null</code>). * * @throws IOException if there is an I/O problem. * @throws ClassNotFoundException if there is a problem loading a class. *//*from w w w . j a v a 2 s . com*/ public static Shape readShape(final ObjectInputStream stream) throws IOException, ClassNotFoundException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } Shape result = null; final boolean isNull = stream.readBoolean(); if (!isNull) { final Class c = (Class) stream.readObject(); if (c.equals(Line2D.class)) { final double x1 = stream.readDouble(); final double y1 = stream.readDouble(); final double x2 = stream.readDouble(); final double y2 = stream.readDouble(); result = new Line2D.Double(x1, y1, x2, y2); } else if (c.equals(Rectangle2D.class)) { final double x = stream.readDouble(); final double y = stream.readDouble(); final double w = stream.readDouble(); final double h = stream.readDouble(); result = new Rectangle2D.Double(x, y, w, h); } else if (c.equals(Ellipse2D.class)) { final double x = stream.readDouble(); final double y = stream.readDouble(); final double w = stream.readDouble(); final double h = stream.readDouble(); result = new Ellipse2D.Double(x, y, w, h); } else if (c.equals(Arc2D.class)) { final double x = stream.readDouble(); final double y = stream.readDouble(); final double w = stream.readDouble(); final double h = stream.readDouble(); final double as = stream.readDouble(); // Angle Start final double ae = stream.readDouble(); // Angle Extent final int at = stream.readInt(); // Arc type result = new Arc2D.Double(x, y, w, h, as, ae, at); } else if (c.equals(GeneralPath.class)) { final GeneralPath gp = new GeneralPath(); final float[] args = new float[6]; boolean hasNext = stream.readBoolean(); while (!hasNext) { final int type = stream.readInt(); for (int i = 0; i < 6; i++) { args[i] = stream.readFloat(); } switch (type) { case PathIterator.SEG_MOVETO: gp.moveTo(args[0], args[1]); break; case PathIterator.SEG_LINETO: gp.lineTo(args[0], args[1]); break; case PathIterator.SEG_CUBICTO: gp.curveTo(args[0], args[1], args[2], args[3], args[4], args[5]); break; case PathIterator.SEG_QUADTO: gp.quadTo(args[0], args[1], args[2], args[3]); break; case PathIterator.SEG_CLOSE: gp.closePath(); break; default: throw new RuntimeException("JFreeChart - No path exists"); } gp.setWindingRule(stream.readInt()); hasNext = stream.readBoolean(); } result = gp; } else { result = (Shape) stream.readObject(); } } return result; }
From source file:org.openmeetings.app.data.record.BatikMethods.java
public void drawArrow(SVGGraphics2D g2d, GeomPoint start, GeomPoint end, float thickness, float alpha, Color linecoler, Color fillColor) { if (start.equals(end)) return;/*from w ww .j a v a 2 s.c om*/ // (double edgeControlPosition, double edgeControlSize, // double headLength, double headWidth, double shaftControlPosition, // double shaftControlSize, float shaftPosition, double shaftThickness) ArrowStyle arrowStyle = new ArrowStyle(0.5, 0.5, thickness * 5, thickness * 5, 0.5, 0.5, 0, thickness); GeomPoint fullVect = end.subtract(start); double halfWidth = (arrowStyle.headWidth != -1) ? arrowStyle.headWidth / 2 : arrowStyle.headLength / 2; //Figure out the line start/end points GeomPoint startNorm = new GeomPoint(); startNorm.setLocation(fullVect.getY(), -fullVect.getX()); startNorm.normalize(arrowStyle.shaftThickness / 2); GeomPoint start1 = start.add(startNorm); GeomPoint start2 = start.subtract(startNorm); GeomPoint end1 = end.add(startNorm); GeomPoint end2 = end.subtract(startNorm); //log.debug("startNorm: "+startNorm.toString()); //log.debug("start1: "+start1.toString()); //log.debug("start2: "+start2.toString()); //log.debug("end1: "+end1.toString()); //log.debug("end2: "+end2.toString()); //figure out where the arrow head starts GeomPoint headPnt = fullVect.clone(); //log.debug("headPnt 1: "+headPnt.toString()); //log.debug("headPnt.length 1: "+headPnt.length()); //log.debug("arrowStyle.headLength 1: "+arrowStyle.headLength); headPnt.normalize(headPnt.length() - arrowStyle.headLength); //log.debug("headPnt 2: "+headPnt.toString()); headPnt = headPnt.add(start); //log.debug("headPnt 3: "+headPnt.toString()); //calculate the arrowhead corners GeomPoint headPntNorm = startNorm.clone(); //log.debug("headPntNorm ^^: "+headPntNorm.toString()); //log.debug("halfWidth ^^: "+halfWidth); headPntNorm.normalize(halfWidth); //log.debug("headPntNorm: "+headPntNorm.toString()); GeomPoint edge1 = headPnt.add(headPntNorm); GeomPoint edge2 = headPnt.subtract(headPntNorm); //log.debug("edge1: "+edge1.toString()); //log.debug("edge2: "+edge2.toString()); //Figure out where the arrow connects the the shaft, then calc the intersections GeomPoint shaftCenter = GeomPoint.interpolate(end, headPnt, arrowStyle.shaftPosition); //log.debug("end"+end.toString()); //log.debug("headPnt: "+headPnt.toString()); //log.debug("arrowStyle.shaftPosition: "+arrowStyle.shaftPosition); //log.debug("shaftCenter: "+shaftCenter); //log.debug("edge1: "+edge1); //shaftCenter.setLocation(185.857864376269, 185.857864376269); GeomPoint inter1 = GeomPoint.getLineIntersection(start1, end1, shaftCenter, edge1); GeomPoint inter2 = GeomPoint.getLineIntersection(start2, end2, shaftCenter, edge2); //log.debug("inter1: "+inter1.toString()); //log.debug("inter2: "+inter2.toString()); //Figure out the control points GeomPoint edgeCenter = GeomPoint.interpolate(end, headPnt, (float) arrowStyle.edgeControlPosition); GeomPoint edgeNorm = startNorm.clone(); edgeNorm.normalize(halfWidth * arrowStyle.edgeControlSize); //log.debug("halfWidth*arrowStyle.edgeControlSize: "+(halfWidth*arrowStyle.edgeControlSize)); //log.debug("edgeNorm: "+edgeNorm.toString()); GeomPoint edgeCntrl1 = edgeCenter.add(edgeNorm); GeomPoint edgeCntrl2 = edgeCenter.subtract(edgeNorm); //log.debug("edgeCntrl1: "+edgeCntrl1.toString()); //log.debug("edgeCntrl2: "+edgeCntrl2.toString()); g2d.setPaint(new Color(255, 0, 0)); // graphics.moveTo(start1.x,start1.y); // graphics.lineTo(inter1.x,inter1.y); // graphics.lineTo(edge1.x,edge1.y); // graphics.curveTo(edgeCntrl1.x,edgeCntrl1.y,end.x,end.y); // graphics.curveTo(edgeCntrl2.x,edgeCntrl2.y,edge2.x,edge2.y); // graphics.lineTo(inter2.x,inter2.y); // graphics.lineTo(start2.x,start2.y); // graphics.lineTo(start1.x,start1.y); // log.debug("moveTo"+start1.x+","+start1.y); // log.debug("lineTo"+inter1.x+","+inter1.y); // log.debug("lineTo"+edge1.x+","+edge1.y); // log.debug("quadTo"+edgeCntrl1.x+","+edgeCntrl1.y+","+end.x+","+end.y); // log.debug("quadTo"+edgeCntrl2.x+","+edgeCntrl2.y+","+edge2.x+","+edge2.y); // log.debug("lineTo"+inter2.x+","+inter2.y); // log.debug("lineTo"+start2.x+","+start2.y); // log.debug("lineTo"+start1.x+","+start1.y); GeneralPath graphics = new GeneralPath(); graphics.moveTo(start1.x, start1.y); graphics.lineTo(inter1.x, inter1.y); graphics.lineTo(edge1.x, edge1.y); graphics.quadTo(edgeCntrl1.x, edgeCntrl1.y, end.x, end.y); graphics.quadTo(edgeCntrl2.x, edgeCntrl2.y, edge2.x, edge2.y); graphics.lineTo(inter2.x, inter2.y); graphics.lineTo(start2.x, start2.y); graphics.lineTo(start1.x, start1.y); graphics.closePath(); int[] rules = new int[8]; //all possible Compositing Rules: rules[0] = AlphaComposite.SRC_OVER; rules[1] = AlphaComposite.DST_OVER; rules[2] = AlphaComposite.CLEAR; rules[3] = AlphaComposite.SRC; rules[4] = AlphaComposite.SRC_IN; rules[5] = AlphaComposite.DST_IN; rules[6] = AlphaComposite.SRC_OUT; rules[7] = AlphaComposite.DST_OUT; g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha)); g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); if (linecoler != null) { g2d.setPaint(linecoler); g2d.draw(graphics); } if (fillColor != null) { g2d.setPaint(fillColor); g2d.fill(graphics); } }
From source file:CustomStrokes.java
public Shape createStrokedShape(Shape shape) { GeneralPath newshape = new GeneralPath(); // Start with an empty shape // Iterate through the specified shape, perturb its coordinates, and // use them to build up the new shape. float[] coords = new float[6]; for (PathIterator i = shape.getPathIterator(null); !i.isDone(); i.next()) { int type = i.currentSegment(coords); switch (type) { case PathIterator.SEG_MOVETO: perturb(coords, 2);//from w w w .ja v a2 s . c om newshape.moveTo(coords[0], coords[1]); break; case PathIterator.SEG_LINETO: perturb(coords, 2); newshape.lineTo(coords[0], coords[1]); break; case PathIterator.SEG_QUADTO: perturb(coords, 4); newshape.quadTo(coords[0], coords[1], coords[2], coords[3]); break; case PathIterator.SEG_CUBICTO: perturb(coords, 6); newshape.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case PathIterator.SEG_CLOSE: newshape.closePath(); break; } } // Finally, stroke the perturbed shape and return the result return stroke.createStrokedShape(newshape); }
From source file:org.apache.fontbox.ttf.GlyphRenderer.java
private void quadTo(GeneralPath path, Point ctrlPoint, Point point) { path.quadTo(ctrlPoint.x, ctrlPoint.y, point.x, point.y); if (LOG.isDebugEnabled()) { LOG.trace("quadTo: " + String.format("%d,%d %d,%d", ctrlPoint.x, ctrlPoint.y, point.x, point.y)); }/*from w w w .j av a 2 s.c om*/ }
From source file:org.apache.pdfbox.pdfviewer.font.TTFGlyph2D.java
private void quadTo(GeneralPath path, Point ctrlPoint, Point point) { path.quadTo(ctrlPoint.x, ctrlPoint.y, point.x, point.y); LOG.debug("quadTo: " + String.format("%d,%d %d,%d", ctrlPoint.x, ctrlPoint.y, point.x, point.y)); }
From source file:org.jcurl.math.helpers.CurveShape.java
public static Shape approximateQuadratic(final CurveGhost c, final double[] sections) throws FunctionEvaluationException { final double[] p0 = { c.getC(0, 0, sections[0]), c.getC(1, 0, sections[0]) }; final double[] v0 = { c.getC(0, 1, sections[0]), c.getC(1, 1, sections[0]) }; final double[] p1 = { 0, 0 }; final double[] v1 = { 0, 0 }; final GeneralPath gp = new GeneralPath(GeneralPath.WIND_NON_ZERO, sections.length + 1); gp.moveTo((float) p0[0], (float) p0[1]); final double tmp_a[][] = { { 0, 0 }, { 0, 0 } }; final double tmp_b[] = { 0, 0 }; final double pc[] = { 0, 0 }; for (int i = 1; i < sections.length; i++) { p1[0] = c.getC(0, 0, sections[i]); p1[1] = c.getC(1, 0, sections[i]); v1[0] = c.getC(0, 1, sections[i]); v1[1] = c.getC(1, 1, sections[i]); computeControlPoint(p0, v0, p1, v1, tmp_a, tmp_b, pc); gp.quadTo((float) pc[0], (float) pc[1], (float) p1[0], (float) p1[1]); p0[0] = p1[0];/*from w w w .j a v a 2 s . c o m*/ p0[1] = p1[1]; v0[0] = v1[0]; v0[1] = v1[1]; } return gp; }
From source file:org.jcurl.math.ShaperUtils.java
/** * Compute the control point and add one <a * href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve">Quadratic Bezier * Curve</a> to a {@link GeneralPath}. Does <b>no</b> initial * {@link GeneralPath#moveTo(float, float)}. * //from ww w . j a va 2 s .c o m * <h3>Approximation algorithm</h3> * <p> * This ansatz uses no adaptive optimisation but only * <ul> * <li>the start- and endpoint of each interval als control points k0 and * k2</li> * <li>the directions (normalised velocities) in the control points k0 and * k2. The intersection is used as k1.</li> * </ul> * <p> * TODO maybe re-use endpoint location and velocity. This can cause pain at * C1 discontinuous t's (collissions). * </p> * <h3><a href="http://en.wikipedia.org/wiki/Maxima_(software)">Maxima</a> * Solution</h3> * * <pre> * radsubstflag: true$ * k0_0 + l * v0_0 = k2_0 + m * v2_0; * k0_1 + l * v0_1 = k2_1 + m * v2_1; * solve([%th(2),%th(1)],[l,m]); * subst(q, v0_1 * v2_0 - v0_0 * v2_1, %); * subst(dx_0 + k0_0, k2_0, %); * subst(dx_1 + k0_1, k2_1, %); * ratsimp(%); * </pre> */ static final void quadTo(final R1RNFunction f, final double tmin, final double tmax, final GeneralPath gp, final float zoom) { final double eps = 1e-6; // first control point (startpoint). The same as gp.getCurrentPoint() final double k0_0 = f.at(tmin, 0, 0); final double k0_1 = f.at(tmin, 0, 1); // startpoint velocity double v0_0 = f.at(tmin, 1, 0); double v0_1 = f.at(tmin, 1, 1); if (v0_0 * v0_0 + v0_1 * v0_1 < eps) { v0_0 = f.at(tmin + eps, 1, 0); v0_1 = f.at(tmin + eps, 1, 1); } // 3rd control point (endpoint). final double k2_0 = f.at(tmax, 0, 0); final double k2_1 = f.at(tmax, 0, 1); // endpoint velocity double v2_0 = f.at(tmax, 1, 0); double v2_1 = f.at(tmax, 1, 1); if (v2_0 * v2_0 + v2_1 * v2_1 < eps) { v2_0 = f.at(tmax - eps, 1, 0); v2_1 = f.at(tmax - eps, 1, 1); } // compute the 2nd control point final double dx_0 = k2_0 - k0_0; final double dx_1 = k2_1 - k0_1; final double q = v0_1 * v2_0 - v0_0 * v2_1; final double m = -(dx_0 * v0_1 - dx_1 * v0_0) / q; // 2nd control point is final float k1_0 = (float) (k2_0 + m * v2_0); final float k1_1 = (float) (k2_1 + m * v2_1); if (true) gp.quadTo(zoom * k1_0, zoom * k1_1, zoom * (float) k2_0, zoom * (float) k2_1); else { gp.lineTo(zoom * k1_0, zoom * k1_1); gp.lineTo(zoom * (float) k2_0, zoom * (float) k2_1); } }