This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
centre in any shape - Java2D + Center of Attention
Posted by vijayv on December 28, 2001 at 6:00 AM
I understand that the shapes are reprsented as curves (in my case when i printed the Type information - if found them to be represented as Cubic Type.)
// Holding different shapes VennArea vennarea = (VennArea)VennPanel.this.m_vennAreas.get(i); PathIterator pi = vennarea.getPathIterator(null); System.out.println("Area ............" +"[" + i +"]"); int j=0; while(!pi.isDone()) { describeShape(pi,j); pi.next(); }
void describeShape(PathIterator pi, int j) { double[] coordinates = new double[6]; int type = pi.currentSegment(coordinates); System.out.println("type " + type); Graphics2D graphics = (Graphics2D)this.getGraphics(); switch (type) { case PathIterator.SEG_MOVETO: System.out.println("Move to " + coordinates[0] + "," + coordinates[1] ); graphics.setColor(Color.yellow); break; case PathIterator.SEG_LINETO: System.out.println("Line to " + coordinates[0] + "," + coordinates[1] ); break; case PathIterator.SEG_QUADTO : System.out.print("Quadric to " + coordinates[0] + "," + coordinates[1] ); System.out.println(" " + coordinates[2] + "," + coordinates[3] ); break; case PathIterator.SEG_CUBICTO: System.out.print("cubic to " + coordinates[0] + "," + coordinates[1] ); System.out.print(" , " + coordinates[2] + "," + coordinates[3] ); System.out.print(" , " + coordinates[4] + "," + coordinates[5] ); // Reconstruct the same curve QuadCurve2D qd = new QuadCurve2D.Double(coordinates[0],coordinates[1],coordinates[2],coordinates[3],coordinates[4],coordinates[5]); //QuadCurve2D qd1 = new QuadCurve2D.Double(245,21,101,21,101,169); graphics.draw(qd); break; case PathIterator.SEG_CLOSE: System.out.println("Close..............................."); break; default: System.out.println("defualt case"); break; } }
The code to find the curve is shown. But when i again reconstruct the same curve - it doesn't work right. !!!
Any idea - what foolish error i am doing here !! I have two gif files which clearly mentions the problem with clarity - i dont know how to attach them here. If some one is intereseted can mail me the id - so that i can send the gif. Thanks Vijayv
Replies:
|